Skip to content

Commit 905b61c

Browse files
Support both python-lsp-server and python-language-server as a backend
1 parent edce8a6 commit 905b61c

File tree

2 files changed

+45
-7
lines changed

2 files changed

+45
-7
lines changed

README.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
![](https://img.shields.io/badge/dynamic/json?color=brightgreen&label=Latest%20Version&query=%24.version&url=https%3A%2F%2Fraw.githubusercontent.com%2Fmmshivesh%2FPython-Nova.novaextension%2Fmaster%2Fextension.json)
77

8-
Full featured Python Language Server Plugin (implements [PyLS](https://github.com/palantir/python-language-server)) for Nova, supports Jedi Autocomplete, PyFlakes, PyLint, YAPF, Rope, McCabe, PyDoc and CodeStyles.
8+
Full featured Python Language Server plugin (implements [PyLS](https://github.com/python-lsp/python-lsp-server)) for Nova, supports Jedi Autocomplete, PyFlakes, PyLint, YAPF, Rope, McCabe, PyDoc and CodeStyles.
99

1010
Also supports all the Python Language Server plugins → `mypy`, `isort` and `black`
1111

@@ -21,10 +21,10 @@ Also supports all the Python Language Server plugins → `mypy`, `isort` and `bl
2121

2222
## Installation
2323

24-
1. Install dependencies using:
24+
1. Install the LSP server and its dependencies using:
2525

2626
```bash
27-
pip3 install 'python-language-server[all]'
27+
pip3 install 'python-lsp-server[all]'
2828
```
2929

3030
2. Enable required modules from settings.

Scripts/main.js

+42-4
Original file line numberDiff line numberDiff line change
@@ -78,11 +78,49 @@ function getPreference(string, def, workspace=false) {
7878
}
7979
}
8080

81+
// Convenience function to get the 'pyls.executable' preference, or default to an appropriate bin in the user's $PATH.
82+
function getPyLSExecutablePreference() {
83+
return getPreference('pyls.executable', searchUsablePyLSExecutable())
84+
}
85+
86+
// Try to find an appropriate bin for the PyLSP server in the user's $PATH.
87+
function searchUsablePyLSExecutable() {
88+
const envPath = nova.environment['PATH']
89+
if (envPath === undefined) {
90+
return undefined
91+
}
92+
93+
const possibleBins = ['pylsp', 'pyls']
94+
const possiblePaths = envPath.split(':')
95+
for (const bin of possibleBins) {
96+
for (const path of possiblePaths) {
97+
const binPath = path + '/' + bin
98+
if (nova.fs.access(binPath, nova.fs.F_OK | nova.fs.X_OK)) {
99+
return binPath
100+
}
101+
}
102+
}
103+
104+
return undefined
105+
}
106+
107+
// Return the appropriate settings namespace for the configured Python LSP implementation.
108+
function getSettingsPyLSNamespace() {
109+
if (getPyLSExecutablePreference() === "pyls") {
110+
return "pyls"
111+
} else {
112+
// If the selected binary is not explicitly pyls, default to the fork
113+
// pylsp as it is more up to date and maintained.
114+
return "pylsp"
115+
}
116+
}
117+
81118
// Get and return the preferences dictionary
82119
function getSettings() {
83120
return {
121+
const pylsNamespace = getSettingsPyLSNamespace()
84122
settings: {
85-
"pyls": {
123+
pylsNamespace: {
86124
"env": {},
87125
"configurationSources": [
88126
getPreference('pyls.configurationSources')
@@ -205,7 +243,7 @@ class PythonLanguageServer {
205243
this.addPreferenceObservers();
206244
// First start.
207245
showNotification("Starting extension.");
208-
this.start(getPreference('pyls.executable', '/usr/local/bin/pyls'));
246+
this.start(getPyLSExecutablePreference());
209247
}
210248

211249
addPreferenceObservers() {
@@ -280,9 +318,9 @@ class PythonLanguageServer {
280318
showNotification("Stopping extension.");
281319
await this.stop();
282320
nova.subscriptions.remove(this.languageClient);
283-
await this.start(getPreference('pyls.executable', '/usr/local/bin/pyls'));
321+
await this.start(getPyLSExecutablePreference());
284322
} else {
285-
await this.start(getPreference('pyls.executable', '/usr/local/bin/pyls'));
323+
await this.start(getPyLSExecutablePreference());
286324
}
287325
}, this);
288326
}

0 commit comments

Comments
 (0)