WIP lsp-manager effort 2
This commit is contained in:
parent
9e01628ffb
commit
f463970b6b
21
newton/fs.js
21
newton/fs.js
@ -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) => {
|
const openFiles = (startPath) => {
|
||||||
dialog.showOpenDialog(
|
dialog.showOpenDialog(
|
||||||
{
|
{
|
||||||
@ -171,6 +191,7 @@ const closeFile = (fpath) => {
|
|||||||
module.exports = {
|
module.exports = {
|
||||||
newtonFs: {
|
newtonFs: {
|
||||||
setWindow: setWindow,
|
setWindow: setWindow,
|
||||||
|
chooseFolder: chooseFolder,
|
||||||
openFiles: openFiles,
|
openFiles: openFiles,
|
||||||
saveFile: saveFile,
|
saveFile: saveFile,
|
||||||
saveFileAs: saveFileAs,
|
saveFileAs: saveFileAs,
|
||||||
|
@ -72,7 +72,8 @@ const loadHandlers = () => {
|
|||||||
ipcMain.handle('openFiles', (eve, startPath) => newton.fs.openFiles(startPath));
|
ipcMain.handle('openFiles', (eve, startPath) => newton.fs.openFiles(startPath));
|
||||||
ipcMain.handle('saveFile', (eve, path, content) => newton.fs.saveFile(path, content));
|
ipcMain.handle('saveFile', (eve, path, content) => newton.fs.saveFile(path, content));
|
||||||
ipcMain.handle('closeFile', (eve, path) => newton.fs.closeFile(path));
|
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 () => {
|
app.whenReady().then(async () => {
|
||||||
|
@ -19,6 +19,7 @@ contextBridge.exposeInMainWorld('fs', {
|
|||||||
openFiles: (startPath) => ipcRenderer.invoke("openFiles", startPath),
|
openFiles: (startPath) => ipcRenderer.invoke("openFiles", startPath),
|
||||||
saveFile: (path, content) => ipcRenderer.invoke("saveFile", path, content),
|
saveFile: (path, content) => ipcRenderer.invoke("saveFile", path, content),
|
||||||
saveFileAs: () => ipcRenderer.invoke("saveFileAs"),
|
saveFileAs: () => ipcRenderer.invoke("saveFileAs"),
|
||||||
|
chooseFolder: () => ipcRenderer.invoke("chooseFolder"),
|
||||||
closeFile: (path) => ipcRenderer.invoke("closeFile", path),
|
closeFile: (path) => ipcRenderer.invoke("closeFile", path),
|
||||||
getPathForFile: (file) => webUtils.getPathForFile(file),
|
getPathForFile: (file) => webUtils.getPathForFile(file),
|
||||||
onLoadFiles: (callback) => ipcRenderer.on('load-files', (_event, paths) => callback(paths)),
|
onLoadFiles: (callback) => ipcRenderer.on('load-files', (_event, paths) => callback(paths)),
|
||||||
|
@ -16,6 +16,7 @@ export class LspManagerService {
|
|||||||
|
|
||||||
lspConfigData!: {};
|
lspConfigData!: {};
|
||||||
languageProviders: {} = {};
|
languageProviders: {} = {};
|
||||||
|
workspaceFolder: string = "";
|
||||||
|
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
@ -40,7 +41,7 @@ export class LspManagerService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public registerEditor(editor: any): void {
|
public registerEditor(editor: any): void {
|
||||||
let modeParts = editor.getSession()["$modeId"].split("/");
|
let modeParts = editor.session.getMode()["$Id"].split("/");
|
||||||
let mode = modeParts[ modeParts.length - 1 ];
|
let mode = modeParts[ modeParts.length - 1 ];
|
||||||
|
|
||||||
if ( !this.languageProviders[mode] ) {
|
if ( !this.languageProviders[mode] ) {
|
||||||
@ -80,13 +81,17 @@ export class LspManagerService {
|
|||||||
return LanguageProvider.create(worker);
|
return LanguageProvider.create(worker);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected setSessionFilePath(session: any, mode: string = "", filePath: string = "") {
|
protected setSessionFilePath(session: any, filePath: string = "") {
|
||||||
if ( !session || !mode || !filePath || !this.languageProviders[mode] ) return;
|
if ( !session || !filePath ) return;
|
||||||
|
let mode = session.getMode()["$Id"];
|
||||||
|
if ( !this.languageProviders[mode] ) return;
|
||||||
this.languageProviders[mode].setSessionFilePath(session, filePath);
|
this.languageProviders[mode].setSessionFilePath(session, filePath);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected closeDocument(session: any, mode: string) {
|
protected closeDocument(session: any) {
|
||||||
if ( !session || !mode || !this.languageProviders[mode] ) return;
|
if ( !session ) return;
|
||||||
|
let mode = session.getMode()["$Id"];
|
||||||
|
if ( !this.languageProviders[mode] ) return;
|
||||||
this.languageProviders[mode].closeDocument(session);
|
this.languageProviders[mode].closeDocument(session);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -59,8 +59,8 @@ export class CodeViewComponent extends CodeViewBase {
|
|||||||
this.editor = ace.edit( this.editorElm.nativeElement );
|
this.editor = ace.edit( this.editorElm.nativeElement );
|
||||||
this.editor.setOptions( this.editorSettings.CONFIG );
|
this.editor.setOptions( this.editorSettings.CONFIG );
|
||||||
|
|
||||||
if (this.isDefault) {
|
|
||||||
this.editorsService.set(this.uuid, this);
|
this.editorsService.set(this.uuid, this);
|
||||||
|
if (this.isDefault) {
|
||||||
this.editorsService.setActiveEditor(this.uuid);
|
this.editorsService.setActiveEditor(this.uuid);
|
||||||
this.addActiveStyling();
|
this.addActiveStyling();
|
||||||
this.editor.focus();
|
this.editor.focus();
|
||||||
@ -128,7 +128,7 @@ export class CodeViewComponent extends CodeViewBase {
|
|||||||
|
|
||||||
this.editorsService.sendMessage(message);
|
this.editorsService.sendMessage(message);
|
||||||
this.searchReplaceService.sendMessage(message);
|
this.searchReplaceService.sendMessage(message);
|
||||||
this.editorsService.sendMessage(message);
|
this.lspManagerService.sendMessage(message);
|
||||||
|
|
||||||
message = new ServiceMessage();
|
message = new ServiceMessage();
|
||||||
message.action = "set-active-editor";
|
message.action = "set-active-editor";
|
||||||
@ -175,6 +175,12 @@ export class CodeViewComponent extends CodeViewBase {
|
|||||||
});
|
});
|
||||||
|
|
||||||
this.editor.on("changeSession", (session) => {
|
this.editor.on("changeSession", (session) => {
|
||||||
|
let message = new ServiceMessage();
|
||||||
|
message.action = "set-active-editor";
|
||||||
|
message.rawData = this.editor;
|
||||||
|
|
||||||
|
this.lspManagerService.sendMessage(message);
|
||||||
|
|
||||||
this.updateInfoBar();
|
this.updateInfoBar();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -2,3 +2,10 @@
|
|||||||
display: grid;
|
display: grid;
|
||||||
min-height: 25em;
|
min-height: 25em;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.clear-left-padding {
|
||||||
|
padding-left: 0px;
|
||||||
|
}
|
||||||
|
.clear-right-padding {
|
||||||
|
padding-right: 0px;
|
||||||
|
}
|
||||||
|
@ -2,24 +2,51 @@
|
|||||||
|
|
||||||
<div class="row mt-2 mb-3">
|
<div class="row mt-2 mb-3">
|
||||||
|
|
||||||
<div class="col">
|
<div class="col clear-right-padding">
|
||||||
<div class="input-group-sm">
|
<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>
|
</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="col col-auto">
|
||||||
<div class="input-group-sm">
|
<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>
|
||||||
|
|
||||||
</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="row">
|
||||||
|
|
||||||
<div class="col">
|
<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>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
@ -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 { Subject, takeUntil } from 'rxjs';
|
||||||
|
|
||||||
import { LspManagerService } from '../../common/services/editor/lsp-manager/lsp-manager.service';
|
import { LspManagerService } from '../../common/services/editor/lsp-manager/lsp-manager.service';
|
||||||
@ -24,13 +24,18 @@ import { ServiceMessage } from '../../common/types/service-message.type';
|
|||||||
})
|
})
|
||||||
export class LspManagerComponent {
|
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;
|
@HostBinding("class.hidden") isHidden: boolean = true;
|
||||||
@ViewChild('editorComponent') editorComponent!: CodeViewComponent;
|
@ViewChild('lspEditorComponent') lspEditorComponent!: CodeViewComponent;
|
||||||
lspTextEditor!: any;
|
@ViewChild('sessionEditorComponent') sessionEditorComponent!: CodeViewComponent;
|
||||||
private editor: any;
|
lspTextEditor: any;
|
||||||
|
innerEditor: any;
|
||||||
|
editor: any;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
@ -38,7 +43,8 @@ export class LspManagerComponent {
|
|||||||
|
|
||||||
|
|
||||||
private ngAfterViewInit(): void {
|
private ngAfterViewInit(): void {
|
||||||
this.lspTextEditor = this.editorComponent.editor;
|
this.lspTextEditor = this.lspEditorComponent.editor;
|
||||||
|
this.innerEditor = this.sessionEditorComponent.editor;
|
||||||
|
|
||||||
this.lspManagerService.loadLspConfigData().then((lspConfigData) => {
|
this.lspManagerService.loadLspConfigData().then((lspConfigData) => {
|
||||||
this.lspTextEditor.session.setMode("ace/mode/json");
|
this.lspTextEditor.session.setMode("ace/mode/json");
|
||||||
@ -65,24 +71,47 @@ export class LspManagerComponent {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public hideLspManager() {
|
public clearWorkspaceFolder() {
|
||||||
this.isHidden = true;
|
this.lspManagerService.workspaceFolder = "";
|
||||||
this.editor.focus();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public setWorkspaceFolder() {
|
||||||
|
window.fs.chooseFolder().then((folder: string) => {
|
||||||
|
if (!folder) return;
|
||||||
|
|
||||||
|
this.lspManagerService.workspaceFolder = folder;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public globalLspManagerKeyHandler(event: any) {
|
public globalLspManagerKeyHandler(event: any) {
|
||||||
if (event.ctrlKey && event.shiftKey && event.key === "l") {
|
if (event.ctrlKey && event.shiftKey && event.key === "l") {
|
||||||
this.hideLspManager();
|
this.hideLspManager();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public hideLspManager() {
|
||||||
|
this.isHidden = true;
|
||||||
|
this.editor.focus();
|
||||||
|
}
|
||||||
|
|
||||||
private toggleLspManager(message: ServiceMessage) {
|
private toggleLspManager(message: ServiceMessage) {
|
||||||
this.isHidden = !this.isHidden;
|
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) {
|
private setActiveEditor(message: ServiceMessage) {
|
||||||
this.editor = message.rawData;
|
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -61,7 +61,7 @@ export class MarkdownPreviewComponent {
|
|||||||
|
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
this.updatePreview();
|
this.updatePreview();
|
||||||
}, 200);
|
}, 10);
|
||||||
}
|
}
|
||||||
|
|
||||||
private setActiveEditor(message: ServiceMessage) {
|
private setActiveEditor(message: ServiceMessage) {
|
||||||
|
@ -29,6 +29,7 @@ declare global {
|
|||||||
openFiles: (arg0) => Promise<string>,
|
openFiles: (arg0) => Promise<string>,
|
||||||
saveFile: (arg0: any, arg1: any) => Promise<string>,
|
saveFile: (arg0: any, arg1: any) => Promise<string>,
|
||||||
saveFileAs: () => Promise<string>,
|
saveFileAs: () => Promise<string>,
|
||||||
|
chooseFolder: () => Promise<string>,
|
||||||
closeFile: (arg0: any) => Promise<string>,
|
closeFile: (arg0: any) => Promise<string>,
|
||||||
getPathForFile: any,
|
getPathForFile: any,
|
||||||
onLoadFiles: (arg0: any) => Promise<string>,
|
onLoadFiles: (arg0: any) => Promise<string>,
|
||||||
|
Loading…
Reference in New Issue
Block a user