Skip to content

Additions to the LSP module for workspace/didChangeWatchedFiles #376

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

Merged
merged 5 commits into from
Mar 17, 2021

Conversation

DavidGoldman
Copy link
Contributor

We can then use this functionality to allow a BuildSystem to watch
files (e.g. via the client or even in-process file watching),
which would allow us to do things like detect new files and provide
accurate build settings for them.


import Foundation

/// FIXME: Find a way to abstract this without deserializing.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure of a better generalization here, we could do something like what we do for Notifications/Requests but to store it we'd need to type erase it/box it (e.g. an AnyRegistrationOptions)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There aren't that many of these - is there a reason not to just make encodeToLSPAny a protocol requirement and implement it concretely for each concrete type that implements the protocol?

@DavidGoldman
Copy link
Contributor Author

@swift-ci please test


import Foundation

/// FIXME: Find a way to abstract this without deserializing.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There aren't that many of these - is there a reason not to just make encodeToLSPAny a protocol requirement and implement it concretely for each concrete type that implements the protocol?

We can then use this functionality to allow a `BuildSystem` to watch
files (e.g. via the client or even in-process file watching),
which would allow us to do things like detect new files and provide
accurate build settings for them.
@DavidGoldman
Copy link
Contributor Author

There aren't that many of these - is there a reason not to just make encodeToLSPAny a protocol requirement and implement it concretely for each concrete type that implements the protocol?

We could but then we'd probably want to implement it for all of the transitive types embedded there, also note that at the moment these really would only ever be encoded, not decoded since only the server sends them over.

@benlangmuir
Copy link
Contributor

We could but then we'd probably want to implement it for all of the transitive types embedded there, also note that at the moment these really would only ever be encoded, not decoded since only the server sends them over.

This is fine for now as long as we don't have a use case, but we generally expect to be able to write both client and server using this code.

We could but then we'd probably want to implement it for all of the transitive types embedded there

Is there something I'm missing? The ones added so far seem straightforward/shallow in terms of object graph.

@DavidGoldman
Copy link
Contributor Author

DavidGoldman commented Mar 15, 2021

We could but then we'd probably want to implement it for all of the transitive types embedded there, also note that at the moment these really would only ever be encoded, not decoded since only the server sends them over.

This is fine for now as long as we don't have a use case, but we generally expect to be able to write both client and server using this code.

We could but then we'd probably want to implement it for all of the transitive types embedded there

Is there something I'm missing? The ones added so far seem straightforward/shallow in terms of object graph.

Do we intend to keep LSPAny like it currently is? If so I wonder if it would be more useful to have a generalized encoder/decoder for it. Although that will be a bit more work it would save manually implementing all of these encoders/decoders. Also note that I didn't include all of the RegistrationOptions, there are more complex ones.

@benlangmuir
Copy link
Contributor

Do we intend to keep LSPAny like it currently is?

Is there a good alternative? We're using it for places where the spec allows any. It would be nice if this was builtin to Foundation so that we could transparently encode/decode between string and LSPAny and between LSPAny and Codable types.

@DavidGoldman
Copy link
Contributor Author

DavidGoldman commented Mar 15, 2021

Do we intend to keep LSPAny like it currently is?

Is there a good alternative? We're using it for places where the spec allows any. It would be nice if this was builtin to Foundation so that we could transparently encode/decode between string and LSPAny and between LSPAny and Codable types.

Right, if we had a proper JSON type that had Encoder/Decoder we could use that instead of LSPAny and LSPAnyCodable, I guess I was asking if we planned to keep LSPAnyCodable. The simplest thing to do here would be to implement LSPAnyCodable on all of the referenced types, but a general fix would be proper coders

@benlangmuir
Copy link
Contributor

I guess I was asking if we planned to keep LSPAnyCodable

LSPAnyCodable is a workaround for the lack of proper encoders/decoders, so from that perspective I'd be fine with getting rid of it if we had proper support. That being said, I'm not sure how big or complex the proper encoders/decoders would be to implement. If proper support reduced the number of lines of code by letting us throw out the LSPAnyCodable implementations, it would probably be an obvious win, but if it ends up being bigger than what we have it's harder to justify the maintenance.

@DavidGoldman
Copy link
Contributor Author

LSPAnyCodable is a workaround for the lack of proper encoders/decoders, so from that perspective I'd be fine with getting rid of it if we had proper support. That being said, I'm not sure how big or complex the proper encoders/decoders would be to implement. If proper support reduced the number of lines of code by letting us throw out the LSPAnyCodable implementations, it would probably be an obvious win, but if it ends up being bigger than what we have it's harder to justify the maintenance.

After looking into the stdlib's JSONEncoder/JSONDecoder which is quite large and complicated, I agree that we should stick with LSPAnyCodable for now, I'll swap it over.

@DavidGoldman
Copy link
Contributor Author

@swift-ci please test


public func encodeToLSPAny() -> LSPAny {
guard let wrapped = self else { return .null }
return wrapped.encodeToLSPAny()
Copy link
Contributor

@benlangmuir benlangmuir Mar 16, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we actually use the null encoding anywhere, or is this just for completeness? If possible I strongly prefer skipping nil values instead of encoding them as null since that seems to play nicer with other tools and saves space.

Edit: to be clear, I'm fine with keeping this conformance of Optional: LSPAnyCodable, particularly so that we can decode it correctly, I'm just wondering if it's used concretely in our code anywhere.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Swapped over the place that used it

@@ -23,6 +35,7 @@ extension SourceKitDTests {

public func __allTests() -> [XCTestCaseEntry] {
return [
testCase(CrashRecoveryTests.__allTests__CrashRecoveryTests),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops! Hope these are working on Linux...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, CI is failing but those errors link to

/home/buildnode/jenkins/workspace/swift-sourcekit-lsp-PR-Linux/tmp/TemporaryDirectory.YD3VQ4/pkg/Package.swift:3:5: error: type annotation missing in pattern
14:18:28 let pack

That seems like an unrelated issue that CI is picking up since it was present and enabled before in SwiftPMWorkspaceTests.testUnparsablePackage or perhaps something related to the diagnostics changed?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm it might be related to the sourcekitd tests?

From the logs:

Test Suite 'Selected tests' started at 2021-03-16 13:18:18.663
Test Suite 'CrashRecoveryTests' started at 2021-03-16 13:18:18.666
Test Case 'CrashRecoveryTests.testSourcekitdCrashRecovery' started at 2021-03-16 13:18:18.666

But I don't see it ever report the status of that test...

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's failing in CrashRecoveryTests.testSourcekitdCrashRecovery, which makes some sense since sourcekitd is in-process on Linux, so that test doesn't really make sense. We should just skip it on non-Darwin platforms. Feel free to either do that in this patch (some kind of try XCTSkipIf(...)) or else remove the changes related to enabling these tests on Linux and let me or @ahoppen deal with it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Gotcha, done

@DavidGoldman
Copy link
Contributor Author

@swift-ci please test

@DavidGoldman
Copy link
Contributor Author

@swift-ci please test

@DavidGoldman DavidGoldman merged commit e6b0796 into swiftlang:main Mar 17, 2021
@compnerd
Copy link
Member

This broke the Windows bootstrap :-(

compnerd added a commit to compnerd/sourcekit-lsp that referenced this pull request Mar 18, 2021
Update the source file list for the new files.  This repairs the
bootstrap build on Windows.
benlangmuir added a commit that referenced this pull request Mar 18, 2021
build: update the CMakeLists.txt after #376
@DavidGoldman
Copy link
Contributor Author

Is there any CI or pre-merge hooks for windows support? Or a script to run to update the CMake files or do you have to do it manually?

@compnerd
Copy link
Member

There're nightly builds at https://dev.azure.com/compnerd/swift-build

The CMake files need to be updated manually.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants