Skip to content

Commit b439a88

Browse files
committed
jedi-language-server for Sublime Text
1 parent 1580763 commit b439a88

12 files changed

+261
-0
lines changed

.python-version

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
3.8

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2021 Raoul Wols <[email protected]>
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.

LSP-jedi.sublime-commands

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
[
2+
{
3+
"caption": "Preferences: LSP-jedi Settings",
4+
"command": "edit_settings",
5+
"args": {
6+
"base_file": "${packages}/LSP-jedi/LSP-jedi.sublime-settings",
7+
"default": "// Settings in here override those in \"LSP-jedi/LSP-jedi.sublime-settings\"\n{\n\t$0\n}\n"
8+
}
9+
}
10+
]

LSP-jedi.sublime-settings

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
// This file is read-only and lives in
2+
//
3+
// $DATA/Installed Packages/LSP-jedi.sublime-package
4+
//
5+
// Provided you installed this package through Package Control. To modify one
6+
// of these settings, you should see a template file to your right where you
7+
// can override various key-value pairs.
8+
//
9+
// It is safe to partially override the "settings" key. All the option of jedi-language-server are provided in
10+
// the official link at https://github.com/pappasam/jedi-language-server
11+
//
12+
//
13+
// You must then *save* the *right* view in
14+
// $DATA/Packages/User/LSP-jedi.sublime-settings.
15+
{
16+
// Defines the Python interpreter to use for creating an environment in which `jedi-language-serever` will run.
17+
// The value can be set to a binary name (like `python`, in which case a binary with that name needs to be present
18+
// on the PATH) or a full path to the Python interpreter binary.
19+
// When the value is `null` then it defaults to `python` on Windows and `python3` on other platforms.
20+
"python_binary": null,
21+
"env": {
22+
// Override PYTHONPATH to extend the paths that jedi searches when looking for stub files.
23+
// Paths have to be specified in two places so that Jedi can pick up types and stubs.
24+
"PYTHONPATH": "${sublime_py_files_dir}${pathsep}${packages}",
25+
"MYPYPATH": "${sublime_py_files_dir}${pathsep}${packages}"
26+
},
27+
"settings": {
28+
"initializationOptions": {
29+
"codeAction": {
30+
"nameExtractVariable": "jls_extract_var",
31+
"nameExtractFunction": "jls_extract_def"
32+
},
33+
"completion": {
34+
"disableSnippets": false,
35+
"resolveEagerly": false,
36+
"ignorePatterns": []
37+
},
38+
"diagnostics": {
39+
"enable": false,
40+
"didOpen": true,
41+
"didChange": true,
42+
"didSave": true
43+
},
44+
"hover": {
45+
"enable": true,
46+
"disable": {
47+
"class": { "all": false, "names": [], "fullNames": [] },
48+
"function": { "all": false, "names": [], "fullNames": [] },
49+
"instance": { "all": false, "names": [], "fullNames": [] },
50+
"keyword": { "all": false, "names": [], "fullNames": [] },
51+
"module": { "all": false, "names": [], "fullNames": [] },
52+
"param": { "all": false, "names": [], "fullNames": [] },
53+
"path": { "all": false, "names": [], "fullNames": [] },
54+
"property": { "all": false, "names": [], "fullNames": [] },
55+
"statement": { "all": false, "names": [], "fullNames": [] }
56+
}
57+
},
58+
"jediSettings": {
59+
"autoImportModules": ["numpy", "pandas"],
60+
"caseInsensitiveCompletion": true,
61+
"debug": false
62+
},
63+
"markupKindPreferred": "markdown",
64+
"workspace": {
65+
"extraPaths": [],
66+
"environmentPath": "/home/sundar/miniconda3/envs",
67+
"symbols": {
68+
"ignoreFolders": [".nox", ".tox", ".venv", "__pycache__", "venv"],
69+
"maxSymbols": 20
70+
}
71+
}
72+
}
73+
},
74+
"command": ["$server_path"],
75+
"selector": "source.python"
76+
}

Main.sublime-menu

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
[
2+
{
3+
"id": "preferences",
4+
"children": [
5+
{
6+
"caption": "Package Settings",
7+
"mnemonic": "P",
8+
"id": "package-settings",
9+
"children": [
10+
{
11+
"caption": "LSP",
12+
"id": "lsp-settings",
13+
"children": [
14+
{
15+
"caption": "Servers",
16+
"id": "lsp-servers",
17+
"children": [
18+
{
19+
"caption": "LSP-jedi",
20+
"command": "edit_settings",
21+
"args": {
22+
"base_file": "${packages}/LSP-jedi/LSP-jedi.sublime-settings",
23+
"default": "// Settings in here override those in \"LSP-jedi/LSP-jedi.sublime-settings\"\n\n{\n\t$0\n}\n",
24+
},
25+
},
26+
],
27+
},
28+
],
29+
},
30+
],
31+
},
32+
],
33+
},
34+
]

dependencies.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"*": {
3+
"*": [
4+
"lsp_utils",
5+
"sublime_lib"
6+
]
7+
}
8+
}

mypy.ini

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[mypy]
2+
ignore_missing_imports = True
3+
strict_optional = True

plugin.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
from LSP.plugin.core.typing import Dict
2+
from lsp_utils.pip_client_handler import PipClientHandler
3+
import os
4+
import sublime
5+
6+
7+
class Jedilsp(PipClientHandler):
8+
package_name = __package__
9+
requirements_txt_path = "requirements.txt"
10+
server_filename = "jedi-language-server"
11+
12+
# --- PipClientHandler handlers ------------------------------------------------------------------------------------
13+
14+
@classmethod
15+
def get_python_binary(cls) -> str:
16+
settings = sublime.load_settings("{}.sublime-settings".format(cls.package_name))
17+
python_binary = settings.get("python_binary")
18+
if python_binary and isinstance(python_binary, str):
19+
return python_binary
20+
return super().get_python_binary()
21+
22+
@classmethod
23+
def get_additional_variables(cls) -> Dict[str, str]:
24+
variables = super().get_additional_variables()
25+
variables.update(
26+
{
27+
"sublime_py_files_dir": os.path.dirname(sublime.__file__),
28+
}
29+
)
30+
return variables
31+
32+
33+
def plugin_loaded() -> None:
34+
Jedilsp.setup()
35+
36+
37+
def plugin_unloaded() -> None:
38+
Jedilsp.cleanup()

pyproject.toml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
[tool.black]
2+
line-length = 120
3+
target-version = ['py33']
4+
5+
[tool.pyright]
6+
pythonVersion = '3.11'
7+
8+
[tool.ruff]
9+
line-length = 120

requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
jedi-language-server==0.41.4

0 commit comments

Comments
 (0)