Skip to content

Commit 2261455

Browse files
committed
Add plugin skeleton generated by cookiecutter-pylsp-plugin.
0 parents  commit 2261455

File tree

13 files changed

+582
-0
lines changed

13 files changed

+582
-0
lines changed

.github/ISSUE_TEMPLATE.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
* python-lsp-isort version:
2+
* Text editor/IDE/LSP Client:
3+
* Python version:
4+
* Operating System:
5+
6+
### Description
7+
8+
Describe what you were trying to get done.
9+
Tell us what happened, what went wrong, and what you expected to happen.
10+
11+
### Details
12+
13+
```
14+
If there was a crash, please include the traceback here.
15+
```

.gitignore

Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
# Byte-compiled / optimized / DLL files
2+
__pycache__/
3+
*.py[cod]
4+
*$py.class
5+
6+
# C extensions
7+
*.so
8+
9+
# Distribution / packaging
10+
.Python
11+
env/
12+
build/
13+
develop-eggs/
14+
dist/
15+
downloads/
16+
eggs/
17+
.eggs/
18+
lib/
19+
lib64/
20+
parts/
21+
sdist/
22+
var/
23+
wheels/
24+
*.egg-info/
25+
.installed.cfg
26+
*.egg
27+
28+
# PyInstaller
29+
# Usually these files are written by a python script from a template
30+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
31+
*.manifest
32+
*.spec
33+
34+
# Installer logs
35+
pip-log.txt
36+
pip-delete-this-directory.txt
37+
38+
# Unit test / coverage reports
39+
htmlcov/
40+
.tox/
41+
.coverage
42+
.coverage.*
43+
.cache
44+
nosetests.xml
45+
coverage.xml
46+
*.cover
47+
.hypothesis/
48+
.pytest_cache/
49+
50+
# Translations
51+
*.mo
52+
*.pot
53+
54+
# Django stuff:
55+
*.log
56+
local_settings.py
57+
58+
# Flask stuff:
59+
instance/
60+
.webassets-cache
61+
62+
# Scrapy stuff:
63+
.scrapy
64+
65+
# Sphinx documentation
66+
docs/_build/
67+
68+
# PyBuilder
69+
target/
70+
71+
# Jupyter Notebook
72+
.ipynb_checkpoints
73+
74+
# pyenv
75+
.python-version
76+
77+
# celery beat schedule file
78+
celerybeat-schedule
79+
80+
# SageMath parsed files
81+
*.sage.py
82+
83+
# dotenv
84+
.env
85+
86+
# virtualenv
87+
.venv
88+
venv/
89+
ENV/
90+
91+
# Spyder project settings
92+
.spyderproject
93+
.spyproject
94+
95+
# Rope project settings
96+
.ropeproject
97+
98+
# mkdocs documentation
99+
/site
100+
101+
# mypy
102+
.mypy_cache/
103+
104+
# IDE settings
105+
.vscode/
106+
.idea/
107+
108+
# ctags
109+
tags

AUTHORS.txt

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
=======
2+
Credits
3+
=======
4+
5+
Development Lead
6+
----------------
7+
8+
* Hiroki Teranishi <[email protected]>
9+
10+
Contributors
11+
------------
12+
13+
None yet. Why not be the first?
14+

LICENSE

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
MIT License
2+
3+
Copyright (c) 2023, Hiroki Teranishi
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.
22+

README.md

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
# python-lsp-isort
2+
3+
isort plugin for the Python LSP Server
4+
5+
This is a plugin for [Python LSP Server](https://github.com/python-lsp/python-lsp-server).
6+
7+
## Installation
8+
9+
To use this plugin, you need to install this plugin in the same virtualenv as python-lsp-server itself.
10+
11+
``` bash
12+
pip install python-lsp-isort
13+
```
14+
15+
Then run `python-lsp-server` as usual, the plugin will be auto-discovered by
16+
`python-lsp-server` if you've installed it to the right environment. Refer to
17+
`python-lsp-server` and your IDE/text editor documentation on how to setup
18+
`python-lsp-server`.
19+
20+
## Configuration
21+
22+
... TODO ...
23+
24+
## Features
25+
26+
This plugin adds the following features to `pylsp`:
27+
28+
- ... TODO ...
29+
30+
## Developing
31+
32+
Install development dependencies with (you might want to create a virtualenv first):
33+
34+
``` bash
35+
git clone https://github.com/chantera/python-lsp-isort python-lsp-isort
36+
cd python-lsp-isort
37+
pip install -e '.[dev]'
38+
```
39+
40+
### Enabling logging
41+
42+
To enable logging in pylsp:
43+
44+
pylsp -v --log-file /tmp/pylsp.log
45+
46+
### Enabling tcp mode
47+
48+
Normally, editors communicate with language servers through standard
49+
input/output. Optionally, you can run pylsp in tcp mode if you want to be able
50+
to use the standard input/output, for example so you can use IPython or pudb,
51+
using the --tcp flag:
52+
53+
pylsp -v --log-file /tmp/pylsp.log --tcp --port 7090
54+
55+
Consult your lsp client documentation on how to connect to tcp-mode language
56+
server, but if it doesn't support connecting to a language server via TCP, then
57+
usually can configure `netcat`/`nc` to be your "language server" that will
58+
proxy requests to a tcp-mode language server:
59+
60+
nc localhost 7090
61+
62+
TODO: document how to connect to pylsp via pylsp from LSP clients.
63+
### Testing
64+
65+
Run `pytest` to run plugin tests.
66+
67+
68+
## Publishing
69+
70+
If this is your first time publishing to PyPI, follow the instruction at [Twine
71+
docs](https://packaging.python.org/guides/distributing-packages-using-setuptools/#create-an-account)
72+
to create an PyPI account and setup Twine.
73+
74+
1. Update version number in `setup.cfg`.
75+
76+
2. Build a package using setuptools:
77+
78+
``` bash
79+
python -m build
80+
twine check dist/*
81+
```
82+
83+
3. Tag the release:
84+
85+
```
86+
git tag --sign 0.1.3
87+
git push origin 0.1.3
88+
```
89+
90+
4. Then upload using Twine:
91+
92+
```
93+
twine upload --sign dist/*
94+
```
95+
96+
Alternatively, you may want to upload to Test PyPI first before going live:
97+
98+
```
99+
twine upload --repository testpypi dist/*
100+
```
101+
102+
## Credits
103+
104+
This package was created with
105+
[Cookiecutter](https://github.com/audreyr/cookiecutter) from
106+
[python-lsp/cookiecutter-pylsp-plugin](https://github.com/python-lsp/cookiecutter-pylsp-plugin)
107+
project template.

pylsp_isort/__init__.py

Whitespace-only changes.

pylsp_isort/plugin.py

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
import logging
2+
3+
from pylsp import hookimpl, uris
4+
5+
6+
logger = logging.getLogger(__name__)
7+
8+
9+
@hookimpl
10+
def pylsp_settings():
11+
logger.info("Initializing pylsp_isort")
12+
13+
# Disable default plugins that conflicts with our plugin
14+
return {
15+
"plugins": {
16+
# "autopep8_format": {"enabled": False},
17+
# "definition": {"enabled": False},
18+
# "flake8_lint": {"enabled": False},
19+
# "folding": {"enabled": False},
20+
# "highlight": {"enabled": False},
21+
# "hover": {"enabled": False},
22+
# "jedi_completion": {"enabled": False},
23+
# "jedi_rename": {"enabled": False},
24+
# "mccabe_lint": {"enabled": False},
25+
# "preload_imports": {"enabled": False},
26+
# "pycodestyle_lint": {"enabled": False},
27+
# "pydocstyle_lint": {"enabled": False},
28+
# "pyflakes_lint": {"enabled": False},
29+
# "pylint_lint": {"enabled": False},
30+
# "references": {"enabled": False},
31+
# "rope_completion": {"enabled": False},
32+
# "rope_rename": {"enabled": False},
33+
# "signature": {"enabled": False},
34+
# "symbols": {"enabled": False},
35+
# "yapf_format": {"enabled": False},
36+
},
37+
}
38+
39+
40+
@hookimpl
41+
def pylsp_code_actions(config, workspace, document, range, context):
42+
logger.info("textDocument/codeAction: %s %s %s", document, range, context)
43+
44+
return [
45+
{
46+
"title": "Extract method",
47+
"kind": "refactor.extract",
48+
"command": {
49+
"command": "example.refactor.extract",
50+
"arguments": [document.uri, range],
51+
},
52+
},
53+
]
54+
55+
56+
@hookimpl
57+
def pylsp_execute_command(config, workspace, command, arguments):
58+
logger.info("workspace/executeCommand: %s %s", command, arguments)
59+
60+
if command == "example.refactor.extract":
61+
current_document, range = arguments
62+
63+
workspace_edit = {
64+
"changes": {
65+
current_document: [
66+
{
67+
"range": range,
68+
"newText": "replacement text",
69+
},
70+
]
71+
}
72+
}
73+
74+
logger.info("applying workspace edit: %s %s", command, workspace_edit)
75+
workspace.apply_edit(workspace_edit)
76+
77+
78+
@hookimpl
79+
def pylsp_definitions(config, workspace, document, position):
80+
logger.info("textDocument/definition: %s %s", document, position)
81+
82+
filename = __file__
83+
uri = uris.uri_with(document.uri, path=filename)
84+
with open(filename) as f:
85+
lines = f.readlines()
86+
for lineno, line in enumerate(lines):
87+
if "def pylsp_definitions" in line:
88+
break
89+
return [
90+
{
91+
"uri": uri,
92+
"range": {
93+
"start": {
94+
"line": lineno,
95+
"character": 4,
96+
},
97+
"end": {
98+
"line": lineno,
99+
"character": line.find(")") + 1,
100+
},
101+
}
102+
}
103+
]

0 commit comments

Comments
 (0)