Skip to content
Merged
Show file tree
Hide file tree
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
19 changes: 9 additions & 10 deletions pygls/workspace/position_codec.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,10 @@
# limitations under the License. #
############################################################################
import logging
from typing import List, Optional, Union
from typing import Optional, Union, Sequence

from lsprotocol import types


log = logging.getLogger(__name__)


Expand Down Expand Up @@ -64,7 +63,7 @@ def client_num_units(self, chars: str):
return utf32_units + self.utf16_unit_offset(chars)

def position_from_client_units(
self, lines: List[str], position: types.Position
self, lines: Sequence[str], position: types.Position
) -> types.Position:
"""
Convert the position.character from UTF-[32|16|8] code units to UTF-32.
Expand All @@ -84,7 +83,7 @@ def position_from_client_units(
see: https://github.com/microsoft/language-server-protocol/issues/376

Arguments:
lines (list):
lines (sequence):
The content of the document which the position refers to.
position (Position):
The line and character offset in UTF-[32|16|8] code units.
Expand Down Expand Up @@ -138,14 +137,14 @@ def position_from_client_units(
return position

def position_to_client_units(
self, lines: List[str], position: types.Position
self, lines: Sequence[str], position: types.Position
) -> types.Position:
"""
Convert the position.character from its internal UTF-32 representation
to client-supported UTF-[32|16|8] code units.

Arguments:
lines (list):
lines (sequence):
The content of the document which the position refers to.
position (Position):
The line and character offset in UTF-32 code units.
Expand All @@ -165,13 +164,13 @@ def position_to_client_units(
return types.Position(line=len(lines), character=0)

def range_from_client_units(
self, lines: List[str], range: types.Range
self, lines: Sequence[str], range: types.Range
) -> types.Range:
"""
Convert range.[start|end].character from UTF-[32|16|8] code units to UTF-32.

Arguments:
lines (list):
lines (sequence):
The content of the document which the range refers to.
range (Range):
The line and character offset in UTF-[32|16|8] code units.
Expand All @@ -186,13 +185,13 @@ def range_from_client_units(
return range_new

def range_to_client_units(
self, lines: List[str], range: types.Range
self, lines: Sequence[str], range: types.Range
) -> types.Range:
"""
Convert range.[start|end].character from UTF-32 to UTF-[32|16|8] code units.

Arguments:
lines (list):
lines (sequence):
The content of the document which the range refers to.
range (Range):
The line and character offset in code units.
Expand Down
6 changes: 3 additions & 3 deletions pygls/workspace/text_document.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import os
import pathlib
import re
from typing import List, Optional, Pattern
from typing import Optional, Pattern, Sequence

from lsprotocol import types

Expand Down Expand Up @@ -163,8 +163,8 @@ def apply_change(self, change: types.TextDocumentContentChangeEvent) -> None:
self._apply_full_change(change)

@property
def lines(self) -> List[str]:
return self.source.splitlines(True)
def lines(self) -> Sequence[str]:
return tuple(self.source.splitlines(True))

def offset_at_position(self, client_position: types.Position) -> int:
"""Return the character offset pointed at by the given client_position."""
Expand Down
12 changes: 6 additions & 6 deletions tests/test_document.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def test_document_end_of_file_edit():
)
doc.apply_change(change)

assert doc.lines == [
assert list(doc.lines) == [
"print 'a'\n",
"print 'b'\n",
"o",
Expand All @@ -73,7 +73,7 @@ def test_document_full_edit():
)
doc.apply_change(change)

assert doc.lines == ["print a, b"]
assert list(doc.lines) == ["print a, b"]

doc = TextDocument(
"file:///uri", "".join(old), sync_kind=types.TextDocumentSyncKind.Full
Expand All @@ -87,7 +87,7 @@ def test_document_full_edit():
)
doc.apply_change(change)

assert doc.lines == ["print a, b"]
assert list(doc.lines) == ["print a, b"]


def test_document_line_edit():
Expand Down Expand Up @@ -125,7 +125,7 @@ def test_document_multiline_edit():
)
doc.apply_change(change)

assert doc.lines == ["def hello(a, b):\n", " print a, b\n"]
assert list(doc.lines) == ["def hello(a, b):\n", " print a, b\n"]

doc = TextDocument(
"file:///uri", "".join(old), sync_kind=types.TextDocumentSyncKind.Incremental
Expand All @@ -139,7 +139,7 @@ def test_document_multiline_edit():
)
doc.apply_change(change)

assert doc.lines == ["def hello(a, b):\n", " print a, b\n"]
assert list(doc.lines) == ["def hello(a, b):\n", " print a, b\n"]


def test_document_no_edit():
Expand All @@ -157,7 +157,7 @@ def test_document_no_edit():
)
doc.apply_change(change)

assert doc.lines == old
assert list(doc.lines) == old


def test_document_props():
Expand Down
Loading