Skip to content

Commit 603632e

Browse files
authored
update LSP types and pyright (#2519)
1 parent 7a037da commit 603632e

File tree

5 files changed

+120
-30
lines changed

5 files changed

+120
-30
lines changed

.github/workflows/main.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ jobs:
4141
python-version: '3.8'
4242
- run: sudo apt update
4343
- run: sudo apt install --no-install-recommends -y x11-xserver-utils
44-
- run: pip3 install mypy==1.7.1 flake8==5.0.4 pyright==1.1.339 --user
44+
- run: pip3 install mypy==1.7.1 flake8==5.0.4 pyright==1.1.381 --user
4545
- run: echo "$HOME/.local/bin" >> $GITHUB_PATH
4646
- run: mypy stubs
4747
- run: flake8 plugin tests

plugin/core/input_handlers.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ def __init__(
7070
def list_items(self) -> ListItemsReturn:
7171
if self._initial_value is not None:
7272
sublime.set_timeout(self._select_and_reset)
73-
return [self._initial_value], 0 # pyright: ignore[reportGeneralTypeIssues]
73+
return [self._initial_value], 0 # pyright: ignore[reportReturnType]
7474
else:
7575
return self.get_list_items()
7676

@@ -123,7 +123,7 @@ def attach_listener(self) -> None:
123123
raise RuntimeError('Could not find the Command Palette input field view')
124124
self.listener = InputListener(self)
125125
self.listener.attach(buffer)
126-
if ST_VERSION < 4161:
126+
if ST_VERSION < 4161 and self.input_view:
127127
# Workaround for initial_selection not working; see https://github.com/sublimehq/sublime_text/issues/6175
128128
selection = self.input_view.sel()
129129
selection.clear()

plugin/core/protocol.py

+111-21
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ class SemanticTokenTypes(StrEnum):
4949
Operator = 'operator'
5050
Decorator = 'decorator'
5151
""" @since 3.17.0 """
52+
Label = 'label'
53+
""" @since 3.18.0 """
5254

5355

5456
class SemanticTokenModifiers(StrEnum):
@@ -118,7 +120,7 @@ class LSPErrorCodes(IntEnum):
118120
If a client decides that a result is not of any use anymore
119121
the client should cancel the request. """
120122
RequestCancelled = -32800
121-
""" The client has canceled a request and a server as detected
123+
""" The client has canceled a request and a server has detected
122124
the cancel. """
123125

124126

@@ -1780,6 +1782,48 @@ class InlineCompletionRegistrationOptions(TypedDict):
17801782
the request again. See also Registration#id. """
17811783

17821784

1785+
class TextDocumentContentParams(TypedDict):
1786+
""" Parameters for the `workspace/textDocumentContent` request.
1787+
1788+
@since 3.18.0
1789+
@proposed """
1790+
uri: 'DocumentUri'
1791+
""" The uri of the text document. """
1792+
1793+
1794+
class TextDocumentContentResult(TypedDict):
1795+
""" Result of the `workspace/textDocumentContent` request.
1796+
1797+
@since 3.18.0
1798+
@proposed """
1799+
text: str
1800+
""" The text content of the text document. Please note, that the content of
1801+
any subsequent open notifications for the text document might differ
1802+
from the returned content due to whitespace and line ending
1803+
normalizations done on the client """
1804+
1805+
1806+
class TextDocumentContentRegistrationOptions(TypedDict):
1807+
""" Text document content provider registration options.
1808+
1809+
@since 3.18.0
1810+
@proposed """
1811+
schemes: List[str]
1812+
""" The schemes for which the server provides content. """
1813+
id: NotRequired[str]
1814+
""" The id used to register the request. The id can be used to deregister
1815+
the request again. See also Registration#id. """
1816+
1817+
1818+
class TextDocumentContentRefreshParams(TypedDict):
1819+
""" Parameters for the `workspace/textDocumentContent/refresh` request.
1820+
1821+
@since 3.18.0
1822+
@proposed """
1823+
uri: 'DocumentUri'
1824+
""" The uri of the text document to refresh. """
1825+
1826+
17831827
class RegistrationParams(TypedDict):
17841828
registrations: List['Registration']
17851829

@@ -2567,7 +2611,13 @@ class WorkspaceSymbolParams(TypedDict):
25672611
""" The parameters of a {@link WorkspaceSymbolRequest}. """
25682612
query: str
25692613
""" A query string to filter symbols by. Clients may send an empty
2570-
string here to request all symbols. """
2614+
string here to request all symbols.
2615+
2616+
The `query`-parameter should be interpreted in a *relaxed way* as editors
2617+
will apply their own highlighting and scoring on the results. A good rule
2618+
of thumb is to match case-insensitive and to simply check that the
2619+
characters of *query* appear in their order in a candidate symbol.
2620+
Servers shouldn't use prefix, substring, or similar strict matching. """
25712621
workDoneToken: NotRequired['ProgressToken']
25722622
""" An optional token that a server can use to report work done progress. """
25732623
partialResultToken: NotRequired['ProgressToken']
@@ -3077,18 +3127,12 @@ class Position(TypedDict):
30773127
30783128
@since 3.17.0 - support for negotiated position encoding. """
30793129
line: Uint
3080-
""" Line position in a document (zero-based).
3081-
3082-
If a line number is greater than the number of lines in a document, it defaults back to the number of lines in the document.
3083-
If a line number is negative, it defaults to 0. """
3130+
""" Line position in a document (zero-based). """
30843131
character: Uint
30853132
""" Character offset on a line in a document (zero-based).
30863133
30873134
The meaning of this offset is determined by the negotiated
3088-
`PositionEncodingKind`.
3089-
3090-
If the character value is greater than the line length it defaults back to the
3091-
line length. """
3135+
`PositionEncodingKind`. """
30923136

30933137

30943138
class SelectionRangeOptions(TypedDict):
@@ -3597,6 +3641,15 @@ class InlineCompletionOptions(TypedDict):
35973641
workDoneProgress: NotRequired[bool]
35983642

35993643

3644+
class TextDocumentContentOptions(TypedDict):
3645+
""" Text document content provider options.
3646+
3647+
@since 3.18.0
3648+
@proposed """
3649+
schemes: List[str]
3650+
""" The schemes for which the server provides content. """
3651+
3652+
36003653
class Registration(TypedDict):
36013654
""" General parameters to register for a notification or to register a provider. """
36023655
id: str
@@ -3790,8 +3843,9 @@ class Diagnostic(TypedDict):
37903843
range: 'Range'
37913844
""" The range at which the message applies """
37923845
severity: NotRequired['DiagnosticSeverity']
3793-
""" The diagnostic's severity. Can be omitted. If omitted it is up to the
3794-
client to interpret diagnostics as error, warning, info or hint. """
3846+
""" The diagnostic's severity. To avoid interpretation mismatches when a
3847+
server is used with different clients it is highly recommended that servers
3848+
always provide a severity value. """
37953849
code: NotRequired[Union[int, str]]
37963850
""" The diagnostic's code, which usually appear in the user interface. """
37973851
codeDescription: NotRequired['CodeDescription']
@@ -4482,6 +4536,11 @@ class WorkspaceOptions(TypedDict):
44824536
""" The server is interested in notifications/requests for operations on files.
44834537
44844538
@since 3.16.0 """
4539+
textDocumentContent: NotRequired[Union['TextDocumentContentOptions', 'TextDocumentContentRegistrationOptions']]
4540+
""" The server supports the `workspace/textDocumentContent` request.
4541+
4542+
@since 3.18.0
4543+
@proposed """
44854544

44864545

44874546
class TextDocumentContentChangePartial(TypedDict):
@@ -4701,6 +4760,11 @@ class WorkspaceClientCapabilities(TypedDict):
47014760
47024761
@since 3.18.0
47034762
@proposed """
4763+
textDocumentContent: NotRequired['TextDocumentContentClientCapabilities']
4764+
""" Capabilities specific to the `workspace/textDocumentContent` request.
4765+
4766+
@since 3.18.0
4767+
@proposed """
47044768

47054769

47064770
class TextDocumentClientCapabilities(TypedDict):
@@ -4924,8 +4988,10 @@ class TextDocumentFilterLanguage(TypedDict):
49244988
""" A language id, like `typescript`. """
49254989
scheme: NotRequired[str]
49264990
""" A Uri {@link Uri.scheme scheme}, like `file` or `untitled`. """
4927-
pattern: NotRequired[str]
4928-
""" A glob pattern, like **​/*.{ts,js}. See TextDocumentFilter for examples. """
4991+
pattern: NotRequired['GlobPattern']
4992+
""" A glob pattern, like **​/*.{ts,js}. See TextDocumentFilter for examples.
4993+
4994+
@since 3.18.0 - support for relative patterns. """
49294995

49304996

49314997
class TextDocumentFilterScheme(TypedDict):
@@ -4936,8 +5002,10 @@ class TextDocumentFilterScheme(TypedDict):
49365002
""" A language id, like `typescript`. """
49375003
scheme: str
49385004
""" A Uri {@link Uri.scheme scheme}, like `file` or `untitled`. """
4939-
pattern: NotRequired[str]
4940-
""" A glob pattern, like **​/*.{ts,js}. See TextDocumentFilter for examples. """
5005+
pattern: NotRequired['GlobPattern']
5006+
""" A glob pattern, like **​/*.{ts,js}. See TextDocumentFilter for examples.
5007+
5008+
@since 3.18.0 - support for relative patterns. """
49415009

49425010

49435011
class TextDocumentFilterPattern(TypedDict):
@@ -4948,8 +5016,10 @@ class TextDocumentFilterPattern(TypedDict):
49485016
""" A language id, like `typescript`. """
49495017
scheme: NotRequired[str]
49505018
""" A Uri {@link Uri.scheme scheme}, like `file` or `untitled`. """
4951-
pattern: str
4952-
""" A glob pattern, like **​/*.{ts,js}. See TextDocumentFilter for examples. """
5019+
pattern: 'GlobPattern'
5020+
""" A glob pattern, like **​/*.{ts,js}. See TextDocumentFilter for examples.
5021+
5022+
@since 3.18.0 - support for relative patterns. """
49535023

49545024

49555025
class NotebookDocumentFilterNotebookType(TypedDict):
@@ -4960,7 +5030,7 @@ class NotebookDocumentFilterNotebookType(TypedDict):
49605030
""" The type of the enclosing notebook. """
49615031
scheme: NotRequired[str]
49625032
""" A Uri {@link Uri.scheme scheme}, like `file` or `untitled`. """
4963-
pattern: NotRequired[str]
5033+
pattern: NotRequired['GlobPattern']
49645034
""" A glob pattern. """
49655035

49665036

@@ -4972,7 +5042,7 @@ class NotebookDocumentFilterScheme(TypedDict):
49725042
""" The type of the enclosing notebook. """
49735043
scheme: str
49745044
""" A Uri {@link Uri.scheme scheme}, like `file` or `untitled`. """
4975-
pattern: NotRequired[str]
5045+
pattern: NotRequired['GlobPattern']
49765046
""" A glob pattern. """
49775047

49785048

@@ -4984,7 +5054,7 @@ class NotebookDocumentFilterPattern(TypedDict):
49845054
""" The type of the enclosing notebook. """
49855055
scheme: NotRequired[str]
49865056
""" A Uri {@link Uri.scheme scheme}, like `file` or `untitled`. """
4987-
pattern: str
5057+
pattern: 'GlobPattern'
49885058
""" A glob pattern. """
49895059

49905060

@@ -5188,6 +5258,15 @@ class FoldingRangeWorkspaceClientCapabilities(TypedDict):
51885258
@proposed """
51895259

51905260

5261+
class TextDocumentContentClientCapabilities(TypedDict):
5262+
""" Client capabilities for a text document content provider.
5263+
5264+
@since 3.18.0
5265+
@proposed """
5266+
dynamicRegistration: NotRequired[bool]
5267+
""" Text document content provider supports dynamic registration. """
5268+
5269+
51915270
class TextDocumentSyncClientCapabilities(TypedDict):
51925271
dynamicRegistration: NotRequired[bool]
51935272
""" Whether text document synchronization supports dynamic registration. """
@@ -5376,6 +5455,11 @@ class CodeLensClientCapabilities(TypedDict):
53765455
""" The client capabilities of a {@link CodeLensRequest}. """
53775456
dynamicRegistration: NotRequired[bool]
53785457
""" Whether code lens supports dynamic registration. """
5458+
resolveSupport: NotRequired['ClientCodeLensResolveOptions']
5459+
""" Whether the client supports resolving additional code lens
5460+
properties via a separate `codeLens/resolve` request.
5461+
5462+
@since 3.18.0 """
53795463

53805464

53815465
class DocumentLinkClientCapabilities(TypedDict):
@@ -5847,6 +5931,12 @@ class ClientCodeActionResolveOptions(TypedDict):
58475931
""" The properties that a client can resolve lazily. """
58485932

58495933

5934+
class ClientCodeLensResolveOptions(TypedDict):
5935+
""" @since 3.18.0 """
5936+
properties: List[str]
5937+
""" The properties that a client can resolve lazily. """
5938+
5939+
58505940
class ClientFoldingRangeKindOptions(TypedDict):
58515941
""" @since 3.18.0 """
58525942
valueSet: NotRequired[List['FoldingRangeKind']]

plugin/core/types.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
from .collections import DottedDict
33
from .file_watcher import FileWatcherEventType
44
from .logging import debug, set_debug_logging
5-
from .protocol import TextDocumentSyncKind
5+
from .protocol import ServerCapabilities, TextDocumentSyncKind, TextDocumentSyncOptions
66
from .url import filename_to_uri
77
from .url import parse_uri
88
from typing import Any, Callable, Dict, Generator, Iterable, List, Optional, TypedDict, TypeVar, Union
@@ -478,13 +478,13 @@ def method_to_capability(method: str) -> tuple[str, str]:
478478
return capability_path, registration_path
479479

480480

481-
def normalize_text_sync(textsync: None | int | dict[str, Any]) -> dict[str, Any]:
481+
def normalize_text_sync(textsync: TextDocumentSyncOptions | TextDocumentSyncKind | None) -> dict[str, Any]:
482482
"""
483483
Brings legacy text sync capabilities to the most modern format
484484
"""
485485
result: dict[str, Any] = {}
486486
if isinstance(textsync, int):
487-
change: dict[str, Any] | None = {"syncKind": textsync}
487+
change = {"syncKind": textsync}
488488
result["textDocumentSync"] = {"didOpen": {}, "save": {}, "didClose": {}, "change": change}
489489
elif isinstance(textsync, dict):
490490
new = {}
@@ -560,9 +560,9 @@ def unregister(
560560
self.remove(registration_path)
561561
return discarded
562562

563-
def assign(self, d: dict[str, Any]) -> None:
563+
def assign(self, d: ServerCapabilities) -> None:
564564
textsync = normalize_text_sync(d.pop("textDocumentSync", None))
565-
super().assign(d)
565+
super().assign(cast(dict, d))
566566
if textsync:
567567
self.update(textsync)
568568

tox.ini

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ per-file-ignores =
2222
deps =
2323
mypy==1.7.1
2424
flake8==5.0.4
25-
pyright==1.1.339
25+
pyright==1.1.381
2626
commands =
2727
# mypy disabled for main code as it doesn't currently support cyclic definitions - https://github.com/python/mypy/issues/731
2828
mypy stubs

0 commit comments

Comments
 (0)