Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 16 additions & 2 deletions src/feature/code_completion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,8 @@ class CodeCompletionCollector final : public clang::CodeCompleteConsumer {
llvm::StringRef insert_text,
llvm::StringRef overload_key,
llvm::StringRef signature = {},
llvm::StringRef return_type = {}) {
llvm::StringRef return_type = {},
bool is_deprecated = false) {
if(label.empty()) {
return;
}
Expand Down Expand Up @@ -271,6 +272,9 @@ class CodeCompletionCollector final : public clang::CodeCompleteConsumer {
}
item.label_details = std::move(details);
}
if(is_deprecated) {
item.tags = std::vector{protocol::CompletionItemTag::Deprecated};
}
overloads.push_back({
.item = std::move(item),
.score = *score,
Expand Down Expand Up @@ -299,6 +303,9 @@ class CodeCompletionCollector final : public clang::CodeCompleteConsumer {
}
item.label_details = std::move(details);
}
if(is_deprecated) {
item.tags = std::vector{protocol::CompletionItemTag::Deprecated};
}
collected.push_back(std::move(item));
};

Expand Down Expand Up @@ -355,7 +362,14 @@ class CodeCompletionCollector final : public clang::CodeCompleteConsumer {
return_type = extract_return_type(*ccs);
}

try_add(label, kind, label, qualified_name.str(), signature, return_type);
bool deprecated = candidate.Availability == CXAvailability_Deprecated;
try_add(label,
kind,
label,
qualified_name.str(),
signature,
return_type,
deprecated);
break;
}
}
Expand Down
27 changes: 27 additions & 0 deletions tests/unit/feature/code_completion_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,33 @@ void bar() {
ASSERT_EQ(*it->kind, protocol::CompletionItemKind::Class);
}

TEST_CASE(DeprecatedTag) {
code_complete(R"cpp(
[[deprecated]] int foooo(int x);
int z = fo$(pos)
)cpp");

auto it = find_item("foooo");
ASSERT_TRUE(it != items.end());
ASSERT_TRUE(it->tags.has_value());
auto& tags = *it->tags;
ASSERT_TRUE(std::ranges::find(tags, protocol::CompletionItemTag::Deprecated) != tags.end());
}

TEST_CASE(NotDeprecated) {
code_complete(R"cpp(
int foooo(int x);
int z = fo$(pos)
)cpp");

auto it = find_item("foooo");
ASSERT_TRUE(it != items.end());
// Non-deprecated should have no Deprecated tag.
ASSERT_TRUE(!it->tags.has_value() ||
std::ranges::find(*it->tags, protocol::CompletionItemTag::Deprecated) ==
it->tags->end());
}

TEST_CASE(NoBundleOverloads) {
feature::CodeCompletionOptions opts;
opts.bundle_overloads = false;
Expand Down
Loading