-
-
Notifications
You must be signed in to change notification settings - Fork 3
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
Refactor to improve tests #37
Conversation
This way of testing doesn’t require to use any delays or timeouts. This also works by sending a response, awaiting a reply, then asserting the reply, instead of sending a number of requests only to assert all responses together later. Also any logging messages sent from the connection.console are logged to the console in tests. All of these changes together make troubleshooting any tests much nicer to deal with.
One more test is remaining. It got stuck after rewriting.
This check was previously deemed unreachable, but it can be reached.
This comment has been minimized.
This comment has been minimized.
What's up with CI? |
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.
Couple Qs! Looks pretty good. What do you make of the CI failure?
I think I’ve seen this CI failure locally once across running the tests dozens of times locally. It must be a rare race condition. I’ll investigate. |
This is essentially a type-safe variant of vscode-jsonrpc
This comment was marked as resolved.
This comment was marked as resolved.
@@ -82,6 +82,7 @@ | |||
"typeCoverage": { | |||
"atLeast": 100, | |||
"detail": true, | |||
"ignoreNested": true, |
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 added this, because InitializeRequest.type
is of type ProtocolRequestType<_InitializeParams & WorkspaceFoldersInitializeParams & WorkDoneProgressParams, InitializeResult<any>, never, InitializeError, void>
.
In other words: An upstream type includes an any
type, which we don’t even use.
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.
Oh interesting. I didn’t know about this field. It sounds like it might be useful in other projects too
}) | ||
const connection = startLanguageServer(t, 'remark.js', '.') | ||
const initializeResponse = await connection.sendRequest( | ||
InitializeRequest.type, |
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 a fan of these *.type
s (e.g., InitializeRequest.type
s). It requires knowing this VS Code project that doesn’t have docs. I am not a fan of depending on projects that are not documented (and whose code is unreadable).
Can we somehow pass, say, 'initialize'
, to, well, send an initialize
event?
Rest looks good!
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.
The use of *.type
is what allows to infer the request and response types. It’s not a string, but an object which is typed in a way that allows TypeScript to infer types. Using a string removes type safety, meaning we need to manually add type annotations instead.
Personally I’m not a fan of how this has been implemented by vscode-languageserver-protocol
either, but I do think this is the way to go. This protects us from using wrong request and response types, and it closely resembles how a real client would implement it.
As for the project being undocumented: A basic usage example is missing from their readme, but once you get that figured out, the rest is both pretty self-explanatory and well documented through jsdoc.
Anything particar to check otherwise? Stuff you're 🤔🤷♂️ about? |
I’m not fond of the last commit (4e7e25d), but it’s an upstream issue. It might be note-worthy to state I reran |
thanks! |
This comment has been minimized.
This comment has been minimized.
https://github.com/unifiedjs/unified-language-server/blame/8efe2bc5bb9a2867e9033b269c7351dce79f37d5/test/index.js#L753 seems to indicate that On L1 in
Yields:
|
You need to write |
Ohhh right pff. |
I mean for the server to hijack the global console in the server process, so any console output is also sent to the language client. I don’t think it makes sense for the language server to crash, just because some third party package calls |
it’s theoretically a bit weird how to do it if multiple servers are started, although I don’t see that practically happening? I was under the impression this error only occurred in the tests but now I’m not sure, as you say, I guess it occurs for anything that writes to stdout? Alternatively then we could point |
Only if the server is started using the I created #41 for further discussion. |
Initial checklist
Description of changes
This check was previously deemed unreachable, but it can be reached.
This is based on #35.