Skip to content

Commit 76f59d5

Browse files
authored
Merge pull request #587 from yuntan/pr-add-spec-pyright
add Pyright langserver spec
2 parents 080f772 + 252a8dc commit 76f59d5

File tree

16 files changed

+111
-21
lines changed

16 files changed

+111
-21
lines changed

.github/workflows/job.test.yml

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -214,15 +214,16 @@ jobs:
214214
include:
215215
# if using 3.6, use an old node
216216
- python: 3.6
217-
# Node 10 end-of-life: April 2021
218-
nodejs: '>=10,<11.0.0.a0'
219-
# if using 3.7, use newer node, etc...
220-
- python: 3.7
221217
# Node 12 end-of-life: April 2022
222218
nodejs: '>=12,<13.0.0.a0'
223-
- python: 3.8
219+
# if using 3.7, use newer node, etc...
220+
- python: 3.7
224221
# Node 14 end-of-life: April 2023
225222
nodejs: '>=14,<15.0.0.a0'
223+
- python: 3.8
224+
# TODO: switch to Node 16 once gets merged https://github.com/conda-forge/nodejs-feedstock/pull/189
225+
# Node 15 end-of-life: June 2021
226+
nodejs: '>=15,<16.0.0.a0'
226227
# TODO: remove when mambaforge just works on setup-miniconda
227228
- os: ubuntu
228229
mambaforge: Linux-x86_64.sh

CHANGELOG.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,17 @@
66

77
- add ability to deactivate Kernel completions or LSP completion through the settings ([#586], thanks @Carreau)
88
- allow to set a priority for LSP server, allowing to choose which server to use when multiple servers are installed ([#588])
9+
- add auto-detection of pyright server ([#587], thanks @yuntan)
910

1011
- bug fixes:
11-
- workaround url-parse issue causing problems when using JupyterLab 3.0.15 [#599]
12+
13+
- workaround url-parse issue causing problems when using JupyterLab 3.0.15 ([#599])
14+
15+
- other changes:
16+
- drop Node 10 (EOL 2 weeks ago) testing on CI, add Node 15 ([#587])
1217

1318
[#586]: https://github.com/krassowski/jupyterlab-lsp/pull/586
19+
[#587]: https://github.com/krassowski/jupyterlab-lsp/pull/587
1420
[#588]: https://github.com/krassowski/jupyterlab-lsp/pull/588
1521
[#599]: https://github.com/krassowski/jupyterlab-lsp/pull/599
1622

atest/01_Editor.robot

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,13 @@ Less
4343
Markdown
4444
Editor Shows Features for Language Markdown example.md Diagnostics=`Color` is misspelt
4545

46-
Python
46+
Python (pylsp)
4747
${def} = Set Variable xpath:(//span[contains(@class, 'cm-variable')][contains(text(), 'fib')])[last()]
48-
Editor Shows Features for Language Python example.py Diagnostics=multiple spaces after keyword Jump to Definition=${def} Rename=${def}
48+
Editor Shows Features for Server pylsp Python example.py Diagnostics=undefined name 'result' (pyflakes) Jump to Definition=${def} Rename=${def}
49+
50+
Python (pyright)
51+
${def} = Set Variable xpath:(//span[contains(@class, 'cm-variable')][contains(text(), 'fib')])[last()]
52+
Editor Shows Features for Server pyright Python example.py Diagnostics=is not defined (Pyright) Jump to Definition=${def}
4953

5054
R
5155
${def} = Set Variable xpath:(//span[contains(@class, 'cm-variable')][contains(text(), 'fib')])[last()]
@@ -70,6 +74,12 @@ YAML
7074
Editor Shows Features for Language YAML example.yaml Diagnostics=duplicate key
7175

7276
*** Keywords ***
77+
Editor Shows Features for Server
78+
[Arguments] ${server} ${Language} ${file} &{features}
79+
Configure JupyterLab Plugin
80+
... {"language_servers": {"${server}": {"priority": 10000}}}
81+
Editor Shows Features for Language ${Language} ${file} &{features}
82+
7383
Editor Shows Features for Language
7484
[Arguments] ${Language} ${file} &{features}
7585
Prepare File for Editing ${Language} editor ${file}

atest/Keywords.robot

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -375,6 +375,7 @@ Configure JupyterLab Plugin
375375
Set Editor Content ${settings json} ${CSS USER SETTINGS}
376376
Wait Until Page Contains No errors found
377377
Click Element css:button[title\='Save User Settings']
378+
Wait Until Page Contains No errors found
378379
Click Element ${JLAB XP CLOSE SETTINGS}
379380

380381
Clean Up After Working with File and Settings

atest/examples/example.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
from itertools import (accumulate, chain); accumulate
44

5-
65
# fibs :: Integer :: [Integer]
76
def fibs(n):
87
'''An accumulation of the first n integers in
@@ -27,5 +26,6 @@ def go(ab, _):
2726
print(
2827
'First twenty: ' + repr(
2928
fibs(20)
30-
)
29+
),
30+
result
3131
)

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
"npm-run-all": "^4.1.5",
2020
"precise-commits": "^1.0.2",
2121
"prettier": "^2.1.2",
22+
"pyright": "^1.1",
2223
"sql-language-server": "^0.11.4",
2324
"typescript": "~4.1.3",
2425
"unified-language-server": "^0.3.0",

packages/jupyterlab-lsp/schema/plugin.json

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,13 @@
3131
"language_servers": {
3232
"title": "Language Server",
3333
"description": "Language-server specific configuration, keyed by implementation, e.g: \n\npyls: {\n serverSettings: {\n pyls: {\n plugins: {\n pydocstyle: {\n enabled: true\n },\n pyflakes: {\n enabled: false\n },\n flake8: {\n enabled: true\n }\n }\n }\n }\n}\n\nAlternatively, using VSCode's naming convention:\n\npyls: {\n serverSettings: {\n \"pyls.plugins.pydocstyle.enabled\": true,\n \"pyls.plugins.pyflakes.enabled\": false,\n \"pyls.plugins.flake8.enabled\": true\n }\n}",
34-
"default": {},
34+
"default": {
35+
"pyright": {
36+
"serverSettings": {
37+
"python.analysis.useLibraryCodeForTypes": true
38+
}
39+
}
40+
},
3541
"patternProperties": {
3642
".*": {
3743
"$ref": "#/definitions/language-server"

packages/jupyterlab-lsp/src/connection_manager.ts

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -162,16 +162,28 @@ export class DocumentConnectionManager {
162162
}
163163

164164
/**
165-
* Currently only supports the settings that the language servers
166-
* accept using onDidChangeConfiguration messages, under the
167-
* "serverSettings" keyword in the setting registry. New keywords can
168-
* be added and extra functionality implemented here when needed.
165+
* Handles the settings that do not require an existing connection
166+
* with a language server (or can influence to which server the
167+
* connection will be created, e.g. `priority`).
168+
*
169+
* This function should be called **before** initialization of servers.
170+
*/
171+
public updateConfiguration(allServerSettings: TLanguageServerConfigurations) {
172+
this.language_server_manager.setConfiguration(allServerSettings);
173+
}
174+
175+
/**
176+
* Handles the settings that the language servers accept using
177+
* `onDidChangeConfiguration` messages, which should be passed under
178+
* the "serverSettings" keyword in the setting registry.
179+
* Other configuration options are handled by `updateConfiguration` instead.
180+
*
181+
* This function should be called **after** initialization of servers.
169182
*/
170183
public updateServerConfigurations(
171184
allServerSettings: TLanguageServerConfigurations
172185
) {
173186
let language_server_id: TServerKeys;
174-
this.language_server_manager.setConfiguration(allServerSettings);
175187

176188
for (language_server_id in allServerSettings) {
177189
if (!allServerSettings.hasOwnProperty(language_server_id)) {

packages/jupyterlab-lsp/src/index.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -179,8 +179,11 @@ export class LSPExtension implements ILSPExtension {
179179
.then(settings => {
180180
// Store the initial server settings, to be sent asynchronously
181181
// when the servers are initialized.
182-
this.connection_manager.initial_configurations = (settings.composite
183-
.language_servers || {}) as TLanguageServerConfigurations;
182+
const initial_configuration = (settings.composite.language_servers ||
183+
{}) as TLanguageServerConfigurations;
184+
this.connection_manager.initial_configurations = initial_configuration;
185+
// update the server-independent part of configuration immediately
186+
this.connection_manager.updateConfiguration(initial_configuration);
184187

185188
settings.changed.connect(() => {
186189
this.updateOptions(settings);
@@ -223,6 +226,10 @@ export class LSPExtension implements ILSPExtension {
223226

224227
const languageServerSettings = (options.language_servers ||
225228
{}) as TLanguageServerConfigurations;
229+
230+
this.connection_manager.initial_configurations = languageServerSettings;
231+
// TODO: if priorities changed reset connections
232+
this.connection_manager.updateConfiguration(languageServerSettings);
226233
this.connection_manager.updateServerConfigurations(languageServerSettings);
227234
}
228235
}

packages/jupyterlab-lsp/src/manager.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ export class LanguageServerManager implements ILanguageServerManager {
9090
}
9191
}
9292

93-
return matchingSessionsKeys.sort(this._comparePriorities);
93+
return matchingSessionsKeys.sort(this._comparePriorities.bind(this));
9494
}
9595

9696
get statusCode(): number {

0 commit comments

Comments
 (0)