diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index e8d364f..d3d105f 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -39,7 +39,7 @@ jobs: run: | cmake --version python -m pip install --upgrade setuptools pip wheel - python -m pip install tox tox-gh-actions tox-pdm + python -m pip install tox tox-gh-actions - name: Test with tox run: | tox diff --git a/cmake_language_server/server.py b/cmake_language_server/server.py index cb67941..7d83bd7 100644 --- a/cmake_language_server/server.py +++ b/cmake_language_server/server.py @@ -5,15 +5,14 @@ from pathlib import Path from typing import Any, Callable, List, Optional, Tuple -from pygls.lsp.methods import ( - COMPLETION, - FORMATTING, - HOVER, +from lsprotocol.types import ( + ALL_TYPES_MAP, INITIALIZE, INITIALIZED, + TEXT_DOCUMENT_COMPLETION, TEXT_DOCUMENT_DID_SAVE, -) -from pygls.lsp.types import ( + TEXT_DOCUMENT_FORMATTING, + TEXT_DOCUMENT_HOVER, CompletionItem, CompletionItemKind, CompletionList, @@ -38,6 +37,10 @@ logger = logging.getLogger(__name__) +# fix pygls bug +ALL_TYPES_MAP["TextDocumentSaveOptions"] = TextDocumentSaveRegistrationOptions + + class CMakeLanguageServer(LanguageServer): _api: Optional[API] @@ -60,7 +63,8 @@ def initialize(params: InitializeParams) -> None: trigger_characters = ["{", "("] @self.feature( - COMPLETION, CompletionOptions(trigger_characters=trigger_characters) + TEXT_DOCUMENT_COMPLETION, + CompletionOptions(trigger_characters=trigger_characters), ) def completions(params: CompletionParams) -> CompletionList: assert self._api is not None @@ -151,7 +155,7 @@ def completions(params: CompletionParams) -> CompletionList: if shutil.which("cmake-format") is not None: - @self.feature(FORMATTING) + @self.feature(TEXT_DOCUMENT_FORMATTING) def formatting( params: DocumentFormattingParams, ) -> Optional[List[TextEdit]]: @@ -174,7 +178,7 @@ def formatting( ) ] - @self.feature(HOVER) + @self.feature(TEXT_DOCUMENT_HOVER) def hover(params: TextDocumentPositionParams) -> Optional[Hover]: assert self._api is not None api = self._api @@ -256,4 +260,4 @@ def main() -> None: logging.basicConfig(level=logging.INFO) logging.getLogger("pygls").setLevel(logging.WARNING) - CMakeLanguageServer().start_io() # type: ignore + CMakeLanguageServer("cmake-language-server", __version__).start_io() # type: ignore diff --git a/pdm.lock b/pdm.lock index 3e70a0f..7bd52b6 100644 --- a/pdm.lock +++ b/pdm.lock @@ -20,16 +20,15 @@ dependencies = [ ] [[package]] -name = "cachetools" -version = "5.2.0" -requires_python = "~=3.7" -summary = "Extensible memoizing collections and decorators" - -[[package]] -name = "chardet" -version = "5.1.0" +name = "cattrs" +version = "22.2.0" requires_python = ">=3.7" -summary = "Universal encoding detector for Python 3" +summary = "Composable complex class support for attrs and dataclasses." +dependencies = [ + "attrs>=20", + "exceptiongroup; python_version < \"3.11\"", + "typing-extensions; python_version < \"3.8\"", +] [[package]] name = "click" @@ -72,39 +71,28 @@ dependencies = [ "tomli; python_full_version <= \"3.11.0a6\"", ] -[[package]] -name = "distlib" -version = "0.3.6" -summary = "Distribution utilities" - [[package]] name = "exceptiongroup" version = "1.1.0" requires_python = ">=3.7" summary = "Backport of PEP 654 (exception groups)" -[[package]] -name = "filelock" -version = "3.9.0" -requires_python = ">=3.7" -summary = "A platform independent file lock." - [[package]] name = "flake8" -version = "3.9.2" -requires_python = "!=3.0.*,!=3.1.*,!=3.2.*,!=3.3.*,!=3.4.*,>=2.7" +version = "5.0.4" +requires_python = ">=3.6.1" summary = "the modular source code checker: pep8 pyflakes and co" dependencies = [ - "importlib-metadata; python_version < \"3.8\"", - "mccabe<0.7.0,>=0.6.0", - "pycodestyle<2.8.0,>=2.7.0", - "pyflakes<2.4.0,>=2.3.0", + "importlib-metadata<4.3,>=1.1.0; python_version < \"3.8\"", + "mccabe<0.8.0,>=0.7.0", + "pycodestyle<2.10.0,>=2.9.0", + "pyflakes<2.6.0,>=2.5.0", ] [[package]] name = "importlib-metadata" -version = "6.0.0" -requires_python = ">=3.7" +version = "4.2.0" +requires_python = ">=3.6" summary = "Read metadata from Python packages" dependencies = [ "typing-extensions>=3.6.4; python_version < \"3.8\"", @@ -123,9 +111,20 @@ version = "5.11.4" requires_python = ">=3.7.0" summary = "A Python utility / library to sort Python imports." +[[package]] +name = "lsprotocol" +version = "2022.0.0a9" +requires_python = ">=3.7" +summary = "Python implementation of the Language Server Protocol." +dependencies = [ + "attrs", + "cattrs", +] + [[package]] name = "mccabe" -version = "0.6.1" +version = "0.7.0" +requires_python = ">=3.6" summary = "McCabe checker, plugin for flake8" [[package]] @@ -177,45 +176,26 @@ dependencies = [ [[package]] name = "pycodestyle" -version = "2.7.0" -requires_python = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*" +version = "2.9.1" +requires_python = ">=3.6" summary = "Python style guide checker" -[[package]] -name = "pydantic" -version = "1.9.2" -requires_python = ">=3.6.1" -summary = "Data validation and settings management using python type hints" -dependencies = [ - "typing-extensions>=3.7.4.3", -] - [[package]] name = "pyflakes" -version = "2.3.1" -requires_python = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*" +version = "2.5.0" +requires_python = ">=3.6" summary = "passive checker of Python programs" [[package]] name = "pygls" -version = "0.12.2" -requires_python = "<4,>=3.7" +version = "1.0.0" +requires_python = "<3.12,>=3.7" summary = "a pythonic generic language server (pronounced like \"pie glass\")." dependencies = [ - "pydantic<1.10,>=1.9.1", + "lsprotocol", "typeguard<3,>=2.10.0", ] -[[package]] -name = "pyproject-api" -version = "1.4.0" -requires_python = ">=3.7" -summary = "API to interact with the python pyproject.toml based projects" -dependencies = [ - "packaging>=21.3", - "tomli>=2.0.1; python_version < \"3.11\"", -] - [[package]] name = "pytest" version = "7.2.0" @@ -263,36 +243,6 @@ version = "2.0.1" requires_python = ">=3.7" summary = "A lil' TOML parser" -[[package]] -name = "tox" -version = "4.2.6" -requires_python = ">=3.7" -summary = "tox is a generic virtualenv management and test command line tool" -dependencies = [ - "cachetools>=5.2", - "chardet>=5.1", - "colorama>=0.4.6", - "filelock>=3.9", - "importlib-metadata>=5.2; python_version < \"3.8\"", - "packaging>=22", - "platformdirs>=2.6.2", - "pluggy>=1", - "pyproject-api>=1.2.1", - "tomli>=2.0.1; python_version < \"3.11\"", - "typing-extensions>=4.4; python_version < \"3.8\"", - "virtualenv>=20.17.1", -] - -[[package]] -name = "tox-pdm" -version = "0.6.1" -requires_python = ">=3.7" -summary = "A plugin for tox that utilizes PDM as the package manager and installer" -dependencies = [ - "tomli; python_version < \"3.11\"", - "tox>=3.18.0", -] - [[package]] name = "typed-ast" version = "1.5.4" @@ -311,18 +261,6 @@ version = "4.4.0" requires_python = ">=3.7" summary = "Backported and Experimental Type Hints for Python 3.7+" -[[package]] -name = "virtualenv" -version = "20.17.1" -requires_python = ">=3.6" -summary = "Virtual Python Environment builder" -dependencies = [ - "distlib<1,>=0.3.6", - "filelock<4,>=3.4.1", - "importlib-metadata>=4.8.3; python_version < \"3.8\"", - "platformdirs<3,>=2.4", -] - [[package]] name = "zipp" version = "3.11.0" @@ -331,7 +269,7 @@ summary = "Backport of pathlib-compatible object wrapper for zip files" [metadata] lock_version = "4.1" -content_hash = "sha256:33a613406f6c5d985a0b1d7812dbf4e4f5d20e6388391b1c0c786cf3742c677c" +content_hash = "sha256:34bc24c684193b4aeaa0328feb6cb42b999efc656241099c492907c411de224f" [metadata.files] "attrs 22.2.0" = [ @@ -352,13 +290,9 @@ content_hash = "sha256:33a613406f6c5d985a0b1d7812dbf4e4f5d20e6388391b1c0c786cf37 {url = "https://files.pythonhosted.org/packages/f1/b7/6de002378cfe0b83beba72f0a7875dfb6005b2a214ac9f9ca689583069ef/black-22.12.0-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:c116eed0efb9ff870ded8b62fe9f28dd61ef6e9ddd28d83d7d264a38417dcee2"}, {url = "https://files.pythonhosted.org/packages/f2/b9/06fe2dd83a2104d83c2b737f41aa5679f5a4395630005443ba4fa6fece8b/black-22.12.0-cp39-cp39-win_amd64.whl", hash = "sha256:559c7a1ba9a006226f09e4916060982fd27334ae1998e7a38b3f33a37f7a2148"}, ] -"cachetools 5.2.0" = [ - {url = "https://files.pythonhosted.org/packages/68/aa/5fc646cae6e997c3adf3b0a7e257cda75cff21fcba15354dffd67789b7bb/cachetools-5.2.0-py3-none-any.whl", hash = "sha256:f9f17d2aec496a9aa6b76f53e3b614c965223c061982d434d160f930c698a9db"}, - {url = "https://files.pythonhosted.org/packages/c2/6f/278225c5a070a18a76f85db5f1238f66476579fa9b04cda3722331dcc90f/cachetools-5.2.0.tar.gz", hash = "sha256:6a94c6402995a99c3970cc7e4884bb60b4a8639938157eeed436098bf9831757"}, -] -"chardet 5.1.0" = [ - {url = "https://files.pythonhosted.org/packages/41/32/cdc91dcf83849c7385bf8e2a5693d87376536ed000807fa07f5eab33430d/chardet-5.1.0.tar.gz", hash = "sha256:0d62712b956bc154f85fb0a266e2a3c5913c2967e00348701b32411d6def31e5"}, - {url = "https://files.pythonhosted.org/packages/74/8f/8fc49109009e8d2169d94d72e6b1f4cd45c13d147ba7d6170fb41f22b08f/chardet-5.1.0-py3-none-any.whl", hash = "sha256:362777fb014af596ad31334fde1e8c327dfdb076e1960d1694662d46a6917ab9"}, +"cattrs 22.2.0" = [ + {url = "https://files.pythonhosted.org/packages/43/3b/1d34fc4449174dfd2bc5ad7047a23edb6558b2e4b5a41b25a8ad6655c6c7/cattrs-22.2.0-py3-none-any.whl", hash = "sha256:bc12b1f0d000b9f9bee83335887d532a1d3e99a833d1bf0882151c97d3e68c21"}, + {url = "https://files.pythonhosted.org/packages/fc/da/ff3239eb4241cbc6f8b69f53d4ca27a178d51f9e5a954f1a3588c8227dc5/cattrs-22.2.0.tar.gz", hash = "sha256:f0eed5642399423cf656e7b66ce92cdc5b963ecafd041d1b24d136fdde7acf6d"}, ] "click 8.1.3" = [ {url = "https://files.pythonhosted.org/packages/59/87/84326af34517fca8c58418d148f2403df25303e02736832403587318e9e8/click-8.1.3.tar.gz", hash = "sha256:7682dc8afb30297001674575ea00d1814d808d6a36af415a82bd481d37ba7b8e"}, @@ -425,25 +359,17 @@ content_hash = "sha256:33a613406f6c5d985a0b1d7812dbf4e4f5d20e6388391b1c0c786cf37 {url = "https://files.pythonhosted.org/packages/fc/7c/3981bf2d56c998c7a7a3b0222bb0b9759f85ce3e93f5d912e39e9806814b/coverage-7.0.4-cp37-cp37m-win32.whl", hash = "sha256:2b5936b624fbe711ed02dfd86edd678822e5ee68da02b6d231e5c01090b64590"}, {url = "https://files.pythonhosted.org/packages/fc/9e/d0ebe8531c303a97ab088845bbca2d3167439876c76ea89024b6d63cc1cf/coverage-7.0.4-cp37-cp37m-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:bc74b64bfa89e2f862ea45dd6ac1def371d7cc883b76680d20bdd61a6f3daa20"}, ] -"distlib 0.3.6" = [ - {url = "https://files.pythonhosted.org/packages/58/07/815476ae605bcc5f95c87a62b95e74a1bce0878bc7a3119bc2bf4178f175/distlib-0.3.6.tar.gz", hash = "sha256:14bad2d9b04d3a36127ac97f30b12a19268f211063d8f8ee4f47108896e11b46"}, - {url = "https://files.pythonhosted.org/packages/76/cb/6bbd2b10170ed991cf64e8c8b85e01f2fb38f95d1bc77617569e0b0b26ac/distlib-0.3.6-py2.py3-none-any.whl", hash = "sha256:f35c4b692542ca110de7ef0bea44d73981caeb34ca0b9b6b2e6d7790dda8f80e"}, -] "exceptiongroup 1.1.0" = [ {url = "https://files.pythonhosted.org/packages/15/ab/dd27fb742b19a9d020338deb9ab9a28796524081bca880ac33c172c9a8f6/exceptiongroup-1.1.0.tar.gz", hash = "sha256:bcb67d800a4497e1b404c2dd44fca47d3b7a5e5433dbab67f96c1a685cdfdf23"}, {url = "https://files.pythonhosted.org/packages/e8/14/9c6a7e5f12294ccd6975a45e02899ed25468cd7c2c86f3d9725f387f9f5f/exceptiongroup-1.1.0-py3-none-any.whl", hash = "sha256:327cbda3da756e2de031a3107b81ab7b3770a602c4d16ca618298c526f4bec1e"}, ] -"filelock 3.9.0" = [ - {url = "https://files.pythonhosted.org/packages/0b/dc/eac02350f06c6ed78a655ceb04047df01b02c6b7ea3fc02d4df24ca87d24/filelock-3.9.0.tar.gz", hash = "sha256:7b319f24340b51f55a2bf7a12ac0755a9b03e718311dac567a0f4f7fabd2f5de"}, - {url = "https://files.pythonhosted.org/packages/14/4c/b201d0292ca4e0950f0741212935eac9996f69cd66b92a3587e594999163/filelock-3.9.0-py3-none-any.whl", hash = "sha256:f58d535af89bb9ad5cd4df046f741f8553a418c01a7856bf0d173bbc9f6bd16d"}, +"flake8 5.0.4" = [ + {url = "https://files.pythonhosted.org/packages/ad/00/9808c62b2d529cefc69ce4e4a1ea42c0f855effa55817b7327ec5b75e60a/flake8-5.0.4.tar.gz", hash = "sha256:6fbe320aad8d6b95cec8b8e47bc933004678dc63095be98528b7bdd2a9f510db"}, + {url = "https://files.pythonhosted.org/packages/cf/a0/b881b63a17a59d9d07f5c0cc91a29182c8e8a9aa2bde5b3b2b16519c02f4/flake8-5.0.4-py2.py3-none-any.whl", hash = "sha256:7a1cf6b73744f5806ab95e526f6f0d8c01c66d7bbe349562d22dfca20610b248"}, ] -"flake8 3.9.2" = [ - {url = "https://files.pythonhosted.org/packages/9e/47/15b267dfe7e03dca4c4c06e7eadbd55ef4dfd368b13a0bab36d708b14366/flake8-3.9.2.tar.gz", hash = "sha256:07528381786f2a6237b061f6e96610a4167b226cb926e2aa2b6b1d78057c576b"}, - {url = "https://files.pythonhosted.org/packages/fc/80/35a0716e5d5101e643404dabd20f07f5528a21f3ef4032d31a49c913237b/flake8-3.9.2-py2.py3-none-any.whl", hash = "sha256:bf8fd333346d844f616e8d47905ef3a3384edae6b4e9beb0c5101e25e3110907"}, -] -"importlib-metadata 6.0.0" = [ - {url = "https://files.pythonhosted.org/packages/26/a7/9da7d5b23fc98ab3d424ac2c65613d63c1f401efb84ad50f2fa27b2caab4/importlib_metadata-6.0.0-py3-none-any.whl", hash = "sha256:7efb448ec9a5e313a57655d35aa54cd3e01b7e1fbcf72dce1bf06119420f5bad"}, - {url = "https://files.pythonhosted.org/packages/90/07/6397ad02d31bddf1841c9ad3ec30a693a3ff208e09c2ef45c9a8a5f85156/importlib_metadata-6.0.0.tar.gz", hash = "sha256:e354bedeb60efa6affdcc8ae121b73544a7aa74156d047311948f6d711cd378d"}, +"importlib-metadata 4.2.0" = [ + {url = "https://files.pythonhosted.org/packages/22/51/52442c59db26637681148c21f8984eed58c9db67053a0a4783a047010c98/importlib_metadata-4.2.0-py3-none-any.whl", hash = "sha256:057e92c15bc8d9e8109738a48db0ccb31b4d9d5cfbee5a8670879a30be66304b"}, + {url = "https://files.pythonhosted.org/packages/c7/7c/126a8686399ebe256b5e4343ea80b6f2ee91549969da2eef0bb2891b8d24/importlib_metadata-4.2.0.tar.gz", hash = "sha256:b7e52a1f8dec14a75ea73e0891f3060099ca1d8e6a462a4dff11c3e119ea1b31"}, ] "iniconfig 2.0.0" = [ {url = "https://files.pythonhosted.org/packages/d7/4b/cbd8e699e64a6f16ca3a8220661b5f83792b3017d0f79807cb8708d33913/iniconfig-2.0.0.tar.gz", hash = "sha256:2d91e135bf72d31a410b17c16da610a82cb55f6b0477d1a902134b24a455b8b3"}, @@ -453,9 +379,13 @@ content_hash = "sha256:33a613406f6c5d985a0b1d7812dbf4e4f5d20e6388391b1c0c786cf37 {url = "https://files.pythonhosted.org/packages/76/46/004e2dd6c312e8bb7cb40a6c01b770956e0ef137857e82d47bd9c829356b/isort-5.11.4.tar.gz", hash = "sha256:6db30c5ded9815d813932c04c2f85a360bcdd35fed496f4d8f35495ef0a261b6"}, {url = "https://files.pythonhosted.org/packages/91/3b/a63bafb8141b67c397841b36ad46e7469716af2b2d00cb0be2dfb9667130/isort-5.11.4-py3-none-any.whl", hash = "sha256:c033fd0edb91000a7f09527fe5c75321878f98322a77ddcc81adbd83724afb7b"}, ] -"mccabe 0.6.1" = [ - {url = "https://files.pythonhosted.org/packages/06/18/fa675aa501e11d6d6ca0ae73a101b2f3571a565e0f7d38e062eec18a91ee/mccabe-0.6.1.tar.gz", hash = "sha256:dd8d182285a0fe56bace7f45b5e7d1a6ebcbf524e8f3bd87eb0f125271b8831f"}, - {url = "https://files.pythonhosted.org/packages/87/89/479dc97e18549e21354893e4ee4ef36db1d237534982482c3681ee6e7b57/mccabe-0.6.1-py2.py3-none-any.whl", hash = "sha256:ab8a6258860da4b6677da4bd2fe5dc2c659cff31b3ee4f7f5d64e79735b80d42"}, +"lsprotocol 2022.0.0a9" = [ + {url = "https://files.pythonhosted.org/packages/03/ed/412b60d1333c2b5441364568dc5f302fb748b80f4c3341f8cd6668336ed6/lsprotocol-2022.0.0a9-py3-none-any.whl", hash = "sha256:e4bc3d2ed71045f64cbe4d053bd6d45300a77b122b372a383914ce4ddb9c62d4"}, + {url = "https://files.pythonhosted.org/packages/bd/bc/d187025d533b66314997307d6ba46fc28090351d3bcce6d45bb79a84bdd9/lsprotocol-2022.0.0a9.tar.gz", hash = "sha256:db81eafc80485a6052f6771aaf6fb9cef58cb6409d510c60132f12c6e91d9182"}, +] +"mccabe 0.7.0" = [ + {url = "https://files.pythonhosted.org/packages/27/1a/1f68f9ba0c207934b35b86a8ca3aad8395a3d6dd7921c0686e23853ff5a9/mccabe-0.7.0-py2.py3-none-any.whl", hash = "sha256:6c2d30ab6be0e4a46919781807b4f0d834ebdd6c6e3dca0bda5a15f863427b6e"}, + {url = "https://files.pythonhosted.org/packages/e7/ff/0ffefdcac38932a54d2b5eed4e0ba8a408f215002cd178ad1df0f2806ff8/mccabe-0.7.0.tar.gz", hash = "sha256:348e0240c33b60bbdf4e523192ef919f28cb2c3d7d5c7794f74009290f236325"}, ] "mypy 0.991" = [ {url = "https://files.pythonhosted.org/packages/0e/5c/fbe112ca73d4c6a9e65336f48099c60800514d8949b4129c093a84a28dc8/mypy-0.991.tar.gz", hash = "sha256:3c0165ba8f354a6d9881809ef29f1a9318a236a6d81c690094c5df32107bde06"}, @@ -509,58 +439,17 @@ content_hash = "sha256:33a613406f6c5d985a0b1d7812dbf4e4f5d20e6388391b1c0c786cf37 {url = "https://files.pythonhosted.org/packages/9e/01/f38e2ff29715251cf25532b9082a1589ab7e4f571ced434f98d0139336dc/pluggy-1.0.0-py2.py3-none-any.whl", hash = "sha256:74134bbf457f031a36d68416e1509f34bd5ccc019f0bcc952c7b909d06b37bd3"}, {url = "https://files.pythonhosted.org/packages/a1/16/db2d7de3474b6e37cbb9c008965ee63835bba517e22cdb8c35b5116b5ce1/pluggy-1.0.0.tar.gz", hash = "sha256:4224373bacce55f955a878bf9cfa763c1e360858e330072059e10bad68531159"}, ] -"pycodestyle 2.7.0" = [ - {url = "https://files.pythonhosted.org/packages/02/b3/c832123f2699892c715fcdfebb1a8fdeffa11bb7b2350e46ecdd76b45a20/pycodestyle-2.7.0.tar.gz", hash = "sha256:c389c1d06bf7904078ca03399a4816f974a1d590090fecea0c63ec26ebaf1cef"}, - {url = "https://files.pythonhosted.org/packages/de/cc/227251b1471f129bc35e966bb0fceb005969023926d744139642d847b7ae/pycodestyle-2.7.0-py2.py3-none-any.whl", hash = "sha256:514f76d918fcc0b55c6680472f0a37970994e07bbb80725808c17089be302068"}, -] -"pydantic 1.9.2" = [ - {url = "https://files.pythonhosted.org/packages/04/bc/5231387df42b199f38dd3f29eb10338bc0a272e24020aff5c4cd64d3270d/pydantic-1.9.2-cp39-cp39-musllinux_1_1_i686.whl", hash = "sha256:7ead3cd020d526f75b4188e0a8d71c0dbbe1b4b6b5dc0ea775a93aca16256aeb"}, - {url = "https://files.pythonhosted.org/packages/18/2f/228fe5d1dbf7c36bd252fb304b015d02a50f696e659a0bb370a5628d00f4/pydantic-1.9.2-cp38-cp38-musllinux_1_1_i686.whl", hash = "sha256:bd67cb2c2d9602ad159389c29e4ca964b86fa2f35c2faef54c3eb28b4efd36c8"}, - {url = "https://files.pythonhosted.org/packages/36/23/e7609029b3a71c95613e132e8abcfae2bff2da0aa6d894bad2f0048a3895/pydantic-1.9.2-cp310-cp310-macosx_10_9_x86_64.whl", hash = "sha256:9c9e04a6cdb7a363d7cb3ccf0efea51e0abb48e180c0d31dca8d247967d85c6e"}, - {url = "https://files.pythonhosted.org/packages/4c/f3/b8e7c5b68515f6c0c881b0cd64c03b17e6bc3005b0193be6485c0d5f98f0/pydantic-1.9.2-cp38-cp38-win_amd64.whl", hash = "sha256:d70916235d478404a3fa8c997b003b5f33aeac4686ac1baa767234a0f8ac2326"}, - {url = "https://files.pythonhosted.org/packages/52/e2/52961699414260e6b55500600c90acad94861c981f6ebfdb12e5e99ad1d4/pydantic-1.9.2-cp36-cp36m-win_amd64.whl", hash = "sha256:84d76ecc908d917f4684b354a39fd885d69dd0491be175f3465fe4b59811c001"}, - {url = "https://files.pythonhosted.org/packages/5c/3c/c9ba5be133267efad3be3d46d8b76a1d3c0458feb13838154805803513fb/pydantic-1.9.2-cp36-cp36m-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:e0b214e57623a535936005797567231a12d0da0c29711eb3514bc2b3cd008d0f"}, - {url = "https://files.pythonhosted.org/packages/60/ed/40e339ee852bf1e261b24f1917e6ad6814d488ee23bff91f9e275bfe58e5/pydantic-1.9.2-cp310-cp310-macosx_11_0_arm64.whl", hash = "sha256:fafe841be1103f340a24977f61dee76172e4ae5f647ab9e7fd1e1fca51524f08"}, - {url = "https://files.pythonhosted.org/packages/6f/1e/4dca34af2a7e8effb5226ac2fec3664e99c8e95c97e8ebae9ff47fb3bbef/pydantic-1.9.2-cp39-cp39-macosx_10_9_x86_64.whl", hash = "sha256:f0ca86b525264daa5f6b192f216a0d1e860b7383e3da1c65a1908f9c02f42801"}, - {url = "https://files.pythonhosted.org/packages/75/44/e3c3c72ddbf7f6c987e39cc09f21f61f21cffeebddb75b9019f952624942/pydantic-1.9.2-cp37-cp37m-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:a8c5360a0297a713b4123608a7909e6869e1b56d0e96eb0d792c27585d40757f"}, - {url = "https://files.pythonhosted.org/packages/83/cb/2781906491a09eb7c81e78638624dc4a3dd30c36b6a4bf33221f83609c4d/pydantic-1.9.2-cp36-cp36m-musllinux_1_1_x86_64.whl", hash = "sha256:b34ba24f3e2d0b39b43f0ca62008f7ba962cff51efa56e64ee25c4af6eed987b"}, - {url = "https://files.pythonhosted.org/packages/84/cf/b2514b857196fb8484209c6bf365a164b684f6eef3d1feaa4f9ce2447389/pydantic-1.9.2-cp38-cp38-macosx_11_0_arm64.whl", hash = "sha256:e631c70c9280e3129f071635b81207cad85e6c08e253539467e4ead0e5b219aa"}, - {url = "https://files.pythonhosted.org/packages/85/15/fc8232045224fbc566c2e5f618f17519eb2ae8f15e9e63d6f3363ece7421/pydantic-1.9.2-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:afacf6d2a41ed91fc631bade88b1d319c51ab5418870802cedb590b709c5ae3c"}, - {url = "https://files.pythonhosted.org/packages/86/f8/c2effc693180e16b3ec886bc9d080f937afa7964823a7c204d5c9df55264/pydantic-1.9.2-cp38-cp38-macosx_10_9_x86_64.whl", hash = "sha256:91089b2e281713f3893cd01d8e576771cd5bfdfbff5d0ed95969f47ef6d676c3"}, - {url = "https://files.pythonhosted.org/packages/88/83/42a71762ec2f127ba8141a0608dea0ee2a8aa2dd6fcc0d2cda375aee61eb/pydantic-1.9.2-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:e78578f0c7481c850d1c969aca9a65405887003484d24f6110458fb02cca7747"}, - {url = "https://files.pythonhosted.org/packages/95/5b/5d1d8d5e6e2d9a1ec3a94b75b14fe5a2e6efd13fa96a3e53144db9de9d48/pydantic-1.9.2-cp37-cp37m-macosx_10_9_x86_64.whl", hash = "sha256:4de71c718c9756d679420c69f216776c2e977459f77e8f679a4a961dc7304a56"}, - {url = "https://files.pythonhosted.org/packages/a0/cb/672a6e3a9fa78c9a21f274dbdef7f20633969527f07ac8f882263844f4c1/pydantic-1.9.2-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:5803ad846cdd1ed0d97eb00292b870c29c1f03732a010e66908ff48a762f20e4"}, - {url = "https://files.pythonhosted.org/packages/a1/ef/b9cc1565084701825f4b21ef87bc965025cf5b80b2cb647e668accab1602/pydantic-1.9.2-cp310-cp310-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:3ee0d69b2a5b341fc7927e92cae7ddcfd95e624dfc4870b32a85568bd65e6131"}, - {url = "https://files.pythonhosted.org/packages/aa/c9/0447b23ca481a0222ab0f75bd660ab0035db2c47554825778afb0e92938e/pydantic-1.9.2-cp36-cp36m-macosx_10_9_x86_64.whl", hash = "sha256:328558c9f2eed77bd8fffad3cef39dbbe3edc7044517f4625a769d45d4cf7555"}, - {url = "https://files.pythonhosted.org/packages/ac/bf/9ff92dc00d2dae537c453220e5bab6f5b18ff0f4f1bbe65e12af1b857a5c/pydantic-1.9.2-cp39-cp39-win_amd64.whl", hash = "sha256:f1a68f4f65a9ee64b6ccccb5bf7e17db07caebd2730109cb8a95863cfa9c4e55"}, - {url = "https://files.pythonhosted.org/packages/bb/9c/7ded003135342ea07fcac5581790634a2d70340175c1e7cb2f0affcb1962/pydantic-1.9.2-cp39-cp39-macosx_11_0_arm64.whl", hash = "sha256:1061c6ee6204f4f5a27133126854948e3b3d51fcc16ead2e5d04378c199b2f44"}, - {url = "https://files.pythonhosted.org/packages/bb/e4/e77fe8e16ce33f2737a0fbe9e3566eb05ac141079e6cac9b0d7835e5b778/pydantic-1.9.2-cp37-cp37m-win_amd64.whl", hash = "sha256:32e0b4fb13ad4db4058a7c3c80e2569adbd810c25e6ca3bbd8b2a9cc2cc871d7"}, - {url = "https://files.pythonhosted.org/packages/be/72/841dcb62c23d8955b82784dd3bb73770d1ce8aa562e5bd47c1f52230ca12/pydantic-1.9.2-cp38-cp38-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:5565a49effe38d51882cb7bac18bda013cdb34d80ac336428e8908f0b72499b0"}, - {url = "https://files.pythonhosted.org/packages/c2/6e/f4d724c7004cace580bd3c7ee6be87f4607dda0249574235d26d19b4258c/pydantic-1.9.2-cp36-cp36m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:2bd446bdb7755c3a94e56d7bdfd3ee92396070efa8ef3a34fab9579fe6aa1d84"}, - {url = "https://files.pythonhosted.org/packages/ca/e3/4083d8f5d6691d677be9a99d53a66da3cbecc91cafc6c48d08c75490b3ba/pydantic-1.9.2-cp310-cp310-musllinux_1_1_i686.whl", hash = "sha256:ff68fc85355532ea77559ede81f35fff79a6a5543477e168ab3a381887caea76"}, - {url = "https://files.pythonhosted.org/packages/d3/4b/6f539c1f26c6a8ed942fa751981909ab86336ce5ead28b6c92590ee6bc1b/pydantic-1.9.2-cp38-cp38-musllinux_1_1_x86_64.whl", hash = "sha256:4aafd4e55e8ad5bd1b19572ea2df546ccace7945853832bb99422a79c70ce9b8"}, - {url = "https://files.pythonhosted.org/packages/dd/1c/0046af6bfd47982495b502400e90ffdee0b5e4af11be4e58b50d47007f27/pydantic-1.9.2-cp36-cp36m-musllinux_1_1_i686.whl", hash = "sha256:d8ce3fb0841763a89322ea0432f1f59a2d3feae07a63ea2c958b2315e1ae8adb"}, - {url = "https://files.pythonhosted.org/packages/e0/0f/a8adcc49e58994f6da6b96dac42dedbedd250c3130d59a664d8130c8019d/pydantic-1.9.2-cp37-cp37m-musllinux_1_1_i686.whl", hash = "sha256:cdb4272678db803ddf94caa4f94f8672e9a46bae4a44f167095e4d06fec12979"}, - {url = "https://files.pythonhosted.org/packages/e6/b7/e50089199de9952f7156b8931c2bcd3db6654845d6c453046e9073a5f56d/pydantic-1.9.2-cp310-cp310-win_amd64.whl", hash = "sha256:615661bfc37e82ac677543704437ff737418e4ea04bef9cf11c6d27346606044"}, - {url = "https://files.pythonhosted.org/packages/e9/64/3395d45a05adcebb6d1025702c28d1ed188703397f38999295c52687f87e/pydantic-1.9.2-cp39-cp39-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:5da164119602212a3fe7e3bc08911a89db4710ae51444b4224c2382fd09ad453"}, - {url = "https://files.pythonhosted.org/packages/ed/c9/ffe44727dadb0930783a1ffb60facf8ead7dffbb67db9ae2fa28dacabcf1/pydantic-1.9.2-cp37-cp37m-musllinux_1_1_x86_64.whl", hash = "sha256:19b5686387ea0d1ea52ecc4cffb71abb21702c5e5b2ac626fd4dbaa0834aa49d"}, - {url = "https://files.pythonhosted.org/packages/f6/63/b412252dbbdc712500ad73fe2e591c3220781e63a8c135d26b7d60fcb99c/pydantic-1.9.2-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:4b3946f87e5cef3ba2e7bd3a4eb5a20385fe36521d6cc1ebf3c08a6697c6cfb3"}, - {url = "https://files.pythonhosted.org/packages/f7/76/4a98738c31e520c78a80e9575b655b5c3ae96313102478bff4d643abc2e9/pydantic-1.9.2-cp39-cp39-musllinux_1_1_x86_64.whl", hash = "sha256:7d0f183b305629765910eaad707800d2f47c6ac5bcfb8c6397abdc30b69eeb15"}, - {url = "https://files.pythonhosted.org/packages/f7/ea/05d5fa5ab16536524258c73e932e2c417e47fffa33a939bf7c12e956b961/pydantic-1.9.2-cp310-cp310-musllinux_1_1_x86_64.whl", hash = "sha256:c0f5e142ef8217019e3eef6ae1b6b55f09a7a15972958d44fbd228214cede567"}, - {url = "https://files.pythonhosted.org/packages/fd/8f/3f7e88b507dbdfec8f1f914294aa8831edffb03d668799c65b4b46331c8a/pydantic-1.9.2.tar.gz", hash = "sha256:8cb0bc509bfb71305d7a59d00163d5f9fc4530f0881ea32c74ff4f74c85f3d3d"}, - {url = "https://files.pythonhosted.org/packages/fe/27/0de772dcd0517770b265dbc3998ed3ee3aa2ba25ba67e3685116cbbbccc6/pydantic-1.9.2-py3-none-any.whl", hash = "sha256:78a4d6bdfd116a559aeec9a4cfe77dda62acc6233f8b56a716edad2651023e5e"}, -] -"pyflakes 2.3.1" = [ - {url = "https://files.pythonhosted.org/packages/6c/11/2a745612f1d3cbbd9c69ba14b1b43a35a2f5c3c81cd0124508c52c64307f/pyflakes-2.3.1-py2.py3-none-any.whl", hash = "sha256:7893783d01b8a89811dd72d7dfd4d84ff098e5eed95cfa8905b22bbffe52efc3"}, - {url = "https://files.pythonhosted.org/packages/a8/0f/0dc480da9162749bf629dca76570972dd9cce5bedc60196a3c912875c87d/pyflakes-2.3.1.tar.gz", hash = "sha256:f5bc8ecabc05bb9d291eb5203d6810b49040f6ff446a756326104746cc00c1db"}, -] -"pygls 0.12.2" = [ - {url = "https://files.pythonhosted.org/packages/97/61/18ee9f59ae0e0819d8a0c684ec9e85d4318c59892750f42b036c9cd45bcd/pygls-0.12.2.tar.gz", hash = "sha256:48465ba74a32d50fbc110111ee0b60721c169f5bd9d8eedc582931ff765d6bc6"}, - {url = "https://files.pythonhosted.org/packages/cf/8e/9427c50587172f973cf8837b7b56a81c1e1812d5d417d30f3c4167726662/pygls-0.12.2-py3-none-any.whl", hash = "sha256:ad83aea5c45c915b6b0b47ef0faca3c3b4778d087110c8e912da14b9f1c9f9d7"}, -] -"pyproject-api 1.4.0" = [ - {url = "https://files.pythonhosted.org/packages/08/87/d1d350a5aa74baf598030fcdadc78b42a83014a3c0583354f4b5ecf1cf14/pyproject_api-1.4.0.tar.gz", hash = "sha256:ac85c1f82e0291dbae5a7739dbb9a990e11ee4034c9b5599ea714f07a24ecd71"}, - {url = "https://files.pythonhosted.org/packages/5c/74/430827553d00b2a25294b651cd732b79659551485ae5968a439dd64f1d1e/pyproject_api-1.4.0-py3-none-any.whl", hash = "sha256:c34226297781efdd1ba4dfb74ce21076d9a8360e2125ea31803c1a02c76b2460"}, +"pycodestyle 2.9.1" = [ + {url = "https://files.pythonhosted.org/packages/67/e4/fc77f1039c34b3612c4867b69cbb2b8a4e569720b1f19b0637002ee03aff/pycodestyle-2.9.1-py2.py3-none-any.whl", hash = "sha256:d1735fc58b418fd7c5f658d28d943854f8a849b01a5d0a1e6f3f3fdd0166804b"}, + {url = "https://files.pythonhosted.org/packages/b6/83/5bcaedba1f47200f0665ceb07bcb00e2be123192742ee0edfb66b600e5fd/pycodestyle-2.9.1.tar.gz", hash = "sha256:2c9607871d58c76354b697b42f5d57e1ada7d261c261efac224b664affdc5785"}, +] +"pyflakes 2.5.0" = [ + {url = "https://files.pythonhosted.org/packages/07/92/f0cb5381f752e89a598dd2850941e7f570ac3cb8ea4a344854de486db152/pyflakes-2.5.0.tar.gz", hash = "sha256:491feb020dca48ccc562a8c0cbe8df07ee13078df59813b83959cbdada312ea3"}, + {url = "https://files.pythonhosted.org/packages/dc/13/63178f59f74e53acc2165aee4b002619a3cfa7eeaeac989a9eb41edf364e/pyflakes-2.5.0-py2.py3-none-any.whl", hash = "sha256:4579f67d887f804e67edb544428f264b7b24f435b263c4614f384135cea553d2"}, +] +"pygls 1.0.0" = [ + {url = "https://files.pythonhosted.org/packages/85/91/583946b8a1b7eb4d4dc22776128512994c60da6c9dfa4b5d6597b0bf8b62/pygls-1.0.0-py3-none-any.whl", hash = "sha256:3414594ac29ff3ab990f004c675d1077e4e2659eae5cc3ae67cc6fa4d861e342"}, + {url = "https://files.pythonhosted.org/packages/da/72/f862cf178a076a3d63174c98c82f7b526b3d709c3ea184c763e745027597/pygls-1.0.0.tar.gz", hash = "sha256:c2a1c22e30028f7ca9d3f0a04da8eef29f0f1701bdbd97d8614d8e1e6711f336"}, ] "pytest 7.2.0" = [ {url = "https://files.pythonhosted.org/packages/0b/21/055f39bf8861580b43f845f9e8270c7786fe629b2f8562ff09007132e2e7/pytest-7.2.0.tar.gz", hash = "sha256:c4014eb40e10f11f355ad4e3c2fb2c6c6d1919c73f3b5a433de4708202cade59"}, @@ -582,14 +471,6 @@ content_hash = "sha256:33a613406f6c5d985a0b1d7812dbf4e4f5d20e6388391b1c0c786cf37 {url = "https://files.pythonhosted.org/packages/97/75/10a9ebee3fd790d20926a90a2547f0bf78f371b2f13aa822c759680ca7b9/tomli-2.0.1-py3-none-any.whl", hash = "sha256:939de3e7a6161af0c887ef91b7d41a53e7c5a1ca976325f429cb46ea9bc30ecc"}, {url = "https://files.pythonhosted.org/packages/c0/3f/d7af728f075fb08564c5949a9c95e44352e23dee646869fa104a3b2060a3/tomli-2.0.1.tar.gz", hash = "sha256:de526c12914f0c550d15924c62d72abc48d6fe7364aa87328337a31007fe8a4f"}, ] -"tox 4.2.6" = [ - {url = "https://files.pythonhosted.org/packages/6a/fd/8e1f5e6f251120f643e7e2773d9451b7669e6dfdd3c09fc6d9185b423fc9/tox-4.2.6-py3-none-any.whl", hash = "sha256:fb79b3e4b788491949576a9c80c2d56419eac994567c3591e24bb2788b5901d0"}, - {url = "https://files.pythonhosted.org/packages/70/c4/74a995db95714ead327f30933290fd04a6be9489fb0adbcef8c6f816a3d4/tox-4.2.6.tar.gz", hash = "sha256:ecf224a4f3a318adcdd71aa8fe15ffd31f14afd6a9845a43ffd63950a7325538"}, -] -"tox-pdm 0.6.1" = [ - {url = "https://files.pythonhosted.org/packages/57/42/c437d69c3b884c58027999e524c91716ac355048284be771d810d80ceed1/tox-pdm-0.6.1.tar.gz", hash = "sha256:952ea67f2ec891f11eb00749f63fc0f980384435ca782c448d154390f9f42f5e"}, - {url = "https://files.pythonhosted.org/packages/dd/2e/9c694f9775e3bd6e9eadf6c38fdc9f2e55d2ecbc7a4bba30eecf2a4b7f91/tox_pdm-0.6.1-py3-none-any.whl", hash = "sha256:9e3cf83b7b55c3e33aaee0e65cf341739581ff4604a4178f0ef7dbab73a0bb35"}, -] "typed-ast 1.5.4" = [ {url = "https://files.pythonhosted.org/packages/04/93/482d12fd3334b53ec4087e658ab161ab23affcf8b052166b4cf972ca673b/typed_ast-1.5.4-cp37-cp37m-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl", hash = "sha256:6778e1b2f81dfc7bc58e4b259363b83d2e509a65198e85d5700dfae4c6c8ff1c"}, {url = "https://files.pythonhosted.org/packages/07/d2/d55702e8deba2c80282fea0df53130790d8f398648be589750954c2dcce4/typed_ast-1.5.4.tar.gz", hash = "sha256:39e21ceb7388e4bb37f4c679d72707ed46c2fbf2a5609b8b8ebc4b067d977df2"}, @@ -624,10 +505,6 @@ content_hash = "sha256:33a613406f6c5d985a0b1d7812dbf4e4f5d20e6388391b1c0c786cf37 {url = "https://files.pythonhosted.org/packages/0b/8e/f1a0a5a76cfef77e1eb6004cb49e5f8d72634da638420b9ea492ce8305e8/typing_extensions-4.4.0-py3-none-any.whl", hash = "sha256:16fa4864408f655d35ec496218b85f79b3437c829e93320c7c9215ccfd92489e"}, {url = "https://files.pythonhosted.org/packages/e3/a7/8f4e456ef0adac43f452efc2d0e4b242ab831297f1bac60ac815d37eb9cf/typing_extensions-4.4.0.tar.gz", hash = "sha256:1511434bb92bf8dd198c12b1cc812e800d4181cfcb867674e0f8279cc93087aa"}, ] -"virtualenv 20.17.1" = [ - {url = "https://files.pythonhosted.org/packages/18/a2/7931d40ecb02b5236a34ac53770f2f6931e3082b7a7dafe915d892d749d6/virtualenv-20.17.1-py3-none-any.whl", hash = "sha256:ce3b1684d6e1a20a3e5ed36795a97dfc6af29bc3970ca8dab93e11ac6094b3c4"}, - {url = "https://files.pythonhosted.org/packages/7b/19/65f13cff26c8cc11fdfcb0499cd8f13388dd7b35a79a376755f152b42d86/virtualenv-20.17.1.tar.gz", hash = "sha256:f8b927684efc6f1cc206c9db297a570ab9ad0e51c16fa9e45487d36d1905c058"}, -] "zipp 3.11.0" = [ {url = "https://files.pythonhosted.org/packages/8e/b3/8b16a007184714f71157b1a71bbe632c5d66dd43bc8152b3c799b13881e1/zipp-3.11.0.tar.gz", hash = "sha256:a7a22e05929290a67401440b39690ae6563279bced5f314609d9d03798f56766"}, {url = "https://files.pythonhosted.org/packages/d8/20/256eb3f3f437c575fb1a2efdce5e801a5ce3162ea8117da96c43e6ee97d8/zipp-3.11.0-py3-none-any.whl", hash = "sha256:83a28fcb75844b5c0cdaf5aa4003c2d728c77e05f5aeabe8e95e56727005fbaa"}, diff --git a/pyproject.toml b/pyproject.toml index 1a34b49..6e83c77 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -6,9 +6,9 @@ authors = [ {name = "Regen"}, ] dependencies = [ - "pygls>=0.12.2", + "pygls>=1.0.0", ] -requires-python = ">=3.7" +requires-python = ">=3.7,<3.12" readme = "README.md" license = {text = "MIT"} keywords = ["cmake", "completion", "vim", "lsp"] @@ -41,11 +41,10 @@ dev = [ "pytest-datadir>=1.4.1", "pytest-cov>=4.0.0", "cmakelang>=0.6.13", - "tox-pdm>=0.6.1", ] lint = [ "mypy>=0.991", - "flake8>=3.9.2", + "flake8>=5.0.4", "black>=22.12.0", "isort>=5.11.4", ] diff --git a/tests/conftest.py b/tests/conftest.py index f218b41..346a507 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -1,4 +1,3 @@ -import asyncio import logging import os from pathlib import Path @@ -7,7 +6,7 @@ from typing import Iterable, Tuple import pytest -from pygls.lsp.methods import EXIT +from lsprotocol.types import EXIT, SHUTDOWN from pygls.server import LanguageServer from cmake_language_server.server import CMakeLanguageServer @@ -38,24 +37,21 @@ def client_server() -> Iterable[Tuple[LanguageServer, CMakeLanguageServer]]: s2c_r, s2c_w = os.pipe() def start(ls: LanguageServer, fdr: int, fdw: int) -> None: - # TODO: better patch is needed - # disable `close()` to avoid error messages - close = ls.loop.close - ls.loop.close = lambda: None # type: ignore - ls.start_io(os.fdopen(fdr, "rb"), os.fdopen(fdw, "wb")) # type: ignore - ls.loop.close = close # type: ignore - - server = CMakeLanguageServer(asyncio.new_event_loop()) + ls.start_io( # type: ignore[no-untyped-call] + os.fdopen(fdr, "rb"), os.fdopen(fdw, "wb") + ) + + server = CMakeLanguageServer("server", "v1") server_thread = Thread(target=start, args=(server, c2s_r, s2c_w)) server_thread.start() - client = LanguageServer(asyncio.new_event_loop()) + client = LanguageServer("client", "v1") client_thread = Thread(target=start, args=(client, s2c_r, c2s_w)) client_thread.start() yield client, server - client.send_notification(EXIT) - server.send_notification(EXIT) - server_thread.join() + client.lsp.send_request(SHUTDOWN) + client.lsp.notify(EXIT) client_thread.join() + server_thread.join() diff --git a/tests/test_server.py b/tests/test_server.py index 2f9ebff..f349329 100644 --- a/tests/test_server.py +++ b/tests/test_server.py @@ -1,27 +1,27 @@ from concurrent import futures from pathlib import Path -from typing import Any, Dict, Optional, Tuple +from typing import Optional, Tuple -from pygls.lsp.methods import ( - COMPLETION, - FORMATTING, - HOVER, +import pytest +from lsprotocol.types import ( INITIALIZE, + TEXT_DOCUMENT_COMPLETION, TEXT_DOCUMENT_DID_OPEN, -) -from pygls.lsp.types import ( + TEXT_DOCUMENT_FORMATTING, + TEXT_DOCUMENT_HOVER, ClientCapabilities, CompletionContext, + CompletionList, CompletionParams, CompletionTriggerKind, DidOpenTextDocumentParams, DocumentFormattingParams, FormattingOptions, + HoverParams, InitializeParams, Position, TextDocumentIdentifier, TextDocumentItem, - TextDocumentPositionParams, ) from pygls.server import LanguageServer @@ -50,8 +50,7 @@ def _init(client: LanguageServer, root: Path) -> None: def _open(client: LanguageServer, path: Path, text: Optional[str] = None) -> None: if text is None: - with open(path) as fp: - text = fp.read() + text = path.read_text() client.lsp.notify( TEXT_DOCUMENT_DID_OPEN, @@ -68,7 +67,7 @@ def _test_completion( datadir: Path, content: str, context: Optional[CompletionContext], -) -> Dict[str, Any]: +) -> CompletionList: client, server = client_server _init(client, datadir) path = datadir / "CMakeLists.txt" @@ -78,11 +77,10 @@ def _test_completion( position=Position(line=0, character=len(content)), context=context, ) - if context is None: - # some clients do not send context - del params.context - ret = client.lsp.send_request(COMPLETION, params).result(timeout=CALL_TIMEOUT) - assert isinstance(ret, dict) + ret = client.lsp.send_request(TEXT_DOCUMENT_COMPLETION, params).result( + timeout=CALL_TIMEOUT + ) + assert isinstance(ret, CompletionList) return ret @@ -96,79 +94,43 @@ def test_initialize( assert server._api is not None -def test_completions_invoked( - client_server: Tuple[LanguageServer, CMakeLanguageServer], datadir: Path -) -> None: - response = _test_completion( - client_server, - datadir, - "projec", - CompletionContext(trigger_kind=CompletionTriggerKind.Invoked), - ) - item = next(filter(lambda x: x["label"] == "project", response["items"]), None) - assert item is not None - assert isinstance(item["documentation"], str) - assert "" in item["documentation"] - - -def test_completions_nocontext( - client_server: Tuple[LanguageServer, CMakeLanguageServer], datadir: Path +@pytest.mark.parametrize( + "context", [CompletionContext(trigger_kind=CompletionTriggerKind.Invoked), None] +) +def test_completions( + context: Optional[CompletionContext], + client_server: Tuple[LanguageServer, CMakeLanguageServer], + datadir: Path, ) -> None: - response = _test_completion(client_server, datadir, "projec", None) - item = next(filter(lambda x: x["label"] == "project", response["items"]), None) + 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 "" in item["documentation"] - - -def test_completions_triggercharacter_variable( - client_server: Tuple[LanguageServer, CMakeLanguageServer], datadir: Path -) -> None: - response = _test_completion( - client_server, - datadir, - "${", - CompletionContext( - trigger_kind=CompletionTriggerKind.TriggerCharacter, trigger_character="{" - ), - ) - assert "PROJECT_VERSION" in [x["label"] for x in response["items"]] - - response_nocontext = _test_completion(client_server, datadir, "${", None) - assert response == response_nocontext - - -def test_completions_triggercharacter_module( - client_server: Tuple[LanguageServer, CMakeLanguageServer], datadir: Path -) -> None: - response = _test_completion( - client_server, - datadir, - "include(", - CompletionContext( - trigger_kind=CompletionTriggerKind.TriggerCharacter, trigger_character="(" - ), - ) - assert "GoogleTest" in [x["label"] for x in response["items"]] + assert isinstance(item.documentation, str) + assert "" in item.documentation - response_nocontext = _test_completion(client_server, datadir, "include(", None) - assert response == response_nocontext - -def test_completions_triggercharacter_package( - client_server: Tuple[LanguageServer, CMakeLanguageServer], datadir: Path +@pytest.mark.parametrize( + "text, item", + [("find_package(", "Boost"), ("include(", "GoogleTest"), ("${", "PROJECT_VERSION")], +) +def test_completions_triggercharacter( + text: str, + item: str, + client_server: Tuple[LanguageServer, CMakeLanguageServer], + datadir: Path, ) -> None: response = _test_completion( client_server, datadir, - "find_package(", + text, CompletionContext( - trigger_kind=CompletionTriggerKind.TriggerCharacter, trigger_character="(" + trigger_kind=CompletionTriggerKind.TriggerCharacter, + trigger_character=text[-1], ), ) - assert "Boost" in [x["label"] for x in response["items"]] + assert item in [x.label for x in response.items] - response_nocontext = _test_completion(client_server, datadir, "find_package(", None) + response_nocontext = _test_completion(client_server, datadir, text, None) assert response == response_nocontext @@ -180,13 +142,13 @@ def test_formatting( path = datadir / "CMakeLists.txt" _open(client, path, "a ( b c ) ") response = client.lsp.send_request( - FORMATTING, + TEXT_DOCUMENT_FORMATTING, DocumentFormattingParams( text_document=TextDocumentIdentifier(uri=path.as_uri()), options=FormattingOptions(tab_size=2, insert_spaces=True), ), ).result(timeout=CALL_TIMEOUT) - assert response[0]["newText"] == "a(b c)\n" + assert response[0].new_text == "a(b c)\n" def test_hover( @@ -197,10 +159,10 @@ def test_hover( path = datadir / "CMakeLists.txt" _open(client, path, "project()") response = client.lsp.send_request( - HOVER, - TextDocumentPositionParams( + TEXT_DOCUMENT_HOVER, + HoverParams( text_document=TextDocumentIdentifier(uri=path.as_uri()), position=Position(line=0, character=0), ), ).result(timeout=CALL_TIMEOUT) - assert "" in response["contents"]["value"] + assert "" in response.contents.value diff --git a/tox.ini b/tox.ini index 8587cd1..05e3b37 100644 --- a/tox.ini +++ b/tox.ini @@ -2,6 +2,8 @@ env_list = py{37,38,39,310} isolated_build = True passenv = * +setenv = + PDM_IGNORE_SAVED_PYTHON="1" [gh-actions] python = @@ -11,7 +13,9 @@ python = 3.10: py310 [testenv] -groups = dev, lint +allowlist_externals = + pdm commands = - lint - test + pdm install --dev -G :all + pdm run lint + pdm run test