refactoring LSP to its own service
This commit is contained in:
@@ -1,18 +1,15 @@
|
||||
import { Component, ElementRef, ViewChild, Input } from '@angular/core';
|
||||
|
||||
import { AceLanguageClient, LanguageClientConfig } from 'ace-linters/build/ace-language-client';
|
||||
|
||||
// Import Ace and its modes/themes so that `ace` global is defined
|
||||
import * as ace from 'ace-builds/src-noconflict/ace';
|
||||
import 'ace-builds/src-noconflict/theme-one_dark';
|
||||
import "ace-builds/src-noconflict/ext-language_tools";
|
||||
|
||||
import { LanguageProvider } from "ace-linters";
|
||||
|
||||
import { EditorSettings } from "../../common/configs/editor.config";
|
||||
import { ServiceMessage } from '../../common/types/service-message.type';
|
||||
|
||||
import { EditorsService } from '../../common/services/editor/editors.service';
|
||||
import { ServiceMessage } from '../../common/types/service-message.type';
|
||||
import { LSPService } from '../../common/services/lsp.service';
|
||||
|
||||
|
||||
|
||||
@@ -24,8 +21,7 @@ import { ServiceMessage } from '../../common/types/service-message.type';
|
||||
templateUrl: './ace-editor.component.html',
|
||||
styleUrl: './ace-editor.component.css',
|
||||
host: {
|
||||
'class': 'col',
|
||||
'(click)': 'onClick($event)'
|
||||
'class': 'col'
|
||||
}
|
||||
})
|
||||
export class AceEditorComponent {
|
||||
@@ -34,16 +30,16 @@ export class AceEditorComponent {
|
||||
@ViewChild('editor') editorElm!: ElementRef;
|
||||
editor!: any;
|
||||
uuid!: string;
|
||||
lspConfigData!: {};
|
||||
|
||||
|
||||
constructor(private editorsService: EditorsService) {
|
||||
}
|
||||
constructor(
|
||||
private editorsService: EditorsService,
|
||||
private lspService: LSPService
|
||||
) {}
|
||||
|
||||
|
||||
public ngAfterViewInit(): void {
|
||||
this.loadAce();
|
||||
this.loadLanguageProviders();
|
||||
}
|
||||
|
||||
public loadAce(): void {
|
||||
@@ -52,52 +48,15 @@ export class AceEditorComponent {
|
||||
this.editor = ace.edit( this.editorElm.nativeElement );
|
||||
this.editor.setOptions( this.editorSettings.CONFIG );
|
||||
// this.editor.commands.addCommands( this.editorSettings.KEYBINDINGS );
|
||||
}
|
||||
|
||||
protected onClick(event: any) {
|
||||
let message = new ServiceMessage();
|
||||
message.action = "set-editor";
|
||||
message.message = this.uuid;
|
||||
message.uuid = this.uuid;
|
||||
|
||||
this.editorsService.setData(message);
|
||||
}
|
||||
|
||||
public loadLanguageProviders(): void {
|
||||
let languageProvider = this.getLanguageProviderWithClientServers();
|
||||
// let languageProvider = this.getLanguageProviderWithWebWorker();
|
||||
languageProvider.registerEditor(this.editor);
|
||||
this.editor.on("focus", () => {
|
||||
this.editorsService.setActiveEditor(this.uuid);
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
public getLanguageProviderWithClientServers() {
|
||||
let _initializationOptions = {};
|
||||
|
||||
if (Object.keys(this.lspConfigData).length !== 0) {
|
||||
// _initializationOptions = this.lspConfigData[ this.editor.session.getMode() ]["initialization-options"];
|
||||
_initializationOptions = this.lspConfigData[ "python" ]["initialization-options"];
|
||||
}
|
||||
|
||||
let servers: LanguageClientConfig[] = [
|
||||
{
|
||||
module: () => import("ace-linters/build/language-client"),
|
||||
modes: "python",
|
||||
type: "socket",
|
||||
socket: new WebSocket("ws://127.0.0.1:9999/python"),
|
||||
// socket: new WebSocket("ws://127.0.0.1:9999/?name=pylsp"),
|
||||
initializationOptions: _initializationOptions
|
||||
}
|
||||
];
|
||||
|
||||
return AceLanguageClient.for(servers);
|
||||
}
|
||||
|
||||
|
||||
public getLanguageProviderWithWebWorker() {
|
||||
let worker = new Worker(new URL('./webworker.js', import.meta.url));
|
||||
return LanguageProvider.create(worker);
|
||||
public registerEditorToLSP() {
|
||||
this.lspService.registerEditor(this.editor);
|
||||
}
|
||||
|
||||
}
|
@@ -1,165 +0,0 @@
|
||||
import { ServiceManager } from "ace-linters/build/service-manager";
|
||||
|
||||
let manager = new ServiceManager(self);
|
||||
|
||||
manager.registerService("html", {
|
||||
features: {signatureHelp: false},
|
||||
module: () => import("ace-linters/build/html-service"),
|
||||
className: "HtmlService",
|
||||
modes: "html"
|
||||
});
|
||||
|
||||
manager.registerService("css", {
|
||||
features: {signatureHelp: false},
|
||||
module: () => import("ace-linters/build/css-service"),
|
||||
className: "CssService",
|
||||
modes: "css"
|
||||
});
|
||||
|
||||
manager.registerService("less", {
|
||||
features: {signatureHelp: false},
|
||||
module: () => import("ace-linters/build/css-service"),
|
||||
className: "CssService",
|
||||
modes: "less"
|
||||
});
|
||||
|
||||
manager.registerService("scss", {
|
||||
features: {signatureHelp: false},
|
||||
module: () => import("ace-linters/build/css-service"),
|
||||
className: "CssService",
|
||||
modes: "scss"
|
||||
});
|
||||
|
||||
manager.registerService("json", {
|
||||
features: {signatureHelp: false, documentHighlight: false},
|
||||
module: () => import("ace-linters/build/json-service"),
|
||||
className: "JsonService",
|
||||
modes: "json",
|
||||
});
|
||||
|
||||
manager.registerService("json5", {
|
||||
features: {signatureHelp: false, documentHighlight: false},
|
||||
module: () => import("ace-linters/build/json-service"),
|
||||
className: "JsonService",
|
||||
modes: "json5",
|
||||
});
|
||||
|
||||
manager.registerService("typescript", {
|
||||
module: () => import("ace-linters/build/typescript-service"),
|
||||
className: "TypescriptService",
|
||||
modes: "typescript|tsx|javascript|jsx",
|
||||
});
|
||||
|
||||
manager.registerService("yaml", {
|
||||
features: {signatureHelp: false, documentHighlight: false},
|
||||
module: () => import("ace-linters/build/yaml-service"),
|
||||
className: "YamlService",
|
||||
modes: "yaml",
|
||||
});
|
||||
|
||||
manager.registerService("xml", {
|
||||
features: {completion: false, completionResolve: false, diagnostics: true, format: false, hover: false, documentHighlight: false, signatureHelp: false},
|
||||
module: () => import("ace-linters/build/xml-service"),
|
||||
className: "XmlService",
|
||||
modes: "xml",
|
||||
});
|
||||
|
||||
manager.registerService("php", {
|
||||
features: {completion: false, completionResolve: false, diagnostics: true, format: false, hover: false, documentHighlight: false, signatureHelp: false},
|
||||
module: () => import("ace-linters/build/php-service"),
|
||||
className: "PhpService",
|
||||
modes: "php"
|
||||
});
|
||||
|
||||
manager.registerService("javascript", {
|
||||
features: {completion: false, completionResolve: false, diagnostics: true, format: false, hover: false, documentHighlight: false, signatureHelp: false},
|
||||
module: () => import("ace-linters/build/javascript-service"),
|
||||
className: "JavascriptService",
|
||||
modes: "javascript",
|
||||
});
|
||||
|
||||
|
||||
manager.registerServer("pythonls", {
|
||||
module: () => import("ace-linters/build/language-client"),
|
||||
modes: "python",
|
||||
type: "socket",
|
||||
socket: new WebSocket("ws://127.0.0.1:9999/?name=pylsp")
|
||||
});
|
||||
|
||||
|
||||
|
||||
/*
|
||||
|
||||
|
||||
manager.registerService("clang", {
|
||||
module: () => import("ace-clang-linter/build/ace-clang-linter"),
|
||||
className: "AceClangLinter",
|
||||
modes: "c_cpp",
|
||||
});
|
||||
|
||||
manager.registerService("lua", {
|
||||
features: {completion: false, completionResolve: false, diagnostics: true, format: true, hover: false, documentHighlight: false, signatureHelp: false},
|
||||
module: () => import("ace-lua-linter/build/ace-lua-linter"),
|
||||
className: "AceLuaLinter",
|
||||
modes: "lua",
|
||||
});
|
||||
|
||||
manager.registerService("mysql", {
|
||||
module: () => import("ace-sql-linter/build/mysql-service"),
|
||||
className: "MySQLService",
|
||||
modes: "mysql",
|
||||
});
|
||||
|
||||
manager.registerService("zig", {
|
||||
module: () => import("ace-zig-linter/build/ace-zig-linter"),
|
||||
className: "AceZigLinter",
|
||||
modes: "zig",
|
||||
});
|
||||
|
||||
manager.registerService("python", {
|
||||
features: {completion: false, completionResolve: false, diagnostics: true, format: true, hover: false, documentHighlight: false, signatureHelp: false},
|
||||
module: () => import("ace-python-ruff-linter/build/python-service"),
|
||||
className: "PythonService",
|
||||
modes: "python",
|
||||
});
|
||||
|
||||
manager.registerServer("svelte", {
|
||||
module: () => import("ace-linters/build/language-client"),
|
||||
modes: "html",
|
||||
type: "socket",
|
||||
socket: new WebSocket("ws://127.0.0.1:3030/svelte")
|
||||
});
|
||||
|
||||
manager.registerServer("astro", {
|
||||
module: () => import("ace-linters/build/language-client"),
|
||||
modes: "astro",
|
||||
type: "socket",
|
||||
socket: new WebSocket("ws://127.0.0.1:3030/astro"),
|
||||
initializationOptions: {
|
||||
typescript: {
|
||||
tsdk: "node_modules/typescript/lib", //path to typescript server
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
manager.registerServer("go", {
|
||||
module: () => import("ace-linters/build/language-client"),
|
||||
modes: "golang",
|
||||
type: "socket",
|
||||
socket: new WebSocket("ws://127.0.0.1:3030/go")
|
||||
});
|
||||
|
||||
manager.registerService("dart", {
|
||||
module: () => import("ace-dart-linter/build/ace-dart-linter"),
|
||||
className: "AceDartLinter",
|
||||
modes: "dart",
|
||||
});
|
||||
|
||||
manager.registerService("golang", {
|
||||
module: () => import("ace-go-linter/build/ace-go-linter"),
|
||||
className: "AceGoLinter",
|
||||
modes: "go",
|
||||
});
|
||||
|
||||
|
||||
*/
|
@@ -50,28 +50,19 @@ export class EditorsComponent {
|
||||
|
||||
|
||||
public ngAfterViewInit(): void {
|
||||
this.editorsService.getData$().pipe(
|
||||
this.loadSubscribers();
|
||||
|
||||
let editor = this.createEditor();
|
||||
this.activeEditor = editor.instance.uuid;
|
||||
this.createEditor();
|
||||
}
|
||||
|
||||
loadSubscribers() {
|
||||
this.editorsService.newActiveEditor$().pipe(
|
||||
takeUntil(this.unsubscribe)
|
||||
).subscribe((data: ServiceMessage) => {
|
||||
if (data.action === "set-editor")
|
||||
this.activeEditor = data.uuid;
|
||||
).subscribe((uuid: string) => {
|
||||
this.activeEditor = uuid;
|
||||
});
|
||||
|
||||
this.getLspConfigData().then((lspConfigData: string) => {
|
||||
this.lspConfigData = JSON.parse(lspConfigData);
|
||||
|
||||
if (this.lspConfigData["message"]) {
|
||||
console.log(
|
||||
"Warning: LSP this.lspConfigData is a 'message'",
|
||||
this.lspConfigData
|
||||
);
|
||||
this.lspConfigData = {};
|
||||
}
|
||||
|
||||
let editor = this.createEditor();
|
||||
this.activeEditor = editor.instance.uuid;
|
||||
this.createEditor();
|
||||
})
|
||||
}
|
||||
|
||||
ngOnDestroy() {
|
||||
@@ -79,15 +70,10 @@ export class EditorsComponent {
|
||||
this.unsubscribe.complete();
|
||||
}
|
||||
|
||||
private getLspConfigData(): Promise<string> {
|
||||
return window.fs.getLspConfigData();
|
||||
}
|
||||
|
||||
private createEditor() {
|
||||
const component = this.containerRef.createComponent(AceEditorComponent);
|
||||
component.instance.editorSettings = this.editorSettings;
|
||||
component.instance.uuid = uuid.v4();
|
||||
component.instance.lspConfigData = this.lspConfigData;
|
||||
this.editors.set(component.instance.uuid, component)
|
||||
|
||||
return component;
|
||||
@@ -97,8 +83,10 @@ export class EditorsComponent {
|
||||
this.loadFilesList(event).then((session: EditSession | undefined | null) => {
|
||||
if ( !session ) return;
|
||||
|
||||
let editor = this.editors.get(this.activeEditor)?.instance.editor;
|
||||
let editorComponent = this.editors.get(this.activeEditor)?.instance;
|
||||
let editor = editorComponent.editor;
|
||||
editor?.setSession(session);
|
||||
// editorComponent.registerEditorToLSP();
|
||||
});
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user