Skip to content

Fix references for local variables and parameters#2679

Merged
ahoppen merged 13 commits into
swiftlang:mainfrom
somiljain2006:Local-variable-refrence
Jun 15, 2026
Merged

Fix references for local variables and parameters#2679
ahoppen merged 13 commits into
swiftlang:mainfrom
somiljain2006:Local-variable-refrence

Conversation

@somiljain2006

Copy link
Copy Markdown
Contributor

Fixes #2583

Use relatedIdentifiers as a fallback when indexed references are unavailable, allowing textDocument/references to resolve local variables and parameters. Add regression tests covering local variable references, shadowed locals, parameter references, and includeDeclaration behavior.

@somiljain2006

Copy link
Copy Markdown
Contributor Author

@ahoppen @hamishknight @rintaro Can you review this pr?

@rintaro rintaro left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Looks nice!

Comment thread Sources/SourceKitLSP/SourceKitLSPServer.swift Outdated
Comment thread Sources/SwiftLanguageService/SwiftLanguageService.swift Outdated
@somiljain2006
somiljain2006 requested a review from rintaro June 1, 2026 19:38
@rintaro

rintaro commented Jun 1, 2026

Copy link
Copy Markdown
Member

@swift-ci Please test

@rintaro

rintaro commented Jun 1, 2026

Copy link
Copy Markdown
Member

@swift-ci Please test Windows

@ahoppen ahoppen left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Nice improvement, @somiljain2006.

Comment thread Sources/SourceKitLSP/LanguageService.swift
Comment thread Sources/SourceKitLSP/SourceKitLSPServer.swift Outdated
Comment thread Tests/SourceKitLSPTests/ReferencesTests.swift Outdated
Comment thread Tests/SourceKitLSPTests/ReferencesTests.swift Outdated
Comment thread Tests/SourceKitLSPTests/ReferencesTests.swift
@somiljain2006
somiljain2006 requested a review from ahoppen June 2, 2026 07:42
Comment thread Sources/SourceKitLSP/SourceKitLSPServer.swift Outdated
Comment thread Sources/SourceKitLSP/LanguageService.swift Outdated
Comment thread Sources/SourceKitLSP/SourceKitLSPServer.swift Outdated
@somiljain2006

somiljain2006 commented Jun 2, 2026

Copy link
Copy Markdown
Contributor Author

Thanks for the feedback. I've updated the implementation accordingly: switched back to .deletedFiles, filtered out only current-document index results. I also added a test covering references from edited non-current documents are still reported. All tests are passing.

@somiljain2006
somiljain2006 requested a review from ahoppen June 2, 2026 16:41
Comment thread Sources/SourceKitLSP/LanguageService.swift Outdated
Comment thread Sources/SourceKitLSP/SourceKitLSPServer.swift Outdated
Comment thread Tests/SourceKitLSPTests/ReferencesTests.swift Outdated
@somiljain2006
somiljain2006 requested a review from ahoppen June 5, 2026 02:20

@ahoppen ahoppen left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Sorry for the back-and-forth between Rintaro and myself here. The implementation looks good, just have a few nitpicks on the tests.

Comment thread Tests/SourceKitLSPTests/ReferencesTests.swift Outdated
Comment thread Tests/SourceKitLSPTests/ReferencesTests.swift Outdated
@ahoppen

ahoppen commented Jun 5, 2026

Copy link
Copy Markdown
Member

@swift-ci Please test

@ahoppen

ahoppen commented Jun 5, 2026

Copy link
Copy Markdown
Member

@swift-ci Please test Windows

@somiljain2006

Copy link
Copy Markdown
Contributor Author

@ahoppen The CI failure turned out to be unrelated to the reference's logic itself. The build was failing in the logging statements because SKLogging couldn't interpolate the error value directly. I've updated the logging code to avoid that interpolation issue and pushed a follow-up fix.

@ahoppen

ahoppen commented Jun 11, 2026

Copy link
Copy Markdown
Member

@swift-ci Please test

Comment thread Tests/SourceKitLSPTests/ReferencesTests.swift Outdated
@ahoppen

ahoppen commented Jun 11, 2026

Copy link
Copy Markdown
Member

@swift-ci Please test

@somiljain2006

somiljain2006 commented Jun 12, 2026

Copy link
Copy Markdown
Contributor Author

@ahoppen The macOS CI failure looks unrelated to this PR. The job timed out while building, and I don't see any build errors or test failures in the log.

@rintaro

rintaro commented Jun 12, 2026

Copy link
Copy Markdown
Member

@swift-ci Please test

@ahoppen
ahoppen merged commit 3522158 into swiftlang:main Jun 15, 2026
3 checks passed
@somiljain2006
somiljain2006 deleted the Local-variable-refrence branch June 15, 2026 17:34
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.

Resolve references of local bindings

3 participants