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

Background indexing doesn't index packages in edit mode

Open adam-fowler opened this issue 1 year ago • 6 comments

Swift version

Apple Swift version 6.0.2 (swiftlang-6.0.2.1.2 clang-1600.0.26.4)

Platform

macOS 15

Editor

VS Code

Description

If I open a swift package and set one of its dependencies to be in edit mode the background indexing ignores this and still tries to index the project as if it is using the version of the dependency in .index-build.

Steps to Reproduce

  • Open package with dependencies in VSCode
  • Clone one of its dependencies in a separate folder
  • Right click on dependency in package dependencies view, select "Use Local Version" and select your local clone of that dependency. This is the equivalent of running `swift package edit -path
  • In main package right click on symbol from dependency and jump to definition
  • Note you jump to version in .index-build and not the local version

This is most likely caused by the fact that the package edit commands edit the workspace-state.json file and these changes are not propagated to the .index-build folder.

Logging

No response

adam-fowler avatar Dec 08 '24 08:12 adam-fowler

Synced to Apple’s issue tracker as rdar://141113619

ahoppen avatar Dec 08 '24 08:12 ahoppen

@ahoppen what are the chances this will get fixed for 6.1? This really breaks editing packages in VSCode

adam-fowler avatar Jan 16 '25 15:01 adam-fowler

The fix for this would require a major architectural redesign of how SourceKit-LSP interacts with SwiftPM’s workspace state and integrates with SwiftPM’s build folder. It’s out-of-scope for 6.1.

ahoppen avatar Jan 16 '25 16:01 ahoppen

Ok is there going to be a way to disable background indexing because editing packages just doesn't work with it.

adam-fowler avatar Jan 17 '25 00:01 adam-fowler

Yes, you can disable it via the SourceKit-LSP Configuration file and there’s also a setting in VS Code.

ahoppen avatar Jan 17 '25 16:01 ahoppen

Running into this as I work on SwiftPM with the swift-build dependency in edit mode.

dschaefer2 avatar Mar 14 '25 16:03 dschaefer2

Is this something that can be targeted for 6.2? I use package editing all the time and it is very frustrating.

adam-fowler avatar Apr 16 '25 14:04 adam-fowler

+1 from me. I'm trying to codevelop SwiftPM/swift-build on Windows and the environment is tough without this. But I need to understand how sourcekit-lsp is getting its build info from SwiftPM to see how much of a change it is.

dschaefer2 avatar Apr 16 '25 15:04 dschaefer2

As far as I understand it there are two workspace-state.json files (one in .build and one in .build/index-build) and only one Package.resolved. You run swift package edit and the Package.resolved and workspace-state.json in .build are updated. Then sourcekit-lsp comes along and updates the Package.resolved with the information in its own workspace-state.json in .build/index-build thus reverting your swift package edit.

adam-fowler avatar Apr 16 '25 16:04 adam-fowler

Ugh. This is definitely something I need for my swift build work on Windows/Linux. I'll grab some time over the next couple of days and dig into this a bit as well.

dschaefer2 avatar Apr 21 '25 14:04 dschaefer2

@dschaefer2 @ahoppen Is there any chance this will get resolved for Swift 6.2? It breaks all sorts of stuff having separate source trees for build and indexing.

adam-fowler avatar Jun 19 '25 14:06 adam-fowler

I've been told it would be very complicated to fix. As much as we need it for working on SwiftPM and swift-build at the same time we haven't had the time to take a look.

dschaefer2 avatar Jun 19 '25 15:06 dschaefer2

@bnbarham As we work in the interface between sourcekit-lsp and swiftpm --build-system SwiftBuild, I wonder if this is something we could take into account?

dschaefer2 avatar Jun 19 '25 15:06 dschaefer2

I wonder if this is something we could take into account?

It might help, but it's unlikely to come for free. The main difference between this and a full IDE is that we don't know when package resolution/a build is happening, so we'll likely need to add something like a file lock during package resolution to protect checkouts + workspace state here. That doesn't seem too bad, but also isn't particularly related to the swift-build move.

bnbarham avatar Jun 23 '25 22:06 bnbarham

so we'll likely need to add something like a file lock during package resolution to protect checkouts + workspace state here.

Doesn't SwiftPM already have this?

adam-fowler avatar Jun 24 '25 08:06 adam-fowler

Doesn't SwiftPM already have this?

There's a lock through the commands, I don't remember if that's the case in the API we're using (I thought it wasn't, but maybe I'm wrong). But this will all move into SwiftPM with the swift-build move, which should make this much simpler to handle.

bnbarham avatar Jun 24 '25 23:06 bnbarham