2 Commits

Author SHA1 Message Date
offa
9529df5d68 Add Python 3.12 build (#85)
* Add Python 3.12 build

* Update typing extensions

* Remove Python 3.7
2023-12-31 13:02:53 +09:00
Raoul Wols
8cc05adcf4 Reply with MarkupContent in completion documentation (#87) 2023-10-26 14:06:42 +09:00
6 changed files with 35 additions and 25 deletions

View File

@@ -12,7 +12,7 @@ jobs:
strategy:
fail-fast: false
matrix:
python: ["3.7", "3.8", "3.9", "3.10", "3.11"]
python: ["3.8", "3.9", "3.10", "3.11", "3.12"]
os: [ubuntu-22.04, windows-2022]
steps:
- name: Checkout

View File

@@ -92,7 +92,7 @@ class CMakeLanguageServer(LanguageServer):
CompletionItem(
label=x,
kind=CompletionItemKind.Function,
documentation=self._api.get_command_doc(x),
documentation=self._get_command_doc(x),
insert_text=x,
)
for x in commands
@@ -104,7 +104,7 @@ class CMakeLanguageServer(LanguageServer):
CompletionItem(
label=x,
kind=CompletionItemKind.Variable,
documentation=self._api.get_variable_doc(x),
documentation=self._get_variable_doc(x),
insert_text=x,
)
for x in variables
@@ -129,7 +129,7 @@ class CMakeLanguageServer(LanguageServer):
CompletionItem(
label=x,
kind=CompletionItemKind.Module,
documentation=self._api.get_module_doc(x, False),
documentation=self._get_module_doc(x, False),
insert_text=x,
)
for x in modules
@@ -140,7 +140,7 @@ class CMakeLanguageServer(LanguageServer):
CompletionItem(
label=x,
kind=CompletionItemKind.Module,
documentation=self._api.get_module_doc(x, True),
documentation=self._get_module_doc(x, True),
insert_text=x,
)
for x in modules
@@ -175,27 +175,21 @@ class CMakeLanguageServer(LanguageServer):
@self.feature(TEXT_DOCUMENT_HOVER)
def hover(params: TextDocumentPositionParams) -> Optional[Hover]:
assert self._api is not None
api = self._api
word = self._cursor_word(params.text_document.uri, params.position, True)
if not word:
return None
candidates: List[Callable[[str], Optional[str]]] = [
lambda x: api.get_command_doc(x.lower()),
lambda x: api.get_variable_doc(x),
lambda x: api.get_module_doc(x, False),
lambda x: api.get_module_doc(x, True),
candidates: List[Callable[[str], Optional[MarkupContent]]] = [
lambda x: self._get_command_doc(x.lower()),
lambda x: self._get_variable_doc(x),
lambda x: self._get_module_doc(x, False),
lambda x: self._get_module_doc(x, True),
]
for c in candidates:
doc = c(word[0])
if doc is None:
continue
return Hover(
contents=MarkupContent(kind=MarkupKind.Markdown, value=doc),
range=word[1],
)
return Hover(contents=doc, range=word[1])
return None
@self.thread()
@@ -241,6 +235,21 @@ class CMakeLanguageServer(LanguageServer):
return word
return None
def _get_command_doc(self, command: str) -> Optional[MarkupContent]:
assert self._api is not None
docs = self._api.get_command_doc(command)
return None if docs is None else MarkupContent(MarkupKind.Markdown, docs)
def _get_variable_doc(self, variable: str) -> Optional[MarkupContent]:
assert self._api is not None
docs = self._api.get_variable_doc(variable)
return None if docs is None else MarkupContent(MarkupKind.Markdown, docs)
def _get_module_doc(self, module: str, package: bool) -> Optional[MarkupContent]:
assert self._api is not None
docs = self._api.get_module_doc(module, package)
return None if docs is None else MarkupContent(MarkupKind.Markdown, docs)
def main() -> None:
from argparse import ArgumentParser

6
pdm.lock generated
View File

@@ -549,12 +549,12 @@ files = [
[[package]]
name = "typing-extensions"
version = "4.4.0"
version = "4.9.0"
requires_python = ">=3.7"
summary = "Backported and Experimental Type Hints for Python 3.7+"
files = [
{file = "typing_extensions-4.4.0-py3-none-any.whl", hash = "sha256:16fa4864408f655d35ec496218b85f79b3437c829e93320c7c9215ccfd92489e"},
{file = "typing_extensions-4.4.0.tar.gz", hash = "sha256:1511434bb92bf8dd198c12b1cc812e800d4181cfcb867674e0f8279cc93087aa"},
{file = "typing_extensions-4.9.0-py3-none-any.whl", hash = "sha256:af72aea155e91adfc61c3ae9e0e342dbc0cba726d6cba4b6c72c1f34e47291cd"},
{file = "typing_extensions-4.9.0.tar.gz", hash = "sha256:23478f88c37f27d76ac8aee6c905017a143b0b1b886c3c9f66bc2fd94f9f5783"},
]
[[package]]

View File

@@ -8,7 +8,7 @@ authors = [
dependencies = [
"pygls>=1.1.1",
]
requires-python = ">=3.7.9,<3.12"
requires-python = ">=3.8.0,<3.13"
readme = "README.md"
license = {text = "MIT"}
keywords = ["cmake", "completion", "vim", "lsp"]

View File

@@ -19,6 +19,7 @@ from lsprotocol.types import (
FormattingOptions,
HoverParams,
InitializeParams,
MarkupContent,
Position,
TextDocumentIdentifier,
TextDocumentItem,
@@ -105,8 +106,8 @@ def test_completions(
response = _test_completion(client_server, datadir, "projec", context)
item = next(filter(lambda x: x.label == "project", response.items), None)
assert item is not None
assert isinstance(item.documentation, str)
assert "<PROJECT-NAME>" in item.documentation
assert isinstance(item.documentation, MarkupContent)
assert "<PROJECT-NAME>" in item.documentation.value
@pytest.mark.parametrize(

View File

@@ -1,5 +1,5 @@
[tox]
env_list = py{37,38,39,310,311}
env_list = py{38,39,310,311,312}
isolated_build = True
passenv = *
setenv =
@@ -7,11 +7,11 @@ setenv =
[gh-actions]
python =
3.7: py37
3.8: py38
3.9: py39
3.10: py310
3.11: py311
3.12: py312
[testenv]
allowlist_externals =