Skip to content

Commit 731721d

Browse files
authored
Merge pull request #18 from guillaumealgis/pylsp-settings-namespace
Migrate to python-lsp-server ?
2 parents 4a7ef2a + 905b61c commit 731721d

File tree

2 files changed

+45
-7
lines changed

2 files changed

+45
-7
lines changed

README.md

Lines changed: 3 additions & 3 deletions
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

Lines changed: 42 additions & 4 deletions
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')
@@ -202,7 +240,7 @@ class PythonLanguageServer {
202240
this.addPreferenceObservers();
203241
// First start.
204242
showNotification("Starting extension.");
205-
this.start(getPreference('pyls.executable', '/usr/local/bin/pyls'));
243+
this.start(getPyLSExecutablePreference());
206244
}
207245

208246
addPreferenceObservers() {
@@ -277,9 +315,9 @@ class PythonLanguageServer {
277315
showNotification("Stopping extension.");
278316
await this.stop();
279317
nova.subscriptions.remove(this.languageClient);
280-
await this.start(getPreference('pyls.executable', '/usr/local/bin/pyls'));
318+
await this.start(getPyLSExecutablePreference());
281319
} else {
282-
await this.start(getPreference('pyls.executable', '/usr/local/bin/pyls'));
320+
await this.start(getPyLSExecutablePreference());
283321
}
284322
}, this);
285323
}

0 commit comments

Comments
 (0)