WIP lsp-manager effort 2

This commit is contained in:
2025-07-13 14:41:46 -05:00
parent 9e01628ffb
commit 766e70d766
16 changed files with 308 additions and 102 deletions

View File

@@ -1,4 +1,4 @@
import { Component, ElementRef, HostBinding, ViewChild, inject } from '@angular/core';
import { Component, ChangeDetectorRef, ElementRef, HostBinding, ViewChild, inject } from '@angular/core';
import { Subject, takeUntil } from 'rxjs';
import { LspManagerService } from '../../common/services/editor/lsp-manager/lsp-manager.service';
@@ -23,14 +23,20 @@ import { ServiceMessage } from '../../common/types/service-message.type';
}
})
export class LspManagerComponent {
private unsubscribe: Subject<void> = new Subject();
private unsubscribe: Subject<void> = new Subject();
private changeDetectorRef: ChangeDetectorRef = inject(ChangeDetectorRef);
private lspManagerService: LspManagerService = inject(LspManagerService);
lspManagerService: LspManagerService = inject(LspManagerService);
@HostBinding("class.hidden") isHidden: boolean = true;
@ViewChild('editorComponent') editorComponent!: CodeViewComponent;
lspTextEditor!: any;
private editor: any;
@ViewChild('lspEditorComponent') lspEditorComponent!: CodeViewComponent;
@ViewChild('sessionEditorComponent') sessionEditorComponent!: CodeViewComponent;
lspTextEditor: any;
innerEditor: any;
editor: any;
activeFile: any;
constructor() {
@@ -38,13 +44,7 @@ export class LspManagerComponent {
private ngAfterViewInit(): void {
this.lspTextEditor = this.editorComponent.editor;
this.lspManagerService.loadLspConfigData().then((lspConfigData) => {
this.lspTextEditor.session.setMode("ace/mode/json");
this.lspTextEditor.session.setValue(lspConfigData);
});
this.mapEditorsAndLoadConfig();
this.loadSubscribers();
}
@@ -53,6 +53,16 @@ export class LspManagerComponent {
this.unsubscribe.complete();
}
private mapEditorsAndLoadConfig() {
this.lspTextEditor = this.lspEditorComponent.editor;
this.innerEditor = this.sessionEditorComponent.editor;
this.lspManagerService.loadLspConfigData().then((lspConfigData) => {
this.lspTextEditor.session.setMode("ace/mode/json");
this.lspTextEditor.session.setValue(lspConfigData);
});
}
private loadSubscribers() {
this.lspManagerService.getMessage$().pipe(
takeUntil(this.unsubscribe)
@@ -61,28 +71,90 @@ export class LspManagerComponent {
this.toggleLspManager(message);
} else if (message.action === "set-active-editor") {
this.setActiveEditor(message);
} else if (message.action === "editor-update") {
this.editorUpdate(message);
} else if (message.action === "close-file") {
this.closeFile(message);
}
});
}
public hideLspManager() {
this.isHidden = true;
this.editor.focus();
public clearWorkspaceFolder() {
this.lspManagerService.workspaceFolder = "";
}
public setWorkspaceFolder() {
window.fs.chooseFolder().then((folder: string) => {
if (!folder) return;
this.lspManagerService.workspaceFolder = folder;
});
}
public createLanguageClient() {
let mode = this.lspManagerService.getMode(this.editor.session);
this.lspManagerService.createLanguageProviderWithClientServer(mode);
}
public registerEditorToLanguageClient() {
this.lspManagerService.registerEditorToLSPClient(this.editor);
/*
this.lspManagerService.setSessionFilePath(
this.editor.session,
this.activeFile.path
);
*/
}
public globalLspManagerKeyHandler(event: any) {
if (event.ctrlKey && event.shiftKey && event.key === "l") {
this.hideLspManager();
}
}
public hideLspManager() {
this.isHidden = true;
this.editor.focus();
}
private toggleLspManager(message: ServiceMessage) {
this.isHidden = !this.isHidden;
if (this.isHidden) return;
// Note: hack for issue with setActiveEditor TODO
setTimeout(() => {
this.innerEditor.setSession(this.editor.getSession());
}, 10);
}
private setActiveEditor(message: ServiceMessage) {
this.editor = message.rawData;
this.editor = message.rawData.editor;
this.activeFile = message.rawData.activeFile;
// TODO: figure out why this doesn't update the session consistently...
// It seems maybe bound to visible state as change detector ref didn't help either.
// this.innerEditor.setSession(this.editor.session);
}
private editorUpdate(message: ServiceMessage) {
if (!message.rawData.activeFile) return;
this.editor.setSession(message.rawData.editor.getSession())
this.activeFile = message.rawData.activeFile;
/*
this.lspManagerService.setSessionFilePath(
this.editor.session,
this.activeFile.path
);
*/
}
private closeFile(message: ServiceMessage) {
this.lspManagerService.closeDocument(message.rawData);
}
}