From 32f840631cb2bfcbd862a018e3d6f4bf00fb1e97 Mon Sep 17 00:00:00 2001 From: Hamish Knight Date: Thu, 10 Jul 2025 15:20:31 +0100 Subject: [PATCH] [6.2] [SourceKit] Fix raw identifier handling for semantic tokens The logic here was unnecessary, the SourceRange gets converted to a CharSourceRange in the function being called, which handles raw identifiers correctly. 6.2-only since this is already fixed on main. rdar://152273926 --- lib/IDE/SourceEntityWalker.cpp | 7 ++-- .../SemanticTokens/raw_identifiers.swift | 33 +++++++++++++++++++ 2 files changed, 35 insertions(+), 5 deletions(-) create mode 100644 test/SourceKit/SemanticTokens/raw_identifiers.swift diff --git a/lib/IDE/SourceEntityWalker.cpp b/lib/IDE/SourceEntityWalker.cpp index 5fabc325f13ad..358255f5fedfd 100644 --- a/lib/IDE/SourceEntityWalker.cpp +++ b/lib/IDE/SourceEntityWalker.cpp @@ -868,11 +868,8 @@ bool SemaAnnotator::passCallAsFunctionReference(ValueDecl *D, SourceLoc Loc, bool SemaAnnotator:: passReference(ValueDecl *D, Type Ty, DeclNameLoc Loc, ReferenceMetaData Data) { - SourceManager &SM = D->getASTContext().SourceMgr; - SourceLoc BaseStart = Loc.getBaseNameLoc(), BaseEnd = BaseStart; - if (BaseStart.isValid() && SM.extractText({BaseStart, 1}) == "`") - BaseEnd = Lexer::getLocForEndOfToken(SM, BaseStart.getAdvancedLoc(1)); - return passReference(D, Ty, BaseStart, {BaseStart, BaseEnd}, Data); + SourceLoc BaseLoc = Loc.getBaseNameLoc(); + return passReference(D, Ty, BaseLoc, BaseLoc, Data); } bool SemaAnnotator:: diff --git a/test/SourceKit/SemanticTokens/raw_identifiers.swift b/test/SourceKit/SemanticTokens/raw_identifiers.swift new file mode 100644 index 0000000000000..72a66e5ce2a9f --- /dev/null +++ b/test/SourceKit/SemanticTokens/raw_identifiers.swift @@ -0,0 +1,33 @@ +// RUN: %empty-directory(%t) +// RUN: split-file %s %t +// RUN: %sourcekitd-test -req=semantic-tokens %t/main.swift -- %t/main.swift > %t/result.json +// RUN: diff -u %t/tokens.json %t/result.json + +//--- main.swift +func `foo`(x: Int) {} +`foo`(x: 0) + +func `foo bar baz`() {} +`foo bar baz`() + +//--- tokens.json +{ + key.semantic_tokens: [ + { + key.kind: source.lang.swift.ref.struct, + key.offset: 14, + key.length: 3, + key.is_system: 1 + }, + { + key.kind: source.lang.swift.ref.function.free, + key.offset: 22, + key.length: 5 + }, + { + key.kind: source.lang.swift.ref.function.free, + key.offset: 59, + key.length: 13 + } + ] +}