updating LSP service to load language servers dynamically
This commit is contained in:
parent
fc7b728fe4
commit
7b08922d20
@ -11,7 +11,7 @@ import { LanguageProvider } from "ace-linters";
|
||||
})
|
||||
export class LSPService {
|
||||
lspConfigData!: {};
|
||||
languageProvider!: any;
|
||||
languageProviders: {} = {};
|
||||
|
||||
constructor() {
|
||||
this.loadLSPService();
|
||||
@ -29,47 +29,49 @@ export class LSPService {
|
||||
|
||||
this.lspConfigData = {};
|
||||
}
|
||||
}).then(() => {
|
||||
this.loadLanguageProviders();
|
||||
});
|
||||
}
|
||||
|
||||
public registerEditor(editor: any): void {
|
||||
this.languageProvider.registerEditor(editor);
|
||||
let modeParts = editor.getSession()["$modeId"].split("/");
|
||||
let mode = modeParts[ modeParts.length - 1];
|
||||
|
||||
if ( !this.languageProviders[mode] ) {
|
||||
this.languageProviders[mode] = this.getLanguageProviderWithClientServer(mode);
|
||||
}
|
||||
|
||||
this.languageProviders[mode].registerEditor(editor);
|
||||
}
|
||||
|
||||
private getLspConfigData(): Promise<string> {
|
||||
return window.fs.getLspConfigData();
|
||||
}
|
||||
|
||||
private loadLanguageProviders(): void {
|
||||
this.languageProvider = this.getLanguageProviderWithClientServers();
|
||||
// this.languageProvider = this.getLanguageProviderWithWebWorker();
|
||||
private getLanguageProviderWithClientServers() {
|
||||
this.getLanguageProviderWithClientServer("python");
|
||||
}
|
||||
|
||||
private getLanguageProviderWithClientServers() {
|
||||
private getLanguageProviderWithClientServer(mode: string) {
|
||||
let _initializationOptions = {};
|
||||
|
||||
if (Object.keys(this.lspConfigData).length !== 0) {
|
||||
// _initializationOptions = this.lspConfigData[ this.editor.session.getMode() ]["initialization-options"];
|
||||
_initializationOptions = this.lspConfigData[ "python" ]["initialization-options"];
|
||||
_initializationOptions = this.lspConfigData[ mode ]["initialization-options"];
|
||||
}
|
||||
|
||||
let servers: LanguageClientConfig[] = [
|
||||
{
|
||||
module: () => import("ace-linters/build/language-client"),
|
||||
modes: "python",
|
||||
modes: mode,
|
||||
type: "socket",
|
||||
socket: new WebSocket("ws://127.0.0.1:9999/python"),
|
||||
// socket: new WebSocket("ws://127.0.0.1:9999/?name=pylsp"),
|
||||
socket: new WebSocket(`ws://127.0.0.1:9999/${mode}`),
|
||||
// socket: new WebSocket("ws://127.0.0.1:9999/?name=pylsp"),
|
||||
initializationOptions: _initializationOptions
|
||||
}
|
||||
];
|
||||
|
||||
return AceLanguageClient.for(servers);
|
||||
}
|
||||
|
||||
|
||||
|
||||
private getLanguageProviderWithWebWorker() {
|
||||
let worker = new Worker(new URL('./webworker.js', import.meta.url));
|
||||
return LanguageProvider.create(worker);
|
||||
|
@ -49,13 +49,19 @@ export class AceEditorComponent {
|
||||
this.editor.setOptions( this.editorSettings.CONFIG );
|
||||
// this.editor.commands.addCommands( this.editorSettings.KEYBINDINGS );
|
||||
|
||||
// Note: https://github.com/mkslanc/ace-linters/blob/c286d85c558530aa1b0597d02108bc782abd4736/packages/ace-linters/src/language-provider.ts#L277
|
||||
// found on focus ^ might have other signals we can watch like session being set, etc.
|
||||
this.editor.on("focus", () => {
|
||||
this.editorsService.setActiveEditor(this.uuid);
|
||||
});
|
||||
|
||||
// this.editor.on("changeSession", (session) => {
|
||||
// console.log(session);
|
||||
// console.log(session.session["$modeId"]);
|
||||
// });
|
||||
}
|
||||
|
||||
public registerEditorToLSP() {
|
||||
public registerEditorToLSPMode() {
|
||||
this.lspService.registerEditor(this.editor);
|
||||
}
|
||||
|
||||
|
@ -86,7 +86,7 @@ export class EditorsComponent {
|
||||
let editorComponent = this.editors.get(this.activeEditor)?.instance;
|
||||
let editor = editorComponent.editor;
|
||||
editor?.setSession(session);
|
||||
// editorComponent.registerEditorToLSP();
|
||||
editorComponent.registerEditorToLSPMode();
|
||||
});
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user