Fix Swift find_referencing_symbols: add --scratch-path and resolve via xcrun#1166
Fix Swift find_referencing_symbols: add --scratch-path and resolve via xcrun#1166Asher- wants to merge 2 commits intooraios:mainfrom
Conversation
…kit-lsp sourcekit-lsp was launched with no arguments, giving it no location to store its background index. Without --scratch-path, textDocument/references always returns empty because there is no index store for cross-file symbol resolution. - Pass --scratch-path <repo>/.build/sourcekit-lsp when launching - Increase local indexing delay from 5s to 10s (real projects need more time) - Add retry logic for local runs when references are empty, not just CI Fixes root cause of issue oraios#876. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
On macOS, bare sourcekit-lsp resolves to Command Line Tools version which has limited indexing capabilities. xcrun without DEVELOPER_DIR also resolves to CLT. Setting DEVELOPER_DIR=/Applications/Xcode.app/Contents/Developer gives the full Xcode sourcekit-lsp with proper background indexing support. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
MischaPanch
left a comment
There was a problem hiding this comment.
Thanks for the contribution! Just a few questions (see comments)
| time.sleep(5) | ||
| # If no references found, retry once after additional delay (indexing may still be in progress) | ||
| if not references: | ||
| retry_delay = 5 if os.getenv("CI") else 3 |
There was a problem hiding this comment.
This waits on every request, not just the first one. It shouldn't be needed, right? Empty references may be the correct result and always waiting for a long time there is not nice.
We introduced _get_wait_time_for_cross_file_referencing in the base class that is meant to be overridden in the child classes, seems like the implementation of sourcekit_lsp was never adapted to use it. This would be the preferred mechanism, there it's ensured that we wait only once.
| full-featured version when Xcode is installed. | ||
| """ | ||
| # Try xcrun with DEVELOPER_DIR pointing to Xcode (not Command Line Tools) | ||
| xcode_path = "/Applications/Xcode.app/Contents/Developer" |
There was a problem hiding this comment.
is this path always the same on each mac? Otherwise it could be passed with ls_specific_settings
|
|
||
| # sourcekit-lsp needs --scratch-path for background indexing and cross-file references. | ||
| # Without it, textDocument/references returns empty because there's no index store. | ||
| scratch_path = os.path.join(repository_root_path, ".build", "sourcekit-lsp") |
There was a problem hiding this comment.
our tests include references search without this. I'm perplexed as to why
fee8b1c to
d165272
Compare
|
@Asher- do you want to finalize this? |
Summary
Root Cause Analysis
Two issues combined to make find_referencing_symbols return empty for Swift:
ProcessLaunchInfo launched sourcekit-lsp with no arguments. SourceKit-LSP needs --scratch-path to have a location for its background index store. Without it, textDocument/references returns empty because there is no index data for cross-file symbol resolution.
On macOS with both Xcode and Command Line Tools installed, bare sourcekit-lsp resolves to /Library/Developer/CommandLineTools/usr/bin/sourcekit-lsp which has limited indexing capabilities compared to the Xcode version.
Test plan
Generated with Claude Code