updating LSP service to load language servers dynamically
This commit is contained in:
parent
fc7b728fe4
commit
05d48c5878
@ -11,7 +11,7 @@ import { LanguageProvider } from "ace-linters";
|
|||||||
})
|
})
|
||||||
export class LSPService {
|
export class LSPService {
|
||||||
lspConfigData!: {};
|
lspConfigData!: {};
|
||||||
languageProvider!: any;
|
languageProviders: {} = {};
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
this.loadLSPService();
|
this.loadLSPService();
|
||||||
@ -29,47 +29,45 @@ export class LSPService {
|
|||||||
|
|
||||||
this.lspConfigData = {};
|
this.lspConfigData = {};
|
||||||
}
|
}
|
||||||
}).then(() => {
|
|
||||||
this.loadLanguageProviders();
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public registerEditor(editor: any): void {
|
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> {
|
private getLspConfigData(): Promise<string> {
|
||||||
return window.fs.getLspConfigData();
|
return window.fs.getLspConfigData();
|
||||||
}
|
}
|
||||||
|
|
||||||
private loadLanguageProviders(): void {
|
private getLanguageProviderWithClientServer(mode: string) {
|
||||||
this.languageProvider = this.getLanguageProviderWithClientServers();
|
|
||||||
// this.languageProvider = this.getLanguageProviderWithWebWorker();
|
|
||||||
}
|
|
||||||
|
|
||||||
private getLanguageProviderWithClientServers() {
|
|
||||||
let _initializationOptions = {};
|
let _initializationOptions = {};
|
||||||
|
|
||||||
if (Object.keys(this.lspConfigData).length !== 0) {
|
if (Object.keys(this.lspConfigData).length !== 0) {
|
||||||
// _initializationOptions = this.lspConfigData[ this.editor.session.getMode() ]["initialization-options"];
|
_initializationOptions = this.lspConfigData[mode]["initialization-options"];
|
||||||
_initializationOptions = this.lspConfigData[ "python" ]["initialization-options"];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
let servers: LanguageClientConfig[] = [
|
let servers: LanguageClientConfig[] = [
|
||||||
{
|
{
|
||||||
module: () => import("ace-linters/build/language-client"),
|
module: () => import("ace-linters/build/language-client"),
|
||||||
modes: "python",
|
modes: mode,
|
||||||
type: "socket",
|
type: "socket",
|
||||||
socket: new WebSocket("ws://127.0.0.1:9999/python"),
|
socket: new WebSocket(`ws://127.0.0.1:9999/${mode}`),
|
||||||
// socket: new WebSocket("ws://127.0.0.1:9999/?name=pylsp"),
|
// socket: new WebSocket("ws://127.0.0.1:9999/?name=pylsp"),
|
||||||
initializationOptions: _initializationOptions
|
initializationOptions: _initializationOptions
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
|
|
||||||
return AceLanguageClient.for(servers);
|
return AceLanguageClient.for(servers);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private getLanguageProviderWithWebWorker() {
|
private getLanguageProviderWithWebWorker() {
|
||||||
let worker = new Worker(new URL('./webworker.js', import.meta.url));
|
let worker = new Worker(new URL('./webworker.js', import.meta.url));
|
||||||
return LanguageProvider.create(worker);
|
return LanguageProvider.create(worker);
|
||||||
|
@ -5,12 +5,11 @@ import * as ace from 'ace-builds/src-noconflict/ace';
|
|||||||
import 'ace-builds/src-noconflict/theme-one_dark';
|
import 'ace-builds/src-noconflict/theme-one_dark';
|
||||||
import "ace-builds/src-noconflict/ext-language_tools";
|
import "ace-builds/src-noconflict/ext-language_tools";
|
||||||
|
|
||||||
import { EditorSettings } from "../../common/configs/editor.config";
|
|
||||||
import { ServiceMessage } from '../../common/types/service-message.type';
|
|
||||||
|
|
||||||
import { EditorsService } from '../../common/services/editor/editors.service';
|
import { EditorsService } from '../../common/services/editor/editors.service';
|
||||||
import { LSPService } from '../../common/services/lsp.service';
|
import { LSPService } from '../../common/services/lsp.service';
|
||||||
|
|
||||||
|
import { EditorSettings } from "../../common/configs/editor.config";
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
@ -49,13 +48,19 @@ export class AceEditorComponent {
|
|||||||
this.editor.setOptions( this.editorSettings.CONFIG );
|
this.editor.setOptions( this.editorSettings.CONFIG );
|
||||||
// this.editor.commands.addCommands( this.editorSettings.KEYBINDINGS );
|
// 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.editor.on("focus", () => {
|
||||||
this.editorsService.setActiveEditor(this.uuid);
|
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);
|
this.lspService.registerEditor(this.editor);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -86,7 +86,7 @@ export class EditorsComponent {
|
|||||||
let editorComponent = this.editors.get(this.activeEditor)?.instance;
|
let editorComponent = this.editors.get(this.activeEditor)?.instance;
|
||||||
let editor = editorComponent.editor;
|
let editor = editorComponent.editor;
|
||||||
editor?.setSession(session);
|
editor?.setSession(session);
|
||||||
// editorComponent.registerEditorToLSP();
|
editorComponent.registerEditorToLSPMode();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user