-
Notifications
You must be signed in to change notification settings - Fork 148
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add priority setting for servers handling the same language #588
Changes from 2 commits
57055c1
b34e960
10aa2bb
6d7647d
a5d515e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -35,7 +35,12 @@ import { LSPConnection } from '../connection'; | |
import { DocumentConnectionManager } from '../connection_manager'; | ||
import { SERVER_EXTENSION_404 } from '../errors'; | ||
import { LanguageServerManager } from '../manager'; | ||
import { ILSPAdapterManager, ILanguageServerManager } from '../tokens'; | ||
import { | ||
ILSPAdapterManager, | ||
ILanguageServerManager, | ||
TSessionMap, | ||
TLanguageServerId | ||
} from '../tokens'; | ||
import { VirtualDocument, collect_documents } from '../virtual/document'; | ||
|
||
import { codeCheckIcon, codeClockIcon, codeWarningIcon } from './icons'; | ||
|
@@ -464,34 +469,44 @@ export namespace LSPStatus { | |
}, this); | ||
} | ||
|
||
get available_servers(): Array<SCHEMA.LanguageServerSession> { | ||
return Array.from(this.language_server_manager.sessions.values()); | ||
get available_servers(): TSessionMap { | ||
return this.language_server_manager.sessions; | ||
} | ||
|
||
get supported_languages(): Set<string> { | ||
const languages = new Set<string>(); | ||
for (let server of this.available_servers) { | ||
for (let server of this.available_servers.values()) { | ||
for (let language of server.spec.languages) { | ||
languages.add(language.toLocaleLowerCase()); | ||
} | ||
} | ||
return languages; | ||
} | ||
|
||
private is_server_running(server: SCHEMA.LanguageServerSession): boolean { | ||
for (let language of server.spec.languages) { | ||
if (this.detected_languages.has(language.toLocaleLowerCase())) { | ||
private is_server_running( | ||
id: TLanguageServerId, | ||
server: SCHEMA.LanguageServerSession | ||
): boolean { | ||
for (const language of this.detected_languages) { | ||
const matchedServers = this.language_server_manager.getMatchingServers({ | ||
language | ||
}); | ||
// TODO server.status === "started" ? | ||
// TODO update once multiple servers are allowed | ||
if (matchedServers.length && matchedServers[0] === id) { | ||
return true; | ||
} | ||
} | ||
return false; | ||
} | ||
|
||
get documents_by_server(): Map< | ||
SCHEMA.LanguageServerSession, | ||
Map<string, VirtualDocument[]> | ||
> { | ||
let data = new Map(); | ||
let data = new Map< | ||
SCHEMA.LanguageServerSession, | ||
Map<string, VirtualDocument[]> | ||
>(); | ||
if (!this.adapter?.virtual_editor) { | ||
return data; | ||
} | ||
|
@@ -501,19 +516,17 @@ export namespace LSPStatus { | |
|
||
for (let document of documents.values()) { | ||
let language = document.language.toLocaleLowerCase(); | ||
let servers = this.available_servers.filter( | ||
server => server.spec.languages.indexOf(language) !== -1 | ||
let server_ids = this._connection_manager.language_server_manager.getMatchingServers( | ||
{ language: document.language } | ||
); | ||
if (servers.length > 1) { | ||
console.warn('More than one server per language for', language); | ||
} | ||
if (servers.length === 0) { | ||
if (server_ids.length === 0) { | ||
continue; | ||
} | ||
let server = servers[0]; | ||
// For now only use the server with the highest priority | ||
Comment on lines
-504
to
+525
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should probably use the connection + server Identifier here. Also should we restart all connections if preferred language server changed our just add a note that JupyterLab reload is needed for changes to go into effect? Probably the latter There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i think wherever possible, settings changes should take effect immediately, since have established the pattern... can see how it would be a tad onerous There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Right. But I would prefer not to do this now given the plan to rewrite it later to support multiple connections per document which would invalidate the logic; lets consider the priority setting a tool for us to test multiple servers on CI for now, and a user-facing feature once it starts defining priority between multiple servers running in tandem. |
||
let server = this.language_server_manager.sessions.get(server_ids[0]); | ||
|
||
if (!data.has(server)) { | ||
data.set(server, new Map<string, VirtualDocument>()); | ||
data.set(server, new Map<string, VirtualDocument[]>()); | ||
} | ||
|
||
let documents_map = data.get(server); | ||
|
@@ -529,9 +542,9 @@ export namespace LSPStatus { | |
} | ||
|
||
get servers_available_not_in_use(): Array<SCHEMA.LanguageServerSession> { | ||
return this.available_servers.filter( | ||
server => !this.is_server_running(server) | ||
); | ||
return [...this.available_servers.entries()] | ||
.filter(([id, server]) => !this.is_server_running(id, server)) | ||
.map(([id, server]) => server); | ||
} | ||
|
||
get detected_languages(): Set<string> { | ||
|
@@ -577,10 +590,11 @@ export namespace LSPStatus { | |
|
||
detected_documents.forEach((document, uri) => { | ||
let connection = this._connection_manager.connections.get(uri); | ||
let server_id = this._connection_manager.language_server_manager.getServerId( | ||
let server_ids = this._connection_manager.language_server_manager.getMatchingServers( | ||
{ language: document.language } | ||
); | ||
if (server_id !== null) { | ||
|
||
if (server_ids.length !== 0) { | ||
documents_with_known_servers.add(document); | ||
} | ||
if (!connection) { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
getting long... maybe we hoist to a fixture file?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, could we have
Configure JupyterLab Plugin
merge the new settings with the default priorities (unless custom priorities are given)? This should simplify tests that have custom config.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Or just move
"pylsp": {"priority": 1000}
to a fixture file. I think we used to have a json file for frontend settings but cannot see it.