1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122
|
import sys
from typing import List, Dict, Optional, NewType, Any, Union
try:
from typing import TypeGuard
except ImportError:
from typing_extensions import TypeGuard
if sys.version_info >= (3, 8):
from typing import TypedDict, Literal
else:
from typing_extensions import TypedDict, Literal
##########################
### Standard LSP types ###
##########################
DocumentUri = NewType("DocumentUri", str)
class Position(TypedDict):
line: int
character: int
class Range(TypedDict):
start: Position
end: Position
class TextDocumentIdentifier(TypedDict):
uri: DocumentUri
class OptionalVersionedTextDocumentIdentifier(TextDocumentIdentifier):
version: Optional[int]
class TextEdit(TypedDict):
range: Range
newText: str
class TextDocumentEdit(TypedDict):
textDocument: OptionalVersionedTextDocumentIdentifier
edits: List[TextEdit] # FIXME: should be: list[TextEdit| AnnotatedTextEdit]
class WorkspaceEditWithChanges(TypedDict):
changes: Dict[DocumentUri, List[TextEdit]]
# documentChanges: Optional[list[TextDocumentEdit]] # FIXME: should be: (TextDocumentEdit | CreateFile | RenameFile | DeleteFile)[]
# changeAnnotations: ...
class WorkspaceEditWithDocumentChanges(TypedDict):
# changes: Optional[Dict[DocumentUri, List[TextEdit]]]
documentChanges: List[
TextDocumentEdit
] # FIXME: should be: (TextDocumentEdit | CreateFile | RenameFile | DeleteFile)[]
# changeAnnotations: ...
WorkspaceEdit = Union[WorkspaceEditWithChanges, WorkspaceEditWithDocumentChanges]
def is_workspace_edit_with_changes(
workspace_edit: WorkspaceEdit,
) -> TypeGuard[WorkspaceEditWithChanges]:
return "changes" in workspace_edit
def is_workspace_edit_with_document_changes(
workspace_edit: WorkspaceEdit,
) -> TypeGuard[WorkspaceEditWithDocumentChanges]:
return "documentChanges" in workspace_edit
class ApplyWorkspaceEditParams(TypedDict):
label: Optional[str]
edit: WorkspaceEdit
class Command(TypedDict):
title: str
command: str
arguments: Optional[List[Any]]
CodeActionKind = Literal[
"",
"quickfix",
"refactor",
"refactor.extract",
"refactor.inline",
"refactor.rewrite",
"source",
"source.organizeImports",
"source.fixAll",
]
class CodeAction(TypedDict):
title: str
kind: Optional[CodeActionKind]
# diagnostics: Optional[List[Diagnostic]]
# isPreferred: Optional[bool]
# disabled: Optional[_CodeActionDisabledReason]
# edit: Optional[WorkspaceEdit]
command: Optional[Command]
# data: Optional[Any]
########################
### pylsp-rope types ###
########################
DocumentContent = NewType("DocumentContent", str)
Line = NewType("Line", str)
LineNumber = NewType("LineNumber", int)
CharNumber = NewType("CharNumber", int)
|