11import json
22import sys
3- from typing import Optional
3+ from typing import Dict , List , Optional
44
55
66class RequestError (Exception ):
@@ -39,14 +39,14 @@ def run(self):
3939 try :
4040 result = self .handle_message (message )
4141 if result :
42- response_message : dict [str , object ] = {
42+ response_message : Dict [str , object ] = {
4343 "jsonrpc" : "2.0" ,
4444 "id" : message ["id" ],
4545 "result" : result ,
4646 }
4747 self .send_raw_message (response_message )
4848 except RequestError as e :
49- error_response_message : dict [str , object ] = {
49+ error_response_message : Dict [str , object ] = {
5050 "jsonrpc" : "2.0" ,
5151 "id" : message ["id" ],
5252 "error" : {
@@ -56,12 +56,12 @@ def run(self):
5656 }
5757 self .send_raw_message (error_response_message )
5858
59- def handle_message (self , message : dict [str , object ]) -> Optional [dict [str , object ]]:
59+ def handle_message (self , message : Dict [str , object ]) -> Optional [Dict [str , object ]]:
6060 """
6161 Dispatch handling of the given method, received from SourceKit-LSP to the message handling function.
6262 """
6363 method : str = str (message ["method" ])
64- params : dict [str , object ] = message ["params" ] # type: ignore
64+ params : Dict [str , object ] = message ["params" ] # type: ignore
6565 if method == "build/exit" :
6666 return self .exit (params )
6767 elif method == "build/initialize" :
@@ -77,7 +77,7 @@ def handle_message(self, message: dict[str, object]) -> Optional[dict[str, objec
7777 if "id" in message :
7878 raise RequestError (code = - 32601 , message = f"Method not found: { method } " )
7979
80- def send_raw_message (self , message : dict [str , object ]):
80+ def send_raw_message (self , message : Dict [str , object ]):
8181 """
8282 Send a raw message to SourceKit-LSP. The message needs to have all JSON-RPC wrapper fields.
8383
@@ -89,24 +89,37 @@ def send_raw_message(self, message: dict[str, object]):
8989 )
9090 sys .stdout .flush ()
9191
92- def send_notification (self , method : str , params : dict [str , object ]):
92+ def send_notification (self , method : str , params : Dict [str , object ]):
9393 """
9494 Send a notification with the given method and parameters to SourceKit-LSP.
9595 """
96- message : dict [str , object ] = {
96+ message : Dict [str , object ] = {
9797 "jsonrpc" : "2.0" ,
9898 "method" : method ,
9999 "params" : params ,
100100 }
101101 self .send_raw_message (message )
102102
103+ def send_sourcekit_options_changed (self , uri : str , options : List [str ]):
104+ """
105+ Send a `build/sourceKitOptionsChanged` notification to SourceKit-LSP, informing it about new build settings
106+ using the old push-based settings model.
107+ """
108+ self .send_notification (
109+ "build/sourceKitOptionsChanged" ,
110+ {
111+ "uri" : uri ,
112+ "updatedOptions" : {"options" : options },
113+ },
114+ )
115+
103116 # Message handling functions.
104117 # Subclasses should override these to provide functionality.
105118
106- def exit (self , notification : dict [str , object ]) -> None :
119+ def exit (self , notification : Dict [str , object ]) -> None :
107120 pass
108121
109- def initialize (self , request : dict [str , object ]) -> dict [str , object ]:
122+ def initialize (self , request : Dict [str , object ]) -> Dict [str , object ]:
110123 return {
111124 "displayName" : "test server" ,
112125 "version" : "0.1" ,
@@ -119,11 +132,11 @@ def initialize(self, request: dict[str, object]) -> dict[str, object]:
119132 },
120133 }
121134
122- def initialized (self , notification : dict [str , object ]) -> None :
135+ def initialized (self , notification : Dict [str , object ]) -> None :
123136 pass
124137
125- def register_for_changes (self , notification : dict [str , object ]):
138+ def register_for_changes (self , notification : Dict [str , object ]):
126139 pass
127140
128- def shutdown (self , notification : dict [str , object ]) -> None :
141+ def shutdown (self , notification : Dict [str , object ]) -> None :
129142 pass
0 commit comments