-
-
Notifications
You must be signed in to change notification settings - Fork 50
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
35c9edc
commit 9e9d761
Showing
2 changed files
with
52 additions
and
28 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,20 +14,17 @@ import core.thread; | |
import core.thread.fiber; | ||
|
||
import served.lsp.filereader; | ||
import served.lsp.jsonops; | ||
import served.lsp.jsonrpc; | ||
import served.lsp.protocol; | ||
import served.lsp.uri; | ||
import served.lsp.jsonops; | ||
|
||
version (assert) | ||
{ | ||
} | ||
else | ||
static assert(false, "Compile with asserts."); | ||
|
||
__gshared RPCProcessor rpc; | ||
__gshared string cwd; | ||
|
||
// https://forum.dlang.org/post/[email protected] | ||
void copyDir(string inDir, string outDir) | ||
{ | ||
|
@@ -91,25 +88,6 @@ void main() | |
return; | ||
} | ||
|
||
void delegate(RequestMessageRaw msg) gotRequest; | ||
void delegate(RequestMessageRaw msg) gotNotify; | ||
|
||
shared static this() | ||
{ | ||
gotRequest = toDelegate(&defaultRequestHandler); | ||
gotNotify = toDelegate(&defaultNotifyHandler); | ||
} | ||
|
||
void defaultRequestHandler(RequestMessageRaw msg) | ||
{ | ||
assert(false, "Unexpected request " ~ msg.toString); | ||
} | ||
|
||
void defaultNotifyHandler(RequestMessageRaw msg) | ||
{ | ||
info("Ignoring notification " ~ msg.toString); | ||
} | ||
|
||
void pumpEvents() | ||
{ | ||
while (rpc.hasData) | ||
|
@@ -127,13 +105,13 @@ void doTests() | |
WorkspaceClientCapabilities workspace = { | ||
configuration: opt(true) | ||
}; | ||
InitializeParams init = { | ||
processId: thisProcessID, | ||
InitializeParams init = InitializeParams( | ||
processId: typeof(InitializeParams.processId)(thisProcessID), | ||
rootUri: uriFromFile(cwd), | ||
capabilities: { | ||
capabilities: ClientCapabilities( | ||
workspace: opt(workspace) | ||
} | ||
}; | ||
) | ||
); | ||
auto msg = rpc.sendRequest("initialize", init, 10.seconds); | ||
info("Response: ", msg.resultJson); | ||
|
||
|
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,46 @@ | ||
module tests; | ||
|
||
abstract class ServedTest | ||
{ | ||
abstract void run(); | ||
|
||
void tick() | ||
{ | ||
pumpEvents(); | ||
Fiber.yield(); | ||
} | ||
|
||
void processResponse(void delegate(RequestMessageRaw msg) cb) | ||
{ | ||
bool called; | ||
gotRequest = (msg) { | ||
called = true; | ||
cb(msg); | ||
}; | ||
tick(); | ||
assert(called, "no response received!"); | ||
gotRequest = null; | ||
} | ||
} | ||
|
||
__gshared RPCProcessor rpc; | ||
__gshared string cwd; | ||
|
||
__gshared void delegate(RequestMessageRaw msg) gotRequest; | ||
__gshared void delegate(RequestMessageRaw msg) gotNotify; | ||
|
||
shared static this() | ||
{ | ||
gotRequest = toDelegate(&defaultRequestHandler); | ||
gotNotify = toDelegate(&defaultNotifyHandler); | ||
} | ||
|
||
void defaultRequestHandler(RequestMessageRaw msg) | ||
{ | ||
assert(false, "Unexpected request " ~ msg.toString); | ||
} | ||
|
||
void defaultNotifyHandler(RequestMessageRaw msg) | ||
{ | ||
info("Ignoring notification " ~ msg.toString); | ||
} |