VS Code has to be reloaded to make the LSP recognise that a new file belongs to the package

After adding a new Swift file to a VS Code project, the sourcekit-lsp extension doesn't seem to recognise that it belongs to the current package. I get "cannot find in scope" errors flagged in the new file if I try to use symbols defined elsewhere in the package, and in the package's existing files if I try to use symbols defined in the new file. I can fix it by reloading VS Code. Is there some way it can make the LSP aware of the new file or reload the LSP, and do this automatically when a new file is added?

This also seems to affect Xcode, as I have a SwiftPM & iOS Xcodeproj in the same workspace and if I delete or add files Xcode does not build them. Sounds like a bug in LSP

This is a known issue with sourcekit-lsp.

Is there some way it can make the LSP aware of the new file or reload the LSP, and do this automatically when a new file is added?

The closest thing I am aware of is the VSCode command "Developer: Restart Extension Host", which restarts all the extensions that are loaded. I'm not aware of a way to do it automatically when a file is added.

SourceKit-LSP is not currently used by Xcode and the mechanism it uses to determine which files are part of a target are different. For issues with Xcode I suggest filing an issue at http://feedbackassistant.apple.com with details of what you tried and what went wrong

Ah, good to know. I was mistaken in understanding that Xcode had started adopting it.

I've started working on this a bit - see this PR. The plan is to use LSP's file watching capabilities for editors that support it, although it will require that the Package.swift file be in the workspace (as editors such as VS Code don't support watching files outside of the workspace).

1 Like
Terms of Service

Privacy Policy

Cookie Policy