Skip to content

[SourceKit] Report comment tags in 'indexsource' request #41681

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 7, 2022
Merged
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
26 changes: 26 additions & 0 deletions test/SourceKit/Indexing/index_commenttag.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// RUN: %sourcekitd-test -req=index %s -- %s | %FileCheck %s


/// - Tag: SomeTag
/// - Tag: Other
func testFunc() {}

// CHECK-LABEL: key.entities: [

// CHECK: {
// CHECK-DAG: key.kind: source.lang.swift.commenttag
// CHECK-DAG: key.usr: "t:SomeTag"
// CHECK: }

// CHECK: {
// CHECK-DAG: key.kind: source.lang.swift.commenttag
// CHECK-DAG: key.usr: "t:Other"
// CHECK: }

// CHECK: {
// CHECK-DAG: key.kind: source.lang.swift.decl.function.free
// CHECK-DAG: key.name: "testFunc()"
// CHECK-DAG: key.effective_access: source.decl.effective_access.internal
// CHECK: }

// CHECK: ]
4 changes: 2 additions & 2 deletions tools/SourceKit/lib/SwiftLang/SwiftIndexing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ class SKIndexDataConsumer : public IndexDataConsumer {
info.IsImplicit = symbol.roles & (unsigned)SymbolRole::Implicit;
info.IsTestCandidate = symbol.symInfo.Properties & SymbolProperty::UnitTest;
std::vector<UIdent> uidAttrs;
if (!isRef) {
if (!isRef && symbol.decl) {
uidAttrs = getDeclAttributeUIDs(symbol.decl);
info.Attrs = uidAttrs;
if (auto *VD = dyn_cast<ValueDecl>(symbol.decl)) {
Expand Down Expand Up @@ -194,7 +194,7 @@ class SKIndexDataConsumer : public IndexDataConsumer {
info.IsDynamic = relation.roles & (unsigned)SymbolRole::Dynamic;
info.IsTestCandidate = relation.symInfo.Properties & SymbolProperty::UnitTest;
std::vector<UIdent> uidAttrs;
if (!isRef) {
if (!isRef && relation.decl) {
uidAttrs = getDeclAttributeUIDs(relation.decl);
info.Attrs = uidAttrs;
}
Expand Down
5 changes: 4 additions & 1 deletion tools/SourceKit/lib/SwiftLang/SwiftLangSupport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -721,9 +721,12 @@ UIdent SwiftLangSupport::getUIDForSymbol(SymbolInfo sym, bool isRef) {
case SymbolKind::Module:
return KindRefModule;

case SymbolKind::CommentTag:
return KindCommentTag;

default:
// TODO: reconsider whether having a default case is a good idea.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can remove the TODO now (it was a bad idea 😆)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I left this TODO because we still have the default case.

return UIdent();
llvm_unreachable("unhandled symbol kind Swift doesn't use");
}

#undef SIMPLE_CASE
Expand Down
1 change: 1 addition & 0 deletions utils/gyb_sourcekit_support/UIDs.py
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,7 @@ def __init__(self, internal_name, external_name):
KIND('DeclGenericTypeParam', 'source.lang.swift.decl.generic_type_param'),
KIND('RefGenericTypeParam', 'source.lang.swift.ref.generic_type_param'),
KIND('RefModule', 'source.lang.swift.ref.module'),
KIND('CommentTag', 'source.lang.swift.commenttag'),
KIND('StmtForEach', 'source.lang.swift.stmt.foreach'),
KIND('StmtFor', 'source.lang.swift.stmt.for'),
KIND('StmtWhile', 'source.lang.swift.stmt.while'),
Expand Down