File: test_highlight.py

package info (click to toggle)
python-lsp-server 1.12.0-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 796 kB
  • sloc: python: 7,791; sh: 12; makefile: 4
file content (63 lines) | stat: -rw-r--r-- 1,737 bytes parent folder | download
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
# Copyright 2017-2020 Palantir Technologies, Inc.
# Copyright 2021- Python Language Server Contributors.

from pylsp import lsp, uris
from pylsp.plugins.highlight import pylsp_document_highlight
from pylsp.workspace import Document

DOC_URI = uris.from_fs_path(__file__)
DOC = """a = "hello"
a.startswith("b")
"""


def test_highlight(workspace) -> None:
    # Over 'a' in a.startswith
    cursor_pos = {"line": 1, "character": 0}

    doc = Document(DOC_URI, workspace, DOC)
    assert pylsp_document_highlight(doc, cursor_pos) == [
        {
            "range": {
                "start": {"line": 0, "character": 0},
                "end": {"line": 0, "character": 1},
            },
            # The first usage is Write
            "kind": lsp.DocumentHighlightKind.Write,
        },
        {
            "range": {
                "start": {"line": 1, "character": 0},
                "end": {"line": 1, "character": 1},
            },
            # The second usage is Read
            "kind": lsp.DocumentHighlightKind.Read,
        },
    ]


SYS_DOC = """import sys
print sys.path
"""


def test_sys_highlight(workspace) -> None:
    cursor_pos = {"line": 0, "character": 8}

    doc = Document(DOC_URI, workspace, SYS_DOC)
    assert pylsp_document_highlight(doc, cursor_pos) == [
        {
            "range": {
                "start": {"line": 0, "character": 7},
                "end": {"line": 0, "character": 10},
            },
            "kind": lsp.DocumentHighlightKind.Write,
        },
        {
            "range": {
                "start": {"line": 1, "character": 6},
                "end": {"line": 1, "character": 9},
            },
            "kind": lsp.DocumentHighlightKind.Read,
        },
    ]