lsp_tests.test_lsp_dpatches_series

tests/lsp_tests/test_lsp_dpatches_series.py
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
import textwrap

import pytest

from debputy.lsp.debputy_ls import DebputyLanguageServer
from debputy.lsprotocol.types import (
    TextDocumentIdentifier,
    SemanticTokensParams,
)

try:
    from debputy.lsp.lsp_debian_patches_series import (
        _debian_patches_semantic_tokens_full,
        _debian_patches_series_completions,
    )

    from pygls.server import LanguageServer
except ImportError:
    pass
from lsp_tests.lsp_tutil import (
    put_doc_no_cursor,
    resolve_semantic_tokens,
    resolved_semantic_token,
)


@pytest.mark.asyncio
async def test_dpatches_series_semantic_tokens(ls: "DebputyLanguageServer") -> None:
    doc_uri = "file:///nowhere/debian/patches/series"
    content = textwrap.dedent(
        """\
        # Some leading comment

        some.patch

        another-delta.diff # foo
"""
    )
    put_doc_no_cursor(
        ls,
        doc_uri,
        "debian/patches/series",
        content,
    )

    lines = content.splitlines(keepends=True)
    semantic_tokens = await _debian_patches_semantic_tokens_full(
        ls,
        SemanticTokensParams(TextDocumentIdentifier(doc_uri)),
    )
    resolved_semantic_tokens = resolve_semantic_tokens(lines, semantic_tokens)
    assert resolved_semantic_tokens is not None
    assert resolved_semantic_tokens == [
        resolved_semantic_token(0, 0, "# Some leading comment", "comment"),
        resolved_semantic_token(2, 0, "some.patch", "string"),
        resolved_semantic_token(4, 0, "another-delta.diff", "string"),
        resolved_semantic_token(4, len("another-delta.diff") + 1, "# foo", "comment"),
    ]