Skip to content

Determine the access method to a referenced symbol.#172462

Draft
ratzdi wants to merge 14 commits into
llvm:mainfrom
aboutthinkdigital:users/ratzdi/issue_2207_reference_tags_in_call_hierarchy_item
Draft

Determine the access method to a referenced symbol.#172462
ratzdi wants to merge 14 commits into
llvm:mainfrom
aboutthinkdigital:users/ratzdi/issue_2207_reference_tags_in_call_hierarchy_item

Conversation

@ratzdi
Copy link
Copy Markdown
Contributor

@ratzdi ratzdi commented Dec 16, 2025

The access method helps to know in a quick way, what is happening with the referenced symbol somewhere in the code, i.e. is the referenced symbol used as a rvalue object to read a value from or as lvalue object to write some value into.

The basic access methods to a referenced symbol can be write and/or read.

Implementation of the LSP issue microsoft/language-server-protocol#2207 and microsoft/language-server-protocol#2226

The access method helps to know in a quick way, what is happening with the referenced symbol somewhere in the code, i.e.
is the referenced symbol used as a rvalue object to read a value from or as lvalue object to write some value into.

The basic access methods to a referenced symbol can be write and/or read.
@github-actions
Copy link
Copy Markdown

Thank you for submitting a Pull Request (PR) to the LLVM Project!

This PR will be automatically labeled and the relevant teams will be notified.

If you wish to, you can add reviewers by using the "Reviewers" section on this page.

If this is not working for you, it is probably because you do not have write permissions for the repository. In which case you can instead tag reviewers by name in a comment by using @ followed by their GitHub username.

If you have received no comments on your PR for a week, you can request a review by "ping"ing the PR by adding a comment “Ping”. The common courtesy "ping" rate is once a week. Please remember that you are asking for valuable time from other developers.

If you have further questions, they may be answered by the LLVM GitHub User Guide.

You can also ask questions in a comment on this PR, on the LLVM Discord or on the forums.

@github-actions
Copy link
Copy Markdown

github-actions Bot commented Jan 26, 2026

✅ With the latest revision this PR passed the C/C++ code formatter.

@github-actions
Copy link
Copy Markdown

github-actions Bot commented Jan 26, 2026

🐧 Linux x64 Test Results

  • 5002 tests passed
  • 7 tests skipped

✅ The build succeeded and all tests passed.

@github-actions
Copy link
Copy Markdown

github-actions Bot commented Jan 26, 2026

🪟 Windows x64 Test Results

  • 3197 tests passed
  • 31 tests skipped

✅ The build succeeded and all tests passed.

@ratzdi ratzdi force-pushed the users/ratzdi/issue_2207_reference_tags_in_call_hierarchy_item branch 2 times, most recently from fe531ed to d556a72 Compare January 29, 2026 18:33
- Fix lit tests
- Fix unit tests.
@ratzdi ratzdi force-pushed the users/ratzdi/issue_2207_reference_tags_in_call_hierarchy_item branch from d556a72 to 98e1167 Compare January 29, 2026 19:00
Dimitri Ratz and others added 8 commits February 2, 2026 23:22
Try to get the function definition before calling analyseParameterUsage.
Visit member expressions.
Honor the client's referenceTags capability for callHierarchy/\nincomingCalls, recover target decls for header symbols when AST\nlookup falls back to the index, and treat compound assignments\nas both read and write accesses.
… items

Extend call hierarchy outgoing results to annotate variable/field references
with read/write `referenceTags` when supported by the client.

- keep function calls untagged (no [clangd] Add outgoing call reference tags with fast-path and stable ordering

Compute read/write reference tags for outgoing call hierarchy entries on
variables and fields, while keeping function calls untagged.

- preserve index-only outgoing call resolution when reference tags are not needed
- keep outgoing results deterministically ordered
- compute variable/field usage in a single AST traversal
- add and update unit/LSP tests for tagged outgoing calls read/write classification)
- preserve existing incomingCalls behavior (no functional changes)
- update/adjust outgoing-focused tests to cover variable/field tagging
@ratzdi ratzdi force-pushed the users/ratzdi/issue_2207_reference_tags_in_call_hierarchy_item branch from c238a58 to 914239f Compare May 13, 2026 16:22
Implement support for the LSP 3.18 PR llvm#2226 textDocument/references
Reference item response type. When the client announces
textDocument.references.referenceItemsSupport=true, clangd returns
Reference[] objects (with nested 'location' and optional 'referenceTags')
instead of the legacy flat Location[] array.
Changes:
- Protocol.h/cpp: Add 'Reference' struct and JSON serializer; parse
  'textDocument.references.referenceItemsSupport' client capability.
- XRefs.h/cpp: Add 'ReferenceTags' field to ReferencesResult::Reference;
  introduce 6-arg findReferences() overload with ComputeReferenceTags
  flag; keep 5-arg overload for backward compatibility.
- ClangdServer.h/cpp: Thread ComputeReferenceTags flag through to XRefs.
- ClangdLSPServer.h/cpp: Store SupportsReferenceItems capability flag;
  in onReference() emit Reference[] or legacy ReferenceLocation[]
  depending on client capability.
- Tests: Add LSPTest.ReferencesReturnReferenceItemsWithTags and
  LSPTest.ReferencesReturnLegacyLocationWithoutReferenceItemsSupport.
@ratzdi ratzdi force-pushed the users/ratzdi/issue_2207_reference_tags_in_call_hierarchy_item branch from 71e8b5b to d041feb Compare May 23, 2026 22:25
ratzdi added 2 commits May 26, 2026 09:12
Update references.test lit to verify the new LSP 3.18 reference items
response format. Enable referenceItemsSupport capability in the
initialize request, and verify that the response includes:
- nested 'location' field instead of flat uri/range
- 'referenceTags' array marking the reference as Read (tag value 1)
This validates that clangd correctly returns Reference items with
semantic information when the client supports it.
… cases

Add two new textDocument/references lit tests to cover:
- Write reference (referenceTags: [2]): variable assigned via 'w = 5'
  confirms tag value 2 (ReferenceTag::Write) is emitted.
- Function call reference (no referenceTags): calling 'func()' produces
  a Reference item with only 'location'; function calls carry neither
  Read nor Write access semantics, so 'referenceTags' is absent.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant