Skip to content

Commit

Permalink
update server to 2023-12-09 and support references code lenses (#21)
Browse files Browse the repository at this point in the history
  • Loading branch information
rchl authored Dec 11, 2023
1 parent aa89c98 commit 9083a88
Show file tree
Hide file tree
Showing 8 changed files with 169 additions and 3 deletions.
3 changes: 2 additions & 1 deletion .gitattributes
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
pyrightconfig.json export-ignore
screenshots export-ignore
pyproject.toml export-ignore
tox.ini export-ignore
10 changes: 10 additions & 0 deletions .github/dependabot.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
version: 2
updates:
- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: "weekly"
- package-ecosystem: pip
directory: "/"
schedule:
interval: "weekly"
20 changes: 20 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
@@ -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
3 changes: 3 additions & 0 deletions LSP-marksman.sublime-settings
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,7 @@
// 1=full, 2=incremental
"preferredTextSyncKind": 2,
},
"experimental_capabilities": {
"codeLensFindReferences": true,
}
}
36 changes: 34 additions & 2 deletions plugin.py
Original file line number Diff line number Diff line change
@@ -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'

Expand Down Expand Up @@ -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)
Expand Down
11 changes: 11 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -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
67 changes: 67 additions & 0 deletions sublime-package.json
Original file line number Diff line number Diff line change
@@ -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"
}
}
}
}
}
}
}
},
]
}
}
22 changes: 22 additions & 0 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 9083a88

Please sign in to comment.