-
-
Notifications
You must be signed in to change notification settings - Fork 17
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
Allow multiple instances of the server on a single process. #51
Merged
Merged
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
module Ionide.LanguageServerProtocol.Tests.StartWithSetup | ||
|
||
open Expecto | ||
open System.IO.Pipes | ||
open System.IO | ||
open Ionide.LanguageServerProtocol | ||
open Ionide.LanguageServerProtocol.Server | ||
|
||
type TestLspClient(sendServerNotification: ClientNotificationSender, sendServerRequest: ClientRequestSender) = | ||
inherit LspClient () | ||
|
||
let setupEndpoints(_: LspClient): Map<string, System.Delegate> = | ||
[] |> Map.ofList | ||
|
||
let requestWithContentLength(request: string) = | ||
@$"Content-Length: {request.Length} | ||
|
||
{request}" | ||
|
||
let shutdownRequest = @"{""jsonrpc"":""2.0"",""method"":""shutdown"",""id"":1}" | ||
|
||
let exitRequest = @"{""jsonrpc"":""2.0"",""method"":""exit"",""id"":1}" | ||
|
||
let tests = | ||
testList | ||
"startWithSetup" | ||
[ | ||
testAsync "can start up multiple times in same process" { | ||
use inputServerPipe1 = new AnonymousPipeServerStream() | ||
use inputClientPipe1 = new AnonymousPipeClientStream(inputServerPipe1.GetClientHandleAsString()) | ||
use outputServerPipe1 = new AnonymousPipeServerStream() | ||
|
||
use inputWriter1 = new StreamWriter(inputServerPipe1) | ||
inputWriter1.AutoFlush <- true | ||
let server1 = async { | ||
let result = (startWithSetup | ||
setupEndpoints | ||
inputClientPipe1 | ||
outputServerPipe1 | ||
TestLspClient | ||
defaultRpc) | ||
Expect.equal (int result) 0 "server startup failed" | ||
} | ||
|
||
let! server1Async = Async.StartChild(server1) | ||
|
||
use inputServerPipe2 = new AnonymousPipeServerStream() | ||
use inputClientPipe2 = new AnonymousPipeClientStream(inputServerPipe2.GetClientHandleAsString()) | ||
use outputServerPipe2 = new AnonymousPipeServerStream() | ||
|
||
use inputWriter2 = new StreamWriter(inputServerPipe2) | ||
inputWriter2.AutoFlush <- true | ||
let server2 = async { | ||
let result = (startWithSetup | ||
setupEndpoints | ||
inputClientPipe2 | ||
outputServerPipe2 | ||
TestLspClient | ||
defaultRpc) | ||
Expect.equal (int result) 0 "server startup failed" | ||
} | ||
|
||
let! server2Async = Async.StartChild(server2) | ||
|
||
inputWriter1.Write(requestWithContentLength(shutdownRequest)) | ||
inputWriter1.Write(requestWithContentLength(exitRequest)) | ||
|
||
inputWriter2.Write(requestWithContentLength(shutdownRequest)) | ||
inputWriter2.Write(requestWithContentLength(exitRequest)) | ||
|
||
do! server1Async | ||
do! server2Async | ||
} | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -874,7 +874,8 @@ let private serializationTests = | |
Data = None } | ||
testThereAndBackAgain item | ||
] | ||
Shotgun.tests ] | ||
Shotgun.tests | ||
StartWithSetup.tests ] | ||
|
||
[<Tests>] | ||
let tests = testList "LSP" [ serializationTests; Utils.tests ] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I just notice with Utils.Tests being here, maybe StartWithSetup.tests should be too, rather than at the end of the serializationTests. Dunno what maintainers want. |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
let requestWithContentLength(request: string) = $"Content-Length: {request.Length}\r\n\r\n{request}"
git can convert newlines in files, and since this is a string literal, it caused a problem when the underlying file bytes changed. It was coded on windows which is \r\n, but got converted to unix line endings on push which is \n only. The json rpc stream requires \r\n.
Their error message is actually bugged. They don't escape the slashes in their string so it prints an actual newline where they intended to print "\r\n". I'll probably make a PR over there.
Also note it can't be a @ literal string now, or that would literally put \r\n in the string instead of escaping and putting the return and new line bytes.