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