WIP lsp-manager effort 2

This commit is contained in:
itdominator 2025-07-06 21:40:24 -05:00
parent 9e01628ffb
commit f463970b6b
11 changed files with 124 additions and 26 deletions

View File

@ -100,6 +100,26 @@ const saveFileAs = () => {
});
}
const chooseFolder = () => {
return dialog.showOpenDialog(
{
title: "Choose Folder:",
defaultPath: HOME_DIR,
properties: [
'openDirectory'
]
}
).then((response) => {
if (response.canceled) {
console.debug("Canceled folder selection...");
return "";
}
console.log(response)
return response.filePaths[0];
});
}
const openFiles = (startPath) => {
dialog.showOpenDialog(
{
@ -171,6 +191,7 @@ const closeFile = (fpath) => {
module.exports = {
newtonFs: {
setWindow: setWindow,
chooseFolder: chooseFolder,
openFiles: openFiles,
saveFile: saveFile,
saveFileAs: saveFileAs,

View File

@ -72,7 +72,8 @@ const loadHandlers = () => {
ipcMain.handle('openFiles', (eve, startPath) => newton.fs.openFiles(startPath));
ipcMain.handle('saveFile', (eve, path, content) => newton.fs.saveFile(path, content));
ipcMain.handle('closeFile', (eve, path) => newton.fs.closeFile(path));
ipcMain.handle('saveFileAs', (eve, content) => newton.fs.saveFileAs(content));
ipcMain.handle('saveFileAs', (eve) => newton.fs.saveFileAs());
ipcMain.handle('chooseFolder', (eve) => newton.fs.chooseFolder());
}
app.whenReady().then(async () => {

View File

@ -19,6 +19,7 @@ contextBridge.exposeInMainWorld('fs', {
openFiles: (startPath) => ipcRenderer.invoke("openFiles", startPath),
saveFile: (path, content) => ipcRenderer.invoke("saveFile", path, content),
saveFileAs: () => ipcRenderer.invoke("saveFileAs"),
chooseFolder: () => ipcRenderer.invoke("chooseFolder"),
closeFile: (path) => ipcRenderer.invoke("closeFile", path),
getPathForFile: (file) => webUtils.getPathForFile(file),
onLoadFiles: (callback) => ipcRenderer.on('load-files', (_event, paths) => callback(paths)),

View File

@ -15,7 +15,8 @@ export class LspManagerService {
private messageSubject: ReplaySubject<ServiceMessage> = new ReplaySubject<ServiceMessage>(1);
lspConfigData!: {};
languageProviders: {} = {};
languageProviders: {} = {};
workspaceFolder: string = "";
constructor() {
@ -40,7 +41,7 @@ export class LspManagerService {
}
public registerEditor(editor: any): void {
let modeParts = editor.getSession()["$modeId"].split("/");
let modeParts = editor.session.getMode()["$Id"].split("/");
let mode = modeParts[ modeParts.length - 1 ];
if ( !this.languageProviders[mode] ) {
@ -80,13 +81,17 @@ export class LspManagerService {
return LanguageProvider.create(worker);
}
protected setSessionFilePath(session: any, mode: string = "", filePath: string = "") {
if ( !session || !mode || !filePath || !this.languageProviders[mode] ) return;
protected setSessionFilePath(session: any, filePath: string = "") {
if ( !session || !filePath ) return;
let mode = session.getMode()["$Id"];
if ( !this.languageProviders[mode] ) return;
this.languageProviders[mode].setSessionFilePath(session, filePath);
}
protected closeDocument(session: any, mode: string) {
if ( !session || !mode || !this.languageProviders[mode] ) return;
protected closeDocument(session: any) {
if ( !session ) return;
let mode = session.getMode()["$Id"];
if ( !this.languageProviders[mode] ) return;
this.languageProviders[mode].closeDocument(session);
}

View File

@ -59,8 +59,8 @@ export class CodeViewComponent extends CodeViewBase {
this.editor = ace.edit( this.editorElm.nativeElement );
this.editor.setOptions( this.editorSettings.CONFIG );
this.editorsService.set(this.uuid, this);
if (this.isDefault) {
this.editorsService.set(this.uuid, this);
this.editorsService.setActiveEditor(this.uuid);
this.addActiveStyling();
this.editor.focus();
@ -128,7 +128,7 @@ export class CodeViewComponent extends CodeViewBase {
this.editorsService.sendMessage(message);
this.searchReplaceService.sendMessage(message);
this.editorsService.sendMessage(message);
this.lspManagerService.sendMessage(message);
message = new ServiceMessage();
message.action = "set-active-editor";
@ -175,6 +175,12 @@ export class CodeViewComponent extends CodeViewBase {
});
this.editor.on("changeSession", (session) => {
let message = new ServiceMessage();
message.action = "set-active-editor";
message.rawData = this.editor;
this.lspManagerService.sendMessage(message);
this.updateInfoBar();
});
}

View File

@ -2,3 +2,10 @@
display: grid;
min-height: 25em;
}
.clear-left-padding {
padding-left: 0px;
}
.clear-right-padding {
padding-right: 0px;
}

View File

@ -2,24 +2,51 @@
<div class="row mt-2 mb-3">
<div class="col">
<div class="col clear-right-padding">
<div class="input-group-sm">
<input class="form-control" placeholder="Project Path..." />
<label class="form-control" [innerText]="lspManagerService.workspaceFolder || 'Project Path...'">
</label>
</div>
</div>
<div class="col col-auto clear-left-padding">
<button class="btn btn-sm btn-dark" (click)="clearWorkspaceFolder()">x</button>
</div>
<div class="col col-auto">
<div class="input-group-sm">
<button class="btn btn-sm btn-dark">Choose Directory</button>
<button class="btn btn-sm btn-dark" (click)="setWorkspaceFolder()">Workspace Folder</button>
<button class="btn btn-sm btn-danger ms-5" (click)="hideLspManager()">X</button>
</div>
</div>
</div>
<div class="row mt-2 md-2">
<div class="col">
LSP Configs:
</div>
</div>
<div class="row">
<div class="col">
<code-view #lspEditorComponent [mode]="'standalone'" class="lsp-config-text"></code-view>
</div>
</div>
<div class="row mt-2 md-2">
<div class="col">
Target Editor: <label [innerText]="editor?.id || 'Editor...'"></label>
</div>
<div class="col">
Active Editor Session:
</div>
</div>
<div class="row">
<div class="col">
<code-view #editorComponent [mode]="'standalone'" class="lsp-config-text"></code-view>
<code-view #sessionEditorComponent [mode]="'read-only'" class="lsp-config-text"></code-view>
</div>
</div>

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,19 @@ 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;
constructor() {
@ -38,7 +43,8 @@ export class LspManagerComponent {
private ngAfterViewInit(): void {
this.lspTextEditor = this.editorComponent.editor;
this.lspTextEditor = this.lspEditorComponent.editor;
this.innerEditor = this.sessionEditorComponent.editor;
this.lspManagerService.loadLspConfigData().then((lspConfigData) => {
this.lspTextEditor.session.setMode("ace/mode/json");
@ -65,24 +71,47 @@ export class LspManagerComponent {
});
}
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 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.session);
}, 10);
}
private setActiveEditor(message: ServiceMessage) {
this.editor = message.rawData;
// 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);
}
}

View File

@ -61,7 +61,7 @@ export class MarkdownPreviewComponent {
setTimeout(() => {
this.updatePreview();
}, 200);
}, 10);
}
private setActiveEditor(message: ServiceMessage) {

View File

@ -29,6 +29,7 @@ declare global {
openFiles: (arg0) => Promise<string>,
saveFile: (arg0: any, arg1: any) => Promise<string>,
saveFileAs: () => Promise<string>,
chooseFolder: () => Promise<string>,
closeFile: (arg0: any) => Promise<string>,
getPathForFile: any,
onLoadFiles: (arg0: any) => Promise<string>,