Skip to content

Commit 558fe87

Browse files
16bit-ykikoclaude
andcommitted
feat(completion): mark deprecated symbols with CompletionItemTag
Check CXAvailability_Deprecated on CodeCompletionResult and set CompletionItemTag::Deprecated on the CompletionItem. Editors render this as a strikethrough on the completion label. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 9c4a2e1 commit 558fe87

File tree

2 files changed

+43
-2
lines changed

2 files changed

+43
-2
lines changed

src/feature/code_completion.cpp

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,8 @@ class CodeCompletionCollector final : public clang::CodeCompleteConsumer {
240240
llvm::StringRef insert_text,
241241
llvm::StringRef overload_key,
242242
llvm::StringRef signature = {},
243-
llvm::StringRef return_type = {}) {
243+
llvm::StringRef return_type = {},
244+
bool is_deprecated = false) {
244245
if(label.empty()) {
245246
return;
246247
}
@@ -271,6 +272,9 @@ class CodeCompletionCollector final : public clang::CodeCompleteConsumer {
271272
}
272273
item.label_details = std::move(details);
273274
}
275+
if(is_deprecated) {
276+
item.tags = std::vector{protocol::CompletionItemTag::Deprecated};
277+
}
274278
overloads.push_back({
275279
.item = std::move(item),
276280
.score = *score,
@@ -299,6 +303,9 @@ class CodeCompletionCollector final : public clang::CodeCompleteConsumer {
299303
}
300304
item.label_details = std::move(details);
301305
}
306+
if(is_deprecated) {
307+
item.tags = std::vector{protocol::CompletionItemTag::Deprecated};
308+
}
302309
collected.push_back(std::move(item));
303310
};
304311

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

358-
try_add(label, kind, label, qualified_name.str(), signature, return_type);
365+
bool deprecated = candidate.Availability == CXAvailability_Deprecated;
366+
try_add(label,
367+
kind,
368+
label,
369+
qualified_name.str(),
370+
signature,
371+
return_type,
372+
deprecated);
359373
break;
360374
}
361375
}

tests/unit/feature/code_completion_tests.cpp

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,33 @@ void bar() {
192192
ASSERT_EQ(*it->kind, protocol::CompletionItemKind::Class);
193193
}
194194

195+
TEST_CASE(DeprecatedTag) {
196+
code_complete(R"cpp(
197+
[[deprecated]] int foooo(int x);
198+
int z = fo$(pos)
199+
)cpp");
200+
201+
auto it = find_item("foooo");
202+
ASSERT_TRUE(it != items.end());
203+
ASSERT_TRUE(it->tags.has_value());
204+
auto& tags = *it->tags;
205+
ASSERT_TRUE(std::ranges::find(tags, protocol::CompletionItemTag::Deprecated) != tags.end());
206+
}
207+
208+
TEST_CASE(NotDeprecated) {
209+
code_complete(R"cpp(
210+
int foooo(int x);
211+
int z = fo$(pos)
212+
)cpp");
213+
214+
auto it = find_item("foooo");
215+
ASSERT_TRUE(it != items.end());
216+
// Non-deprecated should have no Deprecated tag.
217+
ASSERT_TRUE(!it->tags.has_value() ||
218+
std::ranges::find(*it->tags, protocol::CompletionItemTag::Deprecated) ==
219+
it->tags->end());
220+
}
221+
195222
TEST_CASE(NoBundleOverloads) {
196223
feature::CodeCompletionOptions opts;
197224
opts.bundle_overloads = false;

0 commit comments

Comments
 (0)