Skip to content

Commit 75e7b49

Browse files
committed
refactor: clean up types and linting
1 parent d84d9fd commit 75e7b49

4 files changed

Lines changed: 84 additions & 46 deletions

File tree

plugin.py

Lines changed: 35 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,34 @@
11
from __future__ import annotations
2+
23
from 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
65
from LSP.plugin.locationpicker import LocationPicker
6+
from LSP.protocol import ExecuteCommandParams
7+
from LSP.protocol import Location
8+
from LSP.protocol import LSPAny
79
from lsp_utils import notification_handler
810
from lsp_utils import NpmClientHandler
911
from 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
1021
import sublime
1122

12-
PACKAGE_NAME = __package__
23+
PACKAGE_NAME = str(__package__)
1324
SERVER_DIRECTORY = 'server'
1425
SERVER_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

1829
class TypescriptTsserverCommandParams(TypedDict):
19-
file: Required[str]
30+
file: str
31+
2032

2133
TsserverRequestParams = Tuple[Tuple[int, str, Union[TypescriptTsserverCommandParams, List[str]]]]
2234

@@ -29,38 +41,41 @@ def plugin_unloaded():
2941
LspVuePlugin.cleanup()
3042

3143

44+
@final
3245
class 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()

pyproject.toml

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
[tool.pyright]
2+
pythonVersion = "3.8"
3+
reportAny = "none"
4+
reportExplicitAny = "none"
5+
reportImplicitOverride = "none"
6+
reportIncompatibleMethodOverride = "none"
7+
reportMissingModuleSource = "none"
8+
reportUnannotatedClassAttribute = "none"
9+
reportUnknownArgumentType = "none"
10+
reportUnknownMemberType = "none"
11+
reportUnknownVariableType = "none"
12+
reportUnusedCallResult = "none"
13+
14+
[tool.ruff]
15+
line-length = 120
16+
target-version = "py38"
17+
18+
[tool.ruff.format]
19+
quote-style = "preserve"
20+
indent-style = "space"
21+
# Respect magic trailing commas.
22+
skip-magic-trailing-comma = false
23+
# Automatically detect the appropriate line ending.
24+
line-ending = "auto"
25+
26+
[tool.ruff.lint.isort]
27+
case-sensitive = false
28+
force-single-line = true
29+
from-first = true
30+
no-sections = true
31+
order-by-type = false
32+
required-imports = ["from __future__ import annotations"]
33+
34+
[tool.tox]
35+
env_list = ["py3"]
36+
skipsdist = true
37+
38+
[tool.tox.env_run_base]
39+
deps = [
40+
"pyright==1.1.408",
41+
"ruff==0.15.0",
42+
]
43+
commands = [
44+
# mypy disabled for main code as it doesn't currently support cyclic definitions - https://github.com/python/mypy/issues/731
45+
["pyright"],
46+
["ruff", "check"],
47+
["ruff", "format", "--check"],
48+
]
49+

pyrightconfig.json

Lines changed: 0 additions & 3 deletions
This file was deleted.

tox.ini

Lines changed: 0 additions & 24 deletions
This file was deleted.

0 commit comments

Comments
 (0)