diff --git a/src/feature/code_completion.cpp b/src/feature/code_completion.cpp index 29f3ff2e..b883d5ab 100644 --- a/src/feature/code_completion.cpp +++ b/src/feature/code_completion.cpp @@ -296,7 +296,8 @@ class CodeCompletionCollector final : public clang::CodeCompleteConsumer { llvm::StringRef overload_key, llvm::StringRef signature = {}, llvm::StringRef return_type = {}, - bool is_snippet = false) { + bool is_snippet = false, + bool is_deprecated = false) { if(label.empty()) { return; } @@ -327,6 +328,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, @@ -355,6 +359,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)); }; @@ -431,13 +438,15 @@ class CodeCompletionCollector final : public clang::CodeCompleteConsumer { bool has_snippet = !snippet.empty(); auto insert = has_snippet ? llvm::StringRef(snippet) : llvm::StringRef(label); + bool deprecated = candidate.Availability == CXAvailability_Deprecated; try_add(label, kind, insert, qualified_name.str(), signature, return_type, - has_snippet); + has_snippet, + deprecated); break; } } diff --git a/tests/unit/feature/code_completion_tests.cpp b/tests/unit/feature/code_completion_tests.cpp index 09de96fa..8f7f7474 100644 --- a/tests/unit/feature/code_completion_tests.cpp +++ b/tests/unit/feature/code_completion_tests.cpp @@ -233,6 +233,33 @@ void bar() { } } +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;