@@ -57,6 +57,7 @@ class Client(
5757 sync_file : bool = True
5858 request_timeout : float = 5.0
5959 initialization_options : dict = field (factory = dict )
60+ unmanaged : bool = False
6061
6162 _server : Server = field (init = False )
6263 _buffer : LSPFileBuffer = field (factory = LSPFileBuffer , init = False )
@@ -122,7 +123,6 @@ def get_config_map(self) -> ConfigurationMap:
122123 def get_server (self ) -> Server :
123124 return self ._server
124125
125- @classmethod
126126 @classmethod
127127 @abstractmethod
128128 def create_default_servers (cls ) -> DefaultServers :
@@ -260,35 +260,40 @@ async def __asynccontextmanager__(self) -> AsyncGenerator[Self]:
260260 # since server notification can be sent before `initialize`
261261 tg .soonify (self ._dispatch_server_requests )(receiver )
262262
263- client_capabilities = build_client_capabilities (self .__class__ )
264- root_workspace = self .get_workspace ().get (DEFAULT_WORKSPACE_DIR )
265- root_path = root_workspace .path .as_posix () if root_workspace else None
266- root_uri = root_workspace .uri if root_workspace else None
267-
268- _ = await self ._initialize (
269- lsp_type .InitializeParams (
270- capabilities = client_capabilities ,
271- process_id = os .getpid (),
272- client_info = lsp_type .ClientInfo (
273- name = "lsp-lient" ,
274- version = "1.81.0-insider" ,
275- ),
276- locale = "en-us" ,
277- # if single workspace root provided,
278- # set both `root_path` and `root_uri` for compatibility
279- root_path = root_path ,
280- root_uri = root_uri ,
281- initialization_options = self .initialization_options ,
282- trace = lsp_type .TraceValue .Verbose ,
283- workspace_folders = self ._workspace .to_folders (),
263+ if not self .unmanaged :
264+ client_capabilities = build_client_capabilities (self .__class__ )
265+ root_workspace = self .get_workspace ().get (DEFAULT_WORKSPACE_DIR )
266+ root_path = root_workspace .path .as_posix () if root_workspace else None
267+ root_uri = root_workspace .uri if root_workspace else None
268+
269+ _ = await self ._initialize (
270+ lsp_type .InitializeParams (
271+ capabilities = client_capabilities ,
272+ process_id = os .getpid (),
273+ client_info = lsp_type .ClientInfo (
274+ name = "lsp-lient" ,
275+ version = "1.81.0-insider" ,
276+ ),
277+ locale = "en-us" ,
278+ # if single workspace root provided,
279+ # set both `root_path` and `root_uri` for compatibility
280+ root_path = root_path ,
281+ root_uri = root_uri ,
282+ initialization_options = self .initialization_options ,
283+ trace = lsp_type .TraceValue .Verbose ,
284+ workspace_folders = self ._workspace .to_folders (),
285+ )
284286 )
285- )
286287
287- if init_config := self .create_default_config ():
288- await self ._config .update_global (init_config )
288+ if init_config := self .create_default_config ():
289+ await self ._config .update_global (init_config )
289290
290291 try :
291292 yield self
292293 finally :
293- _ = await self ._shutdown ()
294- await self ._exit ()
294+ if not self .unmanaged :
295+ _ = await self ._shutdown ()
296+ await self ._exit ()
297+ else :
298+ await self .get_server ().kill ()
299+ tg .cancel_scope .cancel ()
0 commit comments