sourcekit-lsp icon indicating copy to clipboard operation
sourcekit-lsp copied to clipboard

Indexing-while-building shouldn't overwrite Package.resolved

Open nkcsgexi opened this issue 7 months ago • 2 comments

Swift version

No response

Platform

No response

Editor

VSCode/Cursor

Description

SourceKit-LSP should pass --force-resolved-versions when invoking SwiftPM for background indexing. This ensures:

  • SourceKit-LSP never writes to Package.resolved.
  • Indexing operates against the package state already on disk, which is the correct behavior — indexing should be read-only.
  • If packages are out of date, the resolution will fail, which is preferable to silently corrupting the resolved file.

This aligns with the principle that background indexing should be a read-only operation with respect to project state.

Steps to Reproduce

  1. Configure a Swift package project that requires --replace-scm-with-registry for correct dependency resolution.
  2. Set the flag in .vscode/settings.json:
    "swift.packageArguments": ["--replace-scm-with-registry"]
    
  3. Resolve dependencies normally — Package.resolved is correct.
  4. Wait for SourceKit-LSP background indexing to trigger a package resolution.
  5. Observe that Package.resolved is overwritten with dependencies resolved without the --replace-scm-with-registry flag.

Logging

No response

nkcsgexi avatar Apr 10 '26 18:04 nkcsgexi

Related issue https://github.com/swiftlang/sourcekit-lsp/issues/1877

tracymiranda avatar Apr 10 '26 18:04 tracymiranda

Seems to also cause https://github.com/swiftlang/swift-package-manager/issues/9924.

dschaefer2 avatar Apr 14 '26 15:04 dschaefer2