-
Notifications
You must be signed in to change notification settings - Fork 254
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add a BuildSystemDelegate
which supports notifications for build settings changes
#152
Conversation
Could you please squash this so we don't have a merge in the middle (or at least squash the changes up to and including the merge commit)? |
We don't need to nail all of this down right away, but I'm wondering about the split of responsibilities between notification and settings method.
|
Squashed, let me know if it looks OK.
That's a good point. What do you think? One option is for the I would assume that after a notification, the
Yeah, this seems reasonable. Potentially an optional, where null means the
Yeah, it's unclear what to do here if the |
I'm wary of using fallback settings in the interim, because it would cause us to create a semantic AST in sourcekitd that is almost certain to have errors. So you're wasting resources typechecking an AST, and you end up with bad diagnostics like failing to import every module. I think you only want to use fallback settings when the build system doesn't know about the file. You could instead open the document with no settings so that you get syntactic support right away.
Seems reasonable.
Yeah, for |
As an alternative then, we could remove the It's also worth noting that at the moment the |
Empty settings for swift means it will be syntax-only, so no semantic errors like module import failures. For clang I'm guessing clangd itself is going to choose fallback settings, but that's pretty hard to avoid. |
So how does removing the Edit: or alternatively keep |
This is my preference, provide the settings along with the notification, which may or may not ever come, and let the LSP service deal with lack of settings however it wants. If the build system can offer temporary or fallback settings, that is nice but not a requirement and it can do it by sending separate notifications. |
language: .swift, | ||
version: 12, | ||
text: """ | ||
func |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To test that the settings update is working correctly, I suggest using #if FOO
and changing the compiler arguments to add/remove -DFOO
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm this doesn't seem to be working, do I need to add in other Swift toolchain flags?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would expect it to work just like a command-line invocation of swiftc. E.g.
$ cat t.swift
#if FOO
func foo() {}
#endif
foo()
$ swiftc t.swift
t.swift:5:1: error: use of unresolved identifier 'foo'
foo()
^~~
$ swiftc t.swift -DFOO
# OK
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With just the build settings of -DFOO
I'm not seeing any diagnostics reported by SourceKit even with the above code
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In that example the diagnostics should be there when it is not defined.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not seeing any diagnostics in the Swift code although it's working fine for ObjC
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, sorry: you need to expect two notifications in Swift, because the syntactic errors (if any) come back immediately, but the semantic ones show up when the AST finishes typechecking/etc. You can see the way I've handled this in LocalSwiftTests.testEditing
, but basically you just pass a second handler. I think you want to just have the first handler be empty, then do the check in the second one where you know you have semantic errors.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Interesting, I'm not seeing a second notification, presumably because SourceKit doesn't have the proper arguments for semantic analysis? I'll try mirroring the flags from the fallback build system.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Works with the FallbackBuildSystem
@swift-ci please test |
That seems fine for now, although I think we'll want to bring back a way to do a one-off request for settings for things like background indexing in the future. But we can deal with it then. |
If we make background indexing an operation supported by the build server then we don't need to get settings, we'll just request the build server to produce index data for certain files. |
Good point. |
Do you think it would make sense for the |
It's not clear to me there's particular benefit, it makes the interaction model a bit more complicated since the LSP will wait for both the |
Ah, that makes sense if there's some sort of async communication protocol that we'd need to wait for. But if the BuildSystem is inside SourceKit-LSP / there's a synchronous channel to get them, you could potentially wait for the register call to return something and then trigger the open. e.g. No placeholder args Placeholder/temp args But I agree, we can always change this later on |
Initial fixes, still need to:
|
@swift-ci please test |
Tests added, is it ok if I remove the |
@swift-ci please test |
Ah looks like I need to merge with upstream to add support for the new BuildSystemBuildSystem from #151. Will do that tomorrow |
OK, added support, tests should be good now |
@swift-ci please test |
@swift-ci please test |
1 similar comment
@swift-ci please test |
…ttings changes Introduce a `BuildSystemDelegate` to handle notifications from the build system * `SourceKitServer` is the main delegate to process these notifications * Currently limited to changes in `FileBuildSettings` * Delegate informs the `BuildSystem` of files to watch via `registerChangeWatching(for: URL)` and `unregisterChangeWatching(for: URL)` * In the future we could have more integration for handling changes in dependencies Handling changes in `FileBuildSettings` * `SourceKitServer` sends notifications to the internal LSPs informing them of any opened documents that have changes in their compiler flags * For clangd, we send a notification to update the compilation database * For SourceKit/sourcekitd we must close and reopen the file to force a new AST with the new compiler flags
@swift-ci please test |
1 similar comment
@swift-ci please test |
Introduce a
BuildSystemDelegate
to handle notifications from the build systemSourceKitServer
is the main delegate to process these notificationsFileBuildSettings
BuildSystem
of files to watch viaregisterChangeWatching(for: URL)
andunregisterChangeWatching(for: URL)
Handling changes in
FileBuildSettings
SourceKitServer
sends notifications to the internal LSPs informing them of any opened documents that have changes in their compiler flags