Skip to content

Commit

Permalink
Use generated types for python 38 (#2500)
Browse files Browse the repository at this point in the history
* use generated types for python 3.8

* remove CompletionEditRange because it is no longer necessary

* fix flake8

* LSP only supports TextEdits for WorkspaceChanges currently

In the future we could remove the is_text_edit check when we add support for  `AnnotatedTextEdit` and `SnippetTextEdit`

* Implement activeParameter being `null` in 3.18 in which case the client should not higlight any parameter

* cast langauge_id to LanguageKind

* I should really setup flake8 locally

* a

* set "noActiveParameterSupport" to False

* remove accidentally committed file

* add space

* remove noActiveParameterSupport": False

* import on separate line

* one import per line

* change Enum to StrEnum

* remove unused import

* sort lines

* remove casting

* remove uint

* fix detecting textEdits not applying because .get('newText') was falsy

{'range': {'start': {'line': 1, 'character': 0}, 'end': {'line': 2, 'character': 0}}, 'newText': ''}

* address type issue

* allowed AnnotatedTextEdit

* fix syntax

---------

Co-authored-by: Rafał Chłodnicki <[email protected]>
Co-authored-by: Rafal Chlodnicki <[email protected]>
  • Loading branch information
3 people authored Aug 20, 2024
1 parent f983345 commit fe795a1
Show file tree
Hide file tree
Showing 5 changed files with 4,515 additions and 4,565 deletions.
4 changes: 2 additions & 2 deletions plugin/completion.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from .core.edit import apply_text_edits
from .core.logging import debug
from .core.promise import Promise
from .core.protocol import CompletionEditRange
from .core.protocol import EditRangeWithInsertReplace
from .core.protocol import CompletionItem
from .core.protocol import CompletionItemDefaults
from .core.protocol import CompletionItemKind
Expand Down Expand Up @@ -127,7 +127,7 @@ def is_range(val: Any) -> TypeGuard[Range]:
return isinstance(val, dict) and 'start' in val and 'end' in val


def is_edit_range(val: Any) -> TypeGuard[CompletionEditRange]:
def is_edit_range(val: Any) -> TypeGuard[EditRangeWithInsertReplace]:
return isinstance(val, dict) and 'insert' in val and 'replace' in val


Expand Down
11 changes: 8 additions & 3 deletions plugin/core/edit.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
from __future__ import annotations
from .logging import debug
from .protocol import AnnotatedTextEdit
from .protocol import Position
from .protocol import TextEdit
from .protocol import UINT_MAX
from .protocol import WorkspaceEdit
from typing import Dict, List, Optional, Tuple
from typing import Dict, List, Optional, Tuple, Union
import sublime


WorkspaceChanges = Dict[str, Tuple[List[TextEdit], Optional[int]]]
WorkspaceChanges = Dict[str, Tuple[List[Union[TextEdit, AnnotatedTextEdit]], Optional[int]]]


def parse_workspace_edit(workspace_edit: WorkspaceEdit) -> WorkspaceChanges:
Expand All @@ -24,7 +25,11 @@ def parse_workspace_edit(workspace_edit: WorkspaceEdit) -> WorkspaceChanges:
uri = text_document['uri']
version = text_document.get('version')
edits = document_change.get('edits')
changes.setdefault(uri, ([], version))[0].extend(edits)
for edit in edits:
if 'snippet' in edit:
debug('Ignoring unsupported SnippetTextEdit')
continue
changes.setdefault(uri, ([], version))[0].append(edit)
else:
raw_changes = workspace_edit.get('changes')
if isinstance(raw_changes, dict):
Expand Down
Loading

0 comments on commit fe795a1

Please sign in to comment.