Sourcekit-lsp: index dosn't refresh after invoking `swift build` on linux

index doesn't refresh after invoking swift build on Linux instead it requires to restart vscode (as relaunching language server)

@blangmuir, is there any functionality like swift package watch which watches file changes and send notification to sourcekit-lsp to re-index

It ought to work if you build. We recently fixed an issue like this on master, so if you were using an older toolchain please try updating. If that doesn’t help, please file a bug on bugs.swift.org and mention which toolchain you’re using.

in my case I'm moving classes and structs to new location (new file) for example
Class Foo is moved from Foo.swift to Zoo.swift
in this case after swift build, I'll still get use of unresolved identifier

Swift version:

Swift version 5.1 (swift-5.1-RELEASE)
Target: x86_64-unknown-linux-gnu

Got it. This is about updating our compiler arguments we get from swiftpm for the live ASTs, not about the index updating. There has been some recent work to setup the APIs needed to update the settings inside SourceKit-LSP. SwiftPM itself doesn't currently expose an API to watch for all the relevant changes. There is support for file watching (FSWatch) that is used by the workspace for watching for Package.resolved changes. We want to do something similar, but watching for new/removed files in the target source directories as well as watching for modifications to the Package.swift file itself.

@blangmuir also are we getting workspace/didChangeWatchedFiles notification? or we need to implement it form client side ?

We're not subscribing for those notifications right now, and I'm not sure what (if anything) we should use it for. There's no guarantee that the client will provide it, so we need a solution on our side anyway, and there is no way to watch files outside the workspace. I don't think we could rely on it to watch files in the build directory, for example.

I have used the vscode fileWatcher on Package.swift to invalidate all the Task promices.
we can add fileWatcher on Sources in vscode extension and send didChangeWatchedFiles notification ?

My point is we want this to

  • work in editors other than VSCode
  • work with or without client-side file watching, since it may not be available

I'm curious why you're using he VSCode extension directly here instead of using workspace/didChangeWatchedFiles?

I'm using it for the vscode task to run list which is kind of client-side feature of vs. also the Package.swift watcher is only for to flush out tasks.

1 Like

Yes i agree with this one.

I have already pr on the task list feature, but require your further guidance on any improvements.

Terms of Service

Privacy Policy

Cookie Policy