Skip to content

Commit 3229d89

Browse files
committed
Fix StrEnum values in initialize request
1 parent fc5a7c7 commit 3229d89

File tree

1 file changed

+26
-25
lines changed

1 file changed

+26
-25
lines changed

plugin/core/sessions.py

+26-25
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@
9898
from .types import SettingsRegistration
9999
from .types import sublime_pattern_to_glob
100100
from .types import WORKSPACE_DIAGNOSTICS_TIMEOUT
101+
from .typing import StrEnum
101102
from .url import filename_to_uri
102103
from .url import parse_uri
103104
from .url import unparse_uri
@@ -248,29 +249,29 @@ def on_post_exit_async(self, session: Session, exit_code: int, exception: Except
248249
raise NotImplementedError()
249250

250251

251-
def _enum_to_list(e: type[IntEnum]) -> list[int]:
252+
def _int_enum_to_list(e: type[IntEnum]) -> list[int]:
252253
return [v.value for v in e]
253254

254255

255-
def _enum_like_class_to_list(c: type[object]) -> list[int | str]:
256-
return [v for k, v in c.__dict__.items() if not k.startswith('_')]
256+
def _str_enum_to_list(e: type[StrEnum]) -> list[str]:
257+
return [v.value for v in e]
257258

258259

259260
def get_initialize_params(variables: dict[str, str], workspace_folders: list[WorkspaceFolder],
260261
config: ClientConfig) -> InitializeParams:
261-
completion_kinds = cast(List[CompletionItemKind], _enum_to_list(CompletionItemKind))
262-
symbol_kinds = cast(List[SymbolKind], _enum_to_list(SymbolKind))
263-
diagnostic_tag_value_set = cast(List[DiagnosticTag], _enum_to_list(DiagnosticTag))
264-
completion_tag_value_set = cast(List[CompletionItemTag], _enum_to_list(CompletionItemTag))
265-
symbol_tag_value_set = cast(List[SymbolTag], _enum_to_list(SymbolTag))
266-
semantic_token_types = cast(List[str], _enum_like_class_to_list(SemanticTokenTypes))
262+
completion_kinds = cast(List[CompletionItemKind], _int_enum_to_list(CompletionItemKind))
263+
symbol_kinds = cast(List[SymbolKind], _int_enum_to_list(SymbolKind))
264+
diagnostic_tag_value_set = cast(List[DiagnosticTag], _int_enum_to_list(DiagnosticTag))
265+
completion_tag_value_set = cast(List[CompletionItemTag], _int_enum_to_list(CompletionItemTag))
266+
symbol_tag_value_set = cast(List[SymbolTag], _int_enum_to_list(SymbolTag))
267+
semantic_token_types = cast(List[str], _str_enum_to_list(SemanticTokenTypes))
267268
if config.semantic_tokens is not None:
268269
for token_type in config.semantic_tokens.keys():
269270
if token_type not in semantic_token_types:
270271
semantic_token_types.append(token_type)
271-
semantic_token_modifiers = cast(List[str], _enum_like_class_to_list(SemanticTokenModifiers))
272-
supported_markup_kinds = [MarkupKind.Markdown, MarkupKind.PlainText]
273-
folding_range_kind_value_set = cast(List[FoldingRangeKind], _enum_like_class_to_list(FoldingRangeKind))
272+
semantic_token_modifiers = cast(List[str], _str_enum_to_list(SemanticTokenModifiers))
273+
supported_markup_kinds = cast(List[MarkupKind], [MarkupKind.Markdown.value, MarkupKind.PlainText.value])
274+
folding_range_kind_value_set = cast(List[FoldingRangeKind], _str_enum_to_list(FoldingRangeKind))
274275
first_folder = workspace_folders[0] if workspace_folders else None
275276
general_capabilities: GeneralClientCapabilities = {
276277
# https://microsoft.github.io/language-server-protocol/specification#regExp
@@ -382,15 +383,15 @@ def get_initialize_params(variables: dict[str, str], workspace_folders: list[Wor
382383
"dynamicRegistration": True,
383384
"codeActionLiteralSupport": {
384385
"codeActionKind": {
385-
"valueSet": [
386-
CodeActionKind.QuickFix,
387-
CodeActionKind.Refactor,
388-
CodeActionKind.RefactorExtract,
389-
CodeActionKind.RefactorInline,
390-
CodeActionKind.RefactorRewrite,
391-
CodeActionKind.SourceFixAll,
392-
CodeActionKind.SourceOrganizeImports,
393-
]
386+
"valueSet": cast(List[CodeActionKind], [
387+
CodeActionKind.QuickFix.value,
388+
CodeActionKind.Refactor.value,
389+
CodeActionKind.RefactorExtract.value,
390+
CodeActionKind.RefactorInline.value,
391+
CodeActionKind.RefactorRewrite.value,
392+
CodeActionKind.SourceFixAll.value,
393+
CodeActionKind.SourceOrganizeImports.value,
394+
])
394395
}
395396
},
396397
"dataSupport": True,
@@ -451,9 +452,9 @@ def get_initialize_params(variables: dict[str, str], workspace_folders: list[Wor
451452
},
452453
"tokenTypes": semantic_token_types,
453454
"tokenModifiers": semantic_token_modifiers,
454-
"formats": [
455-
TokenFormat.Relative
456-
],
455+
"formats": cast(List[TokenFormat], [
456+
TokenFormat.Relative.value
457+
]),
457458
"overlappingTokenSupport": False,
458459
"multilineTokenSupport": True,
459460
"augmentsSyntaxTokens": True
@@ -473,7 +474,7 @@ def get_initialize_params(variables: dict[str, str], workspace_folders: list[Wor
473474
"executeCommand": {},
474475
"workspaceEdit": {
475476
"documentChanges": True,
476-
"failureHandling": FailureHandlingKind.Abort,
477+
"failureHandling": cast(FailureHandlingKind, FailureHandlingKind.Abort.value),
477478
},
478479
"workspaceFolders": True,
479480
"symbol": {

0 commit comments

Comments
 (0)