11from __future__ import annotations
2+
23from LSP .plugin import Notification
3- from LSP .plugin .core .types import cast
4- from LSP .plugin .core .typing import Any , Callable , List , Mapping , Required , Tuple , TypedDict , Union
5- from LSP .plugin .core .protocol import Error , ExecuteCommandParams , LSPAny , Location
4+ from LSP .plugin .core .protocol import Error
65from LSP .plugin .locationpicker import LocationPicker
6+ from LSP .protocol import ExecuteCommandParams
7+ from LSP .protocol import Location
8+ from LSP .protocol import LSPAny
79from lsp_utils import notification_handler
810from lsp_utils import NpmClientHandler
911from pathlib import Path
12+ from typing import Any
13+ from typing import Callable
14+ from typing import cast
15+ from typing import final
16+ from typing import List
17+ from typing import Tuple
18+ from typing import TypedDict
19+ from typing import Union
20+ from typing_extensions import override
1021import sublime
1122
12- PACKAGE_NAME = __package__
23+ PACKAGE_NAME = str ( __package__ )
1324SERVER_DIRECTORY = 'server'
1425SERVER_NODE_MODULES = Path (SERVER_DIRECTORY ) / 'node_modules'
15- SERVER_BINARY_PATH = SERVER_NODE_MODULES / '@vue' / 'language-server' / 'bin' / 'vue-language-server.js'
26+ SERVER_BINARY_PATH = SERVER_NODE_MODULES / '@vue' / 'language-server' / 'bin' / 'vue-language-server.js'
1627
1728
1829class TypescriptTsserverCommandParams (TypedDict ):
19- file : Required [str ]
30+ file : str
31+
2032
2133TsserverRequestParams = Tuple [Tuple [int , str , Union [TypescriptTsserverCommandParams , List [str ]]]]
2234
@@ -29,38 +41,41 @@ def plugin_unloaded():
2941 LspVuePlugin .cleanup ()
3042
3143
44+ @final
3245class LspVuePlugin (NpmClientHandler ):
3346 package_name = PACKAGE_NAME
3447 server_directory = SERVER_DIRECTORY
35- server_binary_path = SERVER_BINARY_PATH
48+ server_binary_path = str ( SERVER_BINARY_PATH )
3649
3750 @classmethod
51+ @override
3852 def required_node_version (cls ) -> str :
3953 return '>=18'
4054
41- def on_pre_server_command (self , command : Mapping [str , Any ], done_callback : Callable [[], None ]) -> bool :
55+ @override
56+ def on_pre_server_command (self , command : ExecuteCommandParams , done_callback : Callable [[], None ]) -> bool :
4257 command_name = command ['command' ]
4358 if command_name == 'editor.action.showReferences' :
44- _ , __ , references = command [ 'arguments' ]
45- self ._handle_show_references (references )
59+ _ , __ , references = command . get ( 'arguments' , [ None , None , None ])
60+ self ._handle_show_references (cast ( list [ Location ], references ) )
4661 done_callback ()
4762 return True
4863 return False
4964
50- def _handle_show_references (self , references : List [Location ]) -> None :
65+ def _handle_show_references (self , references : list [Location ]) -> None :
5166 session = self .weaksession ()
5267 if not session :
5368 return
5469 view = sublime .active_window ().active_view ()
5570 if not view :
5671 return
5772 if len (references ) == 1 :
58- args = {
59- 'location' : references [0 ],
60- 'session_name' : session .config .name ,
61- }
6273 window = view .window ()
6374 if window :
75+ args : dict [str , Any ] = {
76+ 'location' : references [0 ],
77+ 'session_name' : session .config .name ,
78+ }
6479 window .run_command ('lsp_open_location' , args )
6580 elif references :
6681 LocationPicker (view , session , references , side_by_side = False )
@@ -87,12 +102,13 @@ def on_tsserver_request(self, params: TsserverRequestParams) -> None:
87102 'command' : 'typescript.tsserverRequest' ,
88103 'arguments' : [
89104 command_name ,
90- cast ( LSPAny , command_params ) ,
91- { 'isAsync' : True , 'lowPriority' : True },
105+ command_params ,
106+ {'isAsync' : True , 'lowPriority' : True },
92107 ]
93108 }
94- session .execute_command (execute_command_params , progress = False ) \
95- .then (lambda result : self ._on_execute_command_response (seq , result ))
109+ session .execute_command (execute_command_params , progress = False ).then (
110+ lambda result : self ._on_execute_command_response (seq , result )
111+ )
96112
97113 def _on_execute_command_response (self , seq : int , result : LSPAny | Error ) -> None :
98114 session = self .weaksession ()
0 commit comments