Skip to content

Commit

Permalink
✨ Support new LSP 3.18 request methods
Browse files Browse the repository at this point in the history
  • Loading branch information
michprev committed Sep 29, 2024
1 parent 8e73847 commit 5509398
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 2 deletions.
12 changes: 10 additions & 2 deletions wake/lsp/common_structures.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,12 +109,12 @@ class DiagnosticSeverity(IntEnum):

class DiagnosticTag(IntEnum):
UNNECESSARY = 1
"""
"""
Unused or unnecessary code
"""
DEPRECATED = 2
"""
Deprecated or obsolete code
Deprecated or obsolete code
"""


Expand Down Expand Up @@ -1248,3 +1248,11 @@ class InitializeParams(LspModel):
capabilities: ClientCapabilities
trace: Optional[TraceValue] = None
workspace_folders: Optional[List[WorkspaceFolder]] = None


class TextDocumentContentParams(LspModel):
uri: DocumentUri


class TextDocumentContentResult(LspModel):
text: str
5 changes: 5 additions & 0 deletions wake/lsp/methods.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ class RequestMethodEnum(StrEnum):
WORKSPACE_CODE_LENS_REFRESH = "workspace/codeLens/refresh"
WORKSPACE_DIAGNOSTIC = "workspace/diagnostic"
WORKSPACE_DIAGNOSTIC_REFRESH = "workspace/diagnostic/refresh"
WORKSPACE_FOLDING_RANGE_REFRESH = "workspace/foldingRange/refresh"

# File Operations
WORKSPACE_WILL_CREATE_FILES = "workspace/willCreateFiles"
Expand All @@ -50,6 +51,8 @@ class RequestMethodEnum(StrEnum):
WORKSPACE_DID_CHANGE_WATCHED_FILES = (
"workspace/didChangeWatchedFiles" # Notification
)
WORKSPACE_TEXT_DOCUMENT_CONTENT = "workspace/textDocumentContent"
WORKSPACE_TEXT_DOCUMENT_CONTENT_REFRESH = "workspace/textDocumentContent/refresh"

# Text Synchronization
TEXT_DOCUMENT_DID_OPEN = "textDocument/didOpen" # Notification
Expand Down Expand Up @@ -108,10 +111,12 @@ class RequestMethodEnum(StrEnum):
COLOR_PRESENTATION = "textDocument/colorPresentation"
FORMATTING = "textDocument/formatting"
RANGE_FORMATTING = "textDocument/rangeFormatting"
RANGES_FORMATTING = "textDocument/rangesFormatting"
ON_TYPE_FORMATTING = "textDocument/onTypeFormatting"
RENAME = "textDocument/rename"
PREPARE_RENAME = "textDocument/prepareRename"
LINKED_EDITING_RANGE = "textDocument/linkedEditingRange"
INLINE_COMPLETION = "textDocument/inlineCompletion"

# Other
CANCEL_REQUEST = "$/cancelRequest"
Expand Down
18 changes: 18 additions & 0 deletions wake/lsp/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@
SetTraceParams,
ShowMessageParams,
ShowMessageRequestParams,
TextDocumentContentParams,
TextDocumentContentResult,
WatchKind,
WorkDoneProgressBegin,
WorkDoneProgressCreateParams,
Expand Down Expand Up @@ -285,6 +287,10 @@ def __init__(
),
WorkspaceSymbol,
),
RequestMethodEnum.WORKSPACE_TEXT_DOCUMENT_CONTENT: (
self._workspace_text_document_content,
TextDocumentContentParams,
),
RequestMethodEnum.SAKE_COMPILE: (
lambda params: (
self.__sake_context.compile() # pyright: ignore reportAttributeAccessIssue
Expand Down Expand Up @@ -1540,3 +1546,15 @@ async def get_configuration(self) -> None:
return await self.send_request(
RequestMethodEnum.WORKSPACE_CONFIGURATION, params
)

async def _workspace_text_document_content(
self, params: TextDocumentContentParams
) -> TextDocumentContentResult:
file = uri_to_path(params.uri)

try:
return TextDocumentContentResult(text=file.read_text())
except FileNotFoundError:
raise LspError(ErrorCodes.RequestFailed, f"File not found: {file}")
except Exception as e:
raise LspError(ErrorCodes.RequestFailed, f"Failed to read file {file}: {e}")

0 comments on commit 5509398

Please sign in to comment.