Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix StrEnum values in initialize request #2487

Merged
merged 1 commit into from
May 29, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 26 additions & 25 deletions plugin/core/sessions.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@
from .types import SettingsRegistration
from .types import sublime_pattern_to_glob
from .types import WORKSPACE_DIAGNOSTICS_TIMEOUT
from .typing import StrEnum
from .url import filename_to_uri
from .url import parse_uri
from .url import unparse_uri
Expand Down Expand Up @@ -248,29 +249,29 @@ def on_post_exit_async(self, session: Session, exit_code: int, exception: Except
raise NotImplementedError()


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


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


def get_initialize_params(variables: dict[str, str], workspace_folders: list[WorkspaceFolder],
config: ClientConfig) -> InitializeParams:
completion_kinds = cast(List[CompletionItemKind], _enum_to_list(CompletionItemKind))
symbol_kinds = cast(List[SymbolKind], _enum_to_list(SymbolKind))
diagnostic_tag_value_set = cast(List[DiagnosticTag], _enum_to_list(DiagnosticTag))
completion_tag_value_set = cast(List[CompletionItemTag], _enum_to_list(CompletionItemTag))
symbol_tag_value_set = cast(List[SymbolTag], _enum_to_list(SymbolTag))
semantic_token_types = cast(List[str], _enum_like_class_to_list(SemanticTokenTypes))
completion_kinds = cast(List[CompletionItemKind], _int_enum_to_list(CompletionItemKind))
symbol_kinds = cast(List[SymbolKind], _int_enum_to_list(SymbolKind))
diagnostic_tag_value_set = cast(List[DiagnosticTag], _int_enum_to_list(DiagnosticTag))
completion_tag_value_set = cast(List[CompletionItemTag], _int_enum_to_list(CompletionItemTag))
symbol_tag_value_set = cast(List[SymbolTag], _int_enum_to_list(SymbolTag))
semantic_token_types = cast(List[str], _str_enum_to_list(SemanticTokenTypes))
if config.semantic_tokens is not None:
for token_type in config.semantic_tokens.keys():
if token_type not in semantic_token_types:
semantic_token_types.append(token_type)
semantic_token_modifiers = cast(List[str], _enum_like_class_to_list(SemanticTokenModifiers))
supported_markup_kinds = [MarkupKind.Markdown, MarkupKind.PlainText]
folding_range_kind_value_set = cast(List[FoldingRangeKind], _enum_like_class_to_list(FoldingRangeKind))
semantic_token_modifiers = cast(List[str], _str_enum_to_list(SemanticTokenModifiers))
supported_markup_kinds = cast(List[MarkupKind], [MarkupKind.Markdown.value, MarkupKind.PlainText.value])
folding_range_kind_value_set = cast(List[FoldingRangeKind], _str_enum_to_list(FoldingRangeKind))
first_folder = workspace_folders[0] if workspace_folders else None
general_capabilities: GeneralClientCapabilities = {
# https://microsoft.github.io/language-server-protocol/specification#regExp
Expand Down Expand Up @@ -382,15 +383,15 @@ def get_initialize_params(variables: dict[str, str], workspace_folders: list[Wor
"dynamicRegistration": True,
"codeActionLiteralSupport": {
"codeActionKind": {
"valueSet": [
CodeActionKind.QuickFix,
CodeActionKind.Refactor,
CodeActionKind.RefactorExtract,
CodeActionKind.RefactorInline,
CodeActionKind.RefactorRewrite,
CodeActionKind.SourceFixAll,
CodeActionKind.SourceOrganizeImports,
]
"valueSet": cast(List[CodeActionKind], [
CodeActionKind.QuickFix.value,
CodeActionKind.Refactor.value,
CodeActionKind.RefactorExtract.value,
CodeActionKind.RefactorInline.value,
CodeActionKind.RefactorRewrite.value,
CodeActionKind.SourceFixAll.value,
CodeActionKind.SourceOrganizeImports.value,
])
}
},
"dataSupport": True,
Expand Down Expand Up @@ -451,9 +452,9 @@ def get_initialize_params(variables: dict[str, str], workspace_folders: list[Wor
},
"tokenTypes": semantic_token_types,
"tokenModifiers": semantic_token_modifiers,
"formats": [
TokenFormat.Relative
],
"formats": cast(List[TokenFormat], [
TokenFormat.Relative.value
]),
"overlappingTokenSupport": False,
"multilineTokenSupport": True,
"augmentsSyntaxTokens": True
Expand All @@ -473,7 +474,7 @@ def get_initialize_params(variables: dict[str, str], workspace_folders: list[Wor
"executeCommand": {},
"workspaceEdit": {
"documentChanges": True,
"failureHandling": FailureHandlingKind.Abort,
"failureHandling": cast(FailureHandlingKind, FailureHandlingKind.Abort.value),
},
"workspaceFolders": True,
"symbol": {
Expand Down