From 42baa50cda8169a1ea35c37603b873c3f34458a4 Mon Sep 17 00:00:00 2001 From: Rafal Chlodnicki Date: Sun, 10 Dec 2023 17:27:11 +0100 Subject: [PATCH] update server to 2023-12-09 and support references from code lenses --- .gitattributes | 3 +- .github/workflows/ci.yaml | 20 +++++++++++ LSP-marksman.sublime-settings | 3 ++ plugin.py | 36 +++++++++++++++++-- pyproject.toml | 11 ++++++ sublime-package.json | 67 +++++++++++++++++++++++++++++++++++ tox.ini | 22 ++++++++++++ 7 files changed, 159 insertions(+), 3 deletions(-) create mode 100644 .github/workflows/ci.yaml create mode 100644 pyproject.toml create mode 100644 sublime-package.json create mode 100644 tox.ini diff --git a/.gitattributes b/.gitattributes index 789c36c..efbca8c 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1,2 +1,3 @@ pyrightconfig.json export-ignore -screenshots export-ignore +pyproject.toml export-ignore +tox.ini export-ignore diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml new file mode 100644 index 0000000..fb5016d --- /dev/null +++ b/.github/workflows/ci.yaml @@ -0,0 +1,20 @@ +name: main + +on: + push: + branches: + - main + pull_request: + branches: + - main + +jobs: + Lint: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-python@v4 + with: + python-version: '3.8' + - run: pip3 install tox --user + - run: tox diff --git a/LSP-marksman.sublime-settings b/LSP-marksman.sublime-settings index 8a4a742..1fabcd7 100644 --- a/LSP-marksman.sublime-settings +++ b/LSP-marksman.sublime-settings @@ -6,4 +6,7 @@ // 1=full, 2=incremental "preferredTextSyncKind": 2, }, + "experimental_capabilities": { + "codeLensFindReferences": true, + } } diff --git a/plugin.py b/plugin.py index 3d6f0f2..f8939fb 100644 --- a/plugin.py +++ b/plugin.py @@ -1,12 +1,14 @@ from LSP.plugin import AbstractPlugin, register_plugin, unregister_plugin -from LSP.plugin.core.typing import Dict, Optional +from LSP.plugin.core.protocol import Location +from LSP.plugin.core.typing import Any, Callable, Dict, Optional, List, Mapping +from LSP.plugin.locationpicker import LocationPicker from shutil import which import os import sublime import urllib.request -MARKSMAN_TAG = '2023-11-29' +MARKSMAN_TAG = '2023-12-09' MARKSMAN_RELEASES_BASE = 'https://github.com/artempyanykh/marksman/releases/download/{tag}/{platform}' USER_AGENT = 'Sublime Text LSP' @@ -81,6 +83,36 @@ def install_or_update(cls) -> None: with open(os.path.join(cls.basedir(), 'VERSION'), 'w') as fp: fp.write(cls.server_version()) + def on_pre_server_command(self, command: Mapping[str, Any], done_callback: Callable[[], None]) -> bool: + command_name = command['command'] + if command_name == 'marksman.findReferences': + command_arguments = command['arguments'] + if command_arguments and 'locations' in command_arguments[0]: + self._handle_show_references(command_arguments[0]['locations']) + done_callback() + return True + return False + + def _handle_show_references(self, references: List[Location]) -> None: + session = self.weaksession() + if not session: + return + view = sublime.active_window().active_view() + if not view: + return + if len(references) == 1: + args = { + 'location': references[0], + 'session_name': session.config.name, + } + window = view.window() + if window: + window.run_command('lsp_open_location', args) + elif references: + LocationPicker(view, session, references, side_by_side=False) + else: + sublime.status_message('No references found') + def plugin_loaded() -> None: register_plugin(Marksman) diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..12d08dd --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,11 @@ +[tool.ruff] +select = ["E", "F", "W"] +line-length = 120 +target-version = 'py38' + +[[tool.mypy.overrides]] +module = [ + "LSP.*", + "sublime" +] +ignore_missing_imports = true diff --git a/sublime-package.json b/sublime-package.json new file mode 100644 index 0000000..34079f8 --- /dev/null +++ b/sublime-package.json @@ -0,0 +1,67 @@ +{ + "contributions": { + "settings": [ + { + "file_patterns": [ + "/LSP-marksman.sublime-settings" + ], + "schema": { + "$id": "sublime://settings/LSP-marksman", + "definitions": { + "PluginConfig": { + "properties": { + "initializationOptions": { + "additionalProperties": false, + "properties": { + "preferredTextSyncKind": { + "enum": [ + 1, + 2, + null + ], + "markdownEnumDescriptions": [ + "full sync", + "incremental sync", + "default value (full sync)" + ], + "default": null, + "description": "How text is synced between this client and the server." + }, + }, + }, + } + } + }, + "allOf": [ + { + "$ref": "sublime://settings/LSP-plugin-base" + }, + { + "$ref": "sublime://settings/LSP-marksman#/definitions/PluginConfig" + } + ] + } + }, + { + "file_patterns": [ + "/*.sublime-project" + ], + "schema": { + "properties": { + "settings": { + "properties": { + "LSP": { + "properties": { + "LSP-marksman": { + "$ref": "sublime://settings/LSP-marksman#/definitions/PluginConfig" + } + } + } + } + } + } + } + }, + ] + } +} diff --git a/tox.ini b/tox.ini new file mode 100644 index 0000000..eb20f6c --- /dev/null +++ b/tox.ini @@ -0,0 +1,22 @@ +# Tox (http://tox.testrun.org/) is a tool for running tests +# in multiple virtualenvs. This configuration file will run the +# test suite on all supported python versions. To use it, "pip install tox" +# and then run "tox" from this directory. + +[tox] +envlist = py3 +skipsdist = True + +[pycodestyle] +max-line-length = 120 + +[flake8] +max-line-length = 120 + +[testenv] +deps = + mypy==1.7.1 + ruff==0.1.7 +commands = + mypy plugin.py + ruff plugin.py