Skip to content

Conversation

@mizvekov
Copy link
Contributor

@mizvekov mizvekov commented Oct 13, 2025

This adds a note to the documentation of getLocalSourceRange, and cleans up one of the users of this function which was changed in #147835

This also removes TypeLoc::getNonPrefixBeginLoc, which was recently introduced in the above patch, as that became unused.

@mizvekov mizvekov self-assigned this Oct 13, 2025
@llvmbot llvmbot added clang Clang issues not falling into any other category clang-tools-extra clangd clang:frontend Language frontend issues, e.g. anything involving "Sema" labels Oct 13, 2025
@llvmbot
Copy link
Member

llvmbot commented Oct 13, 2025

@llvm/pr-subscribers-clang

Author: Matheus Izvekov (mizvekov)

Changes

This adds a note to the documentation of getLocalSourceRange, and cleans up one of the users of this function which was changed in #147835


Full diff: https://github.com/llvm/llvm-project/pull/163206.diff

2 Files Affected:

  • (modified) clang-tools-extra/clangd/FindTarget.cpp (+4-9)
  • (modified) clang/include/clang/AST/NestedNameSpecifierBase.h (+3)
diff --git a/clang-tools-extra/clangd/FindTarget.cpp b/clang-tools-extra/clangd/FindTarget.cpp
index 8aae41420b83e..799c64b8dab4d 100644
--- a/clang-tools-extra/clangd/FindTarget.cpp
+++ b/clang-tools-extra/clangd/FindTarget.cpp
@@ -1040,16 +1040,11 @@ class ExplicitReferenceCollector
     if (auto *S = N.get<Stmt>())
       return refInStmt(S, Resolver);
     if (auto *NNSL = N.get<NestedNameSpecifierLoc>()) {
+      if (auto TL = NNSL->getAsTypeLoc())
+        return refInTypeLoc(NNSL->getAsTypeLoc(), Resolver);
       // (!) 'DeclRelation::Alias' ensures we do not lose namespace aliases.
-      NestedNameSpecifierLoc Qualifier;
-      SourceLocation NameLoc;
-      if (auto TL = NNSL->getAsTypeLoc()) {
-        Qualifier = TL.getPrefix();
-        NameLoc = TL.getNonPrefixBeginLoc();
-      } else {
-        Qualifier = NNSL->getAsNamespaceAndPrefix().Prefix;
-        NameLoc = NNSL->getLocalBeginLoc();
-      }
+      NestedNameSpecifierLoc Qualifier = NNSL->getAsNamespaceAndPrefix().Prefix;
+      SourceLocation NameLoc = NNSL->getLocalBeginLoc();
       return {
           ReferenceLoc{Qualifier, NameLoc, false,
                        explicitReferenceTargets(
diff --git a/clang/include/clang/AST/NestedNameSpecifierBase.h b/clang/include/clang/AST/NestedNameSpecifierBase.h
index 73c60ba695419..669566e142447 100644
--- a/clang/include/clang/AST/NestedNameSpecifierBase.h
+++ b/clang/include/clang/AST/NestedNameSpecifierBase.h
@@ -361,6 +361,9 @@ class NestedNameSpecifierLoc {
   /// Retrieve the source range covering just the last part of
   /// this nested-name-specifier, not including the prefix.
   ///
+  /// Note that this is the source range of this NestedNameSpecifier chunk,
+  // and for a type this includes the prefix of that type.
+  ///
   /// For example, if this instance refers to a nested-name-specifier
   /// \c \::std::vector<int>::, the returned source range would cover
   /// from "vector" to the last '::'.

@llvmbot
Copy link
Member

llvmbot commented Oct 13, 2025

@llvm/pr-subscribers-clangd

Author: Matheus Izvekov (mizvekov)

Changes

This adds a note to the documentation of getLocalSourceRange, and cleans up one of the users of this function which was changed in #147835


Full diff: https://github.com/llvm/llvm-project/pull/163206.diff

2 Files Affected:

  • (modified) clang-tools-extra/clangd/FindTarget.cpp (+4-9)
  • (modified) clang/include/clang/AST/NestedNameSpecifierBase.h (+3)
diff --git a/clang-tools-extra/clangd/FindTarget.cpp b/clang-tools-extra/clangd/FindTarget.cpp
index 8aae41420b83e..799c64b8dab4d 100644
--- a/clang-tools-extra/clangd/FindTarget.cpp
+++ b/clang-tools-extra/clangd/FindTarget.cpp
@@ -1040,16 +1040,11 @@ class ExplicitReferenceCollector
     if (auto *S = N.get<Stmt>())
       return refInStmt(S, Resolver);
     if (auto *NNSL = N.get<NestedNameSpecifierLoc>()) {
+      if (auto TL = NNSL->getAsTypeLoc())
+        return refInTypeLoc(NNSL->getAsTypeLoc(), Resolver);
       // (!) 'DeclRelation::Alias' ensures we do not lose namespace aliases.
-      NestedNameSpecifierLoc Qualifier;
-      SourceLocation NameLoc;
-      if (auto TL = NNSL->getAsTypeLoc()) {
-        Qualifier = TL.getPrefix();
-        NameLoc = TL.getNonPrefixBeginLoc();
-      } else {
-        Qualifier = NNSL->getAsNamespaceAndPrefix().Prefix;
-        NameLoc = NNSL->getLocalBeginLoc();
-      }
+      NestedNameSpecifierLoc Qualifier = NNSL->getAsNamespaceAndPrefix().Prefix;
+      SourceLocation NameLoc = NNSL->getLocalBeginLoc();
       return {
           ReferenceLoc{Qualifier, NameLoc, false,
                        explicitReferenceTargets(
diff --git a/clang/include/clang/AST/NestedNameSpecifierBase.h b/clang/include/clang/AST/NestedNameSpecifierBase.h
index 73c60ba695419..669566e142447 100644
--- a/clang/include/clang/AST/NestedNameSpecifierBase.h
+++ b/clang/include/clang/AST/NestedNameSpecifierBase.h
@@ -361,6 +361,9 @@ class NestedNameSpecifierLoc {
   /// Retrieve the source range covering just the last part of
   /// this nested-name-specifier, not including the prefix.
   ///
+  /// Note that this is the source range of this NestedNameSpecifier chunk,
+  // and for a type this includes the prefix of that type.
+  ///
   /// For example, if this instance refers to a nested-name-specifier
   /// \c \::std::vector<int>::, the returned source range would cover
   /// from "vector" to the last '::'.

@llvmbot
Copy link
Member

llvmbot commented Oct 13, 2025

@llvm/pr-subscribers-clang-tools-extra

Author: Matheus Izvekov (mizvekov)

Changes

This adds a note to the documentation of getLocalSourceRange, and cleans up one of the users of this function which was changed in #147835


Full diff: https://github.com/llvm/llvm-project/pull/163206.diff

2 Files Affected:

  • (modified) clang-tools-extra/clangd/FindTarget.cpp (+4-9)
  • (modified) clang/include/clang/AST/NestedNameSpecifierBase.h (+3)
diff --git a/clang-tools-extra/clangd/FindTarget.cpp b/clang-tools-extra/clangd/FindTarget.cpp
index 8aae41420b83e..799c64b8dab4d 100644
--- a/clang-tools-extra/clangd/FindTarget.cpp
+++ b/clang-tools-extra/clangd/FindTarget.cpp
@@ -1040,16 +1040,11 @@ class ExplicitReferenceCollector
     if (auto *S = N.get<Stmt>())
       return refInStmt(S, Resolver);
     if (auto *NNSL = N.get<NestedNameSpecifierLoc>()) {
+      if (auto TL = NNSL->getAsTypeLoc())
+        return refInTypeLoc(NNSL->getAsTypeLoc(), Resolver);
       // (!) 'DeclRelation::Alias' ensures we do not lose namespace aliases.
-      NestedNameSpecifierLoc Qualifier;
-      SourceLocation NameLoc;
-      if (auto TL = NNSL->getAsTypeLoc()) {
-        Qualifier = TL.getPrefix();
-        NameLoc = TL.getNonPrefixBeginLoc();
-      } else {
-        Qualifier = NNSL->getAsNamespaceAndPrefix().Prefix;
-        NameLoc = NNSL->getLocalBeginLoc();
-      }
+      NestedNameSpecifierLoc Qualifier = NNSL->getAsNamespaceAndPrefix().Prefix;
+      SourceLocation NameLoc = NNSL->getLocalBeginLoc();
       return {
           ReferenceLoc{Qualifier, NameLoc, false,
                        explicitReferenceTargets(
diff --git a/clang/include/clang/AST/NestedNameSpecifierBase.h b/clang/include/clang/AST/NestedNameSpecifierBase.h
index 73c60ba695419..669566e142447 100644
--- a/clang/include/clang/AST/NestedNameSpecifierBase.h
+++ b/clang/include/clang/AST/NestedNameSpecifierBase.h
@@ -361,6 +361,9 @@ class NestedNameSpecifierLoc {
   /// Retrieve the source range covering just the last part of
   /// this nested-name-specifier, not including the prefix.
   ///
+  /// Note that this is the source range of this NestedNameSpecifier chunk,
+  // and for a type this includes the prefix of that type.
+  ///
   /// For example, if this instance refers to a nested-name-specifier
   /// \c \::std::vector<int>::, the returned source range would cover
   /// from "vector" to the last '::'.

@mizvekov mizvekov force-pushed the users/mizvekov/GH147835-improv1 branch from bd77676 to eeeced2 Compare October 13, 2025 14:41
This adds a note to the documentation of getLocalSourceRange,
and cleans up one of the users of this function which was
changed in #147835

This also removes `TypeLoc::getNonPrefixBeginLoc`, which was recently
introduced in the above patch, as that became unused.
@mizvekov mizvekov force-pushed the users/mizvekov/GH147835-improv1 branch from eeeced2 to 51eedf9 Compare October 13, 2025 15:20
@mizvekov mizvekov merged commit 7a11eb9 into main Oct 13, 2025
10 checks passed
@mizvekov mizvekov deleted the users/mizvekov/GH147835-improv1 branch October 13, 2025 16:16
akadutta pushed a commit to akadutta/llvm-project that referenced this pull request Oct 14, 2025
This adds a note to the documentation of getLocalSourceRange, and cleans
up one of the users of this function which was changed in
llvm#147835

This also removes `TypeLoc::getNonPrefixBeginLoc`, which was recently
introduced in the above patch, as that became unused.
akadutta pushed a commit to akadutta/llvm-project that referenced this pull request Oct 14, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

clang:frontend Language frontend issues, e.g. anything involving "Sema" clang Clang issues not falling into any other category clang-tools-extra clangd

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants