Skip to content

Fix Swift find_referencing_symbols: add --scratch-path and resolve via xcrun#1166

Open
Asher- wants to merge 2 commits intooraios:mainfrom
Asher-:fix/sourcekit-lsp-scratch-path-and-xcrun
Open

Fix Swift find_referencing_symbols: add --scratch-path and resolve via xcrun#1166
Asher- wants to merge 2 commits intooraios:mainfrom
Asher-:fix/sourcekit-lsp-scratch-path-and-xcrun

Conversation

@Asher-
Copy link
Copy Markdown
Contributor

@Asher- Asher- commented Mar 14, 2026

Summary

  • Pass --scratch-path to sourcekit-lsp — without it, there is no index store for background indexing, so textDocument/references always returns empty results. This is the root cause of Indexing time out error on a Swift project #876.
  • Resolve sourcekit-lsp via xcrun with DEVELOPER_DIR — on macOS, bare sourcekit-lsp can resolve to the Command Line Tools version (limited capabilities). Using xcrun --find with DEVELOPER_DIR=/Applications/Xcode.app/Contents/Developer gives the full Xcode version.
  • Increase local indexing delay from 5s to 10s — real-world Swift projects need more time for background indexing before the first references request.
  • Add retry logic for local runs — previously only CI retried on empty references; now local also retries once after a 3s delay.

Root Cause Analysis

Two issues combined to make find_referencing_symbols return empty for Swift:

  1. 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.

  2. 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

  • Verified find_referencing_symbols returns cross-file references for Swift structs and methods
  • Verified find_symbol and get_symbols_overview continue to work
  • Verified sourcekit-lsp process launches with correct path and --scratch-path argument
  • Verified fallback to bare sourcekit-lsp when xcrun is unavailable (Linux compatibility)
  • Run existing Swift test suite (test/solidlsp/swift/test_swift_basic.py)

Generated with Claude Code

Asher- and others added 2 commits March 14, 2026 07:14
…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>
Copy link
Copy Markdown
Contributor

@MischaPanch MischaPanch left a comment

Choose a reason for hiding this comment

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

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
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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"
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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")
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

our tests include references search without this. I'm perplexed as to why

@MischaPanch
Copy link
Copy Markdown
Contributor

@Asher- do you want to finalize this?

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.

2 participants