Skip to content

Commit 10aa2bb

Browse files
committed
Address review comments, back down on lowercase
1 parent b34e960 commit 10aa2bb

File tree

5 files changed

+36
-30
lines changed

5 files changed

+36
-30
lines changed

docs/Configuring.ipynb

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,7 @@
6666
" `mkdir \"new directory\"` should be split into `[\"mkdir\", \"new directory\"]`;\n",
6767
" If you have Python installed, you can use `shlex.split(\"your command\")` to\n",
6868
" get such an array.\n",
69-
"- the `languages` which the language server will respond to (language names\n",
70-
" should be given in lowercase), and\n",
69+
"- the `languages` which the language server will respond to, and\n",
7170
"- the schema `version` of the spec (currently `2`)\n",
7271
"- `mime_types` by which the notebooks and files will be matched to the language\n",
7372
" server:\n",

packages/jupyterlab-lsp/schema/plugin.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
},
2020
"priority": {
2121
"title": "Priority of the server",
22-
"description": "When multiple servers match specific document/language, the server with higher priority will be used",
22+
"description": "When multiple servers match specific document/language, the server with the highest priority will be used",
2323
"type": "number",
2424
"default": 50
2525
}

packages/jupyterlab-lsp/src/editor_integration/testutils.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ import { EditorAdapter } from './editor_adapter';
5454
import createNotebookPanel = NBTestUtils.createNotebookPanel;
5555
import IEditor = CodeEditor.IEditor;
5656

57+
const DEFAULT_SERVER_ID = 'pylsp';
58+
5759
export interface ITestEnvironment {
5860
document_options: VirtualDocument.IOptions;
5961

@@ -71,7 +73,7 @@ export interface ITestEnvironment {
7173
export class MockLanguageServerManager extends LanguageServerManager {
7274
async fetchSessions() {
7375
this._sessions = new Map();
74-
this._sessions.set('pylsp', {
76+
this._sessions.set(DEFAULT_SERVER_ID, {
7577
spec: {
7678
languages: ['python']
7779
}
@@ -243,7 +245,7 @@ function FeatureSupport<TBase extends TestEnvironmentConstructor>(Base: TBase) {
243245
languageId: this.document_options.language,
244246
serverUri: 'ws://localhost:8080',
245247
rootUri: 'file:///unit-test',
246-
serverIdentifier: 'pylsp'
248+
serverIdentifier: DEFAULT_SERVER_ID
247249
});
248250
}
249251

packages/jupyterlab-lsp/src/manager.ts

Lines changed: 29 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -52,40 +52,45 @@ export class LanguageServerManager implements ILanguageServerManager {
5252
this._configuration = configuration;
5353
}
5454

55+
protected _comparePriorities(a: TLanguageServerId, b: TLanguageServerId) {
56+
const DEFAULT_PRIORITY = 50;
57+
const a_priority = this._configuration[a]?.priority ?? DEFAULT_PRIORITY;
58+
const b_priority = this._configuration[b]?.priority ?? DEFAULT_PRIORITY;
59+
if (a_priority == b_priority) {
60+
this.console.warn(
61+
`Two matching servers: ${a} and ${b} have the same priority; choose which one to use by changing the priority in Advanced Settings Editor`
62+
);
63+
return a.localeCompare(b);
64+
}
65+
// higher priority = higher in the list (descending order)
66+
return b_priority - a_priority;
67+
}
68+
5569
getMatchingServers(options: ILanguageServerManager.IGetServerIdOptions) {
70+
if (!options.language) {
71+
this.console.error(
72+
'Cannot match server by language: language not available; ensure that kernel and specs provide language and MIME type'
73+
);
74+
return [];
75+
}
76+
5677
const matchingSessionsKeys: TLanguageServerId[] = [];
57-
const config = this._configuration;
78+
const lowerCaseLanguage = options.language.toLocaleLowerCase();
5879

5980
// most things speak language
6081
// if language is not known, it is guessed based on MIME type earlier
6182
// so some language should be available by now (which can be not obvious, e.g. "plain" for txt documents)
6283
for (const [key, session] of this._sessions.entries()) {
63-
if (options.language) {
64-
if (
65-
session.spec.languages.indexOf(
66-
options.language.toLocaleLowerCase()
67-
) !== -1
68-
) {
69-
matchingSessionsKeys.push(key);
70-
}
71-
} else {
72-
this.console.error(
73-
'Cannot match server by language: language not available; ensure that kernel and specs provide language and MIME type'
74-
);
84+
if (
85+
session.spec.languages.some(
86+
language => language.toLocaleLowerCase() == lowerCaseLanguage
87+
)
88+
) {
89+
matchingSessionsKeys.push(key);
7590
}
7691
}
7792

78-
return matchingSessionsKeys.sort((a, b) => {
79-
const a_priority = config[a]?.priority ?? 50;
80-
const b_priority = config[b]?.priority ?? 50;
81-
if (a_priority == b_priority) {
82-
this.console.warn(
83-
`Two matching servers: ${a} and ${b} have the same priority; choose which one to use by changing the priority in Advanced Settings Editor`
84-
);
85-
}
86-
// higher priority = higher in the list (descending order)
87-
return b_priority - a_priority;
88-
});
93+
return matchingSessionsKeys.sort(this._comparePriorities);
8994
}
9095

9196
get statusCode(): number {

python_packages/jupyter_lsp/jupyter_lsp/schema/schema.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
"type": "string"
3535
},
3636
"language-list": {
37-
"description": "languages supported by this Language Server; lowercase names",
37+
"description": "languages supported by this Language Server",
3838
"items": {
3939
"type": "string"
4040
},

0 commit comments

Comments
 (0)