1 module null_server.extension; 2 3 import served.lsp.protocol; 4 import served.utils.events; 5 6 import core.thread; 7 import std.json; 8 9 alias members = __traits(derivedMembers, null_server.extension); 10 11 InitializeResult initialize(InitializeParams params) 12 { 13 ServerCapabilities ret; 14 ret.experimental = JSONValue("initialized null server"); 15 return InitializeResult(ret); 16 } 17 18 @protocolMethod("dummy/testString") 19 string testString(string param) 20 { 21 return param ~ "_ok"; 22 } 23 24 struct TestParams 25 { 26 string name; 27 int num; 28 string[] arr; 29 } 30 31 struct TestResult 32 { 33 string ret; 34 int a; 35 string[] x; 36 } 37 38 @protocolMethod("dummy/testStruct") 39 TestResult testStruct(TestParams param) 40 { 41 TestResult result; 42 result.ret = param.name ~ "_ok"; 43 result.a = param.num + 1; 44 result.x = param.arr; 45 return result; 46 } 47 48 @protocolMethod("dummy/testJson") 49 JSONValue testJson(JSONValue param) 50 { 51 return JSONValue([ 52 "orig": param, 53 "extra": JSONValue("hello") 54 ]); 55 } 56 57 @protocolMethod("dummy/testVoid") 58 int testVoid() 59 { 60 return 4; 61 } 62 63 @protocolNotification("dummy/testNotify") 64 void testNotify() 65 { 66 import app : rpc; 67 import std.stdio; 68 69 stderr.writeln("got notify"); 70 rpc.notifyMethod("dummy/replyNotify"); 71 } 72 73 @protocolMethod("dummy/testPartial") 74 int[] testPartial1() 75 { 76 Fiber.yield(); 77 return [1, 2]; 78 } 79 80 @protocolMethod("dummy/testPartial") 81 int[] testPartial2() 82 { 83 foreach (i; 0 .. 10) 84 Fiber.yield(); 85 return [3, 4]; 86 } 87 88 @protocolMethod("dummy/testPartial") 89 int[] testPartial3() 90 { 91 foreach (i; 0 .. 100) 92 Fiber.yield(); 93 return [5, 6]; 94 }