1
1
import uuid
2
2
from collections .abc import Iterable
3
3
from importlib .metadata import version
4
- from typing import cast , get_args
4
+ from typing import Final , cast , get_args
5
5
6
6
import attr
7
7
import cattrs
@@ -42,7 +42,7 @@ def make_import_text_edit(import_text: str) -> lsp.TextEdit:
42
42
43
43
44
44
def make_text_edit (edit : Edit ) -> lsp .TextEdit :
45
- node_range = edit .node .range ()
45
+ node_range : Final = edit .node .range ()
46
46
return lsp .TextEdit (
47
47
range = lsp .Range (
48
48
start = lsp .Position (line = node_range .start .line , character = node_range .start .column ),
@@ -55,7 +55,7 @@ def make_text_edit(edit: Edit) -> lsp.TextEdit:
55
55
def make_diagnostics (source : str ) -> Iterable [lsp .Diagnostic ]:
56
56
if not IMPORT_CONFIG :
57
57
return
58
- result = make_replacements (root = SgRoot (source , "python" ).root (), import_config = IMPORT_CONFIG )
58
+ result : Final = make_replacements (root = SgRoot (source , "python" ).root (), import_config = IMPORT_CONFIG )
59
59
60
60
for replacement in result .replacements :
61
61
if replacement .operation_type == AddFinal :
@@ -86,7 +86,7 @@ def make_diagnostics(source: str) -> Iterable[lsp.Diagnostic]:
86
86
def make_fixall_text_edits (source : str ) -> Iterable [lsp .TextEdit ]:
87
87
if not IMPORT_CONFIG :
88
88
return
89
- result = make_replacements (root = SgRoot (source , "python" ).root (), import_config = IMPORT_CONFIG )
89
+ result : Final = make_replacements (root = SgRoot (source , "python" ).root (), import_config = IMPORT_CONFIG )
90
90
91
91
for replacement in result .replacements :
92
92
for edit in replacement .edits :
@@ -147,7 +147,7 @@ def workspace_did_change_configuration(params: lsp.DidChangeConfigurationParams)
147
147
def did_open_did_save_did_change (
148
148
params : lsp .DidOpenTextDocumentParams | lsp .DidSaveTextDocumentParams | lsp .DidChangeTextDocumentParams ,
149
149
) -> None :
150
- text_document = LSP_SERVER .workspace .get_text_document (params .text_document .uri )
150
+ text_document : Final = LSP_SERVER .workspace .get_text_document (params .text_document .uri )
151
151
LSP_SERVER .publish_diagnostics (text_document .uri , diagnostics = list (make_diagnostics (text_document .source )))
152
152
153
153
@@ -163,12 +163,12 @@ def did_close(params: lsp.DidCloseTextDocumentParams) -> None:
163
163
),
164
164
)
165
165
def code_action (params : lsp .CodeActionParams ) -> list [lsp .CodeAction ] | None :
166
- requested_kinds = params .context .only or {lsp .CodeActionKind .QuickFix , lsp .CodeActionKind .SourceFixAll }
167
- actions : list [lsp .CodeAction ] = []
166
+ requested_kinds : Final = params .context .only or {lsp .CodeActionKind .QuickFix , lsp .CodeActionKind .SourceFixAll }
167
+ actions : Final [ list [lsp .CodeAction ] ] = []
168
168
169
169
if lsp .CodeActionKind .QuickFix in requested_kinds :
170
- text_document = LSP_SERVER .workspace .get_text_document (params .text_document .uri )
171
- our_diagnostics = [
170
+ text_document : Final = LSP_SERVER .workspace .get_text_document (params .text_document .uri )
171
+ our_diagnostics : Final = [
172
172
diagnostic for diagnostic in params .context .diagnostics if diagnostic .source == LSP_SERVER .name
173
173
]
174
174
@@ -210,7 +210,7 @@ def code_action(params: lsp.CodeActionParams) -> list[lsp.CodeAction] | None:
210
210
211
211
@LSP_SERVER .feature (lsp .CODE_ACTION_RESOLVE )
212
212
def resolve_code_action (params : lsp .CodeAction ) -> lsp .CodeAction :
213
- text_document = LSP_SERVER .workspace .get_text_document (cast (str , params .data ))
213
+ text_document : Final = LSP_SERVER .workspace .get_text_document (cast (str , params .data ))
214
214
params .edit = lsp .WorkspaceEdit (
215
215
document_changes = [
216
216
lsp .TextDocumentEdit (
0 commit comments