From 822d7780085faba29f8f0627227d7be160e17f03 Mon Sep 17 00:00:00 2001 From: itdominator <1itdominator@gmail.com> Date: Sat, 26 Jul 2025 00:43:45 -0500 Subject: [PATCH] WIP context menu added; upgraded ace-linters; integrated auto session register --- newton/fs.js | 1 - package.json | 4 +- public/lsp-servers-config.json | 16 ++++-- src/app/common/constants/button.map.ts | 5 ++ .../editor/lsp-manager/lsp-manager.service.ts | 26 +++++---- src/app/common/services/files.service.ts | 4 ++ src/app/editor/code-view/view.base.ts | 3 ++ src/app/editor/code-view/view.component.css | 22 +++++++- src/app/editor/code-view/view.component.html | 13 +++++ src/app/editor/code-view/view.component.ts | 54 +++++++++++++++++-- .../lsp-manager/lsp-manager.component.ts | 14 +---- src/app/editor/tabs/tabs.component.css | 1 + src/assets/css/overrides.css | 4 ++ 13 files changed, 134 insertions(+), 33 deletions(-) create mode 100644 src/app/common/constants/button.map.ts diff --git a/newton/fs.js b/newton/fs.js index ab4b043..e1f879d 100644 --- a/newton/fs.js +++ b/newton/fs.js @@ -114,7 +114,6 @@ const chooseFolder = () => { console.debug("Canceled folder selection..."); return ""; } - console.log(response) return response.filePaths[0]; }); diff --git a/package.json b/package.json index f978862..2d06c64 100644 --- a/package.json +++ b/package.json @@ -54,7 +54,7 @@ "ace-builds": "1.43.0", "ace-diff": "3.0.3", "ace-layout": "1.5.0", - "ace-linters": "1.7.1", + "ace-linters": "1.8.1", "bootstrap": "5.3.6", "bootstrap-icons": "1.12.1", "chokidar": "4.0.3", @@ -106,4 +106,4 @@ "tslib": "2.3.0", "typescript": "5.7.2" } -} \ No newline at end of file +} diff --git a/public/lsp-servers-config.json b/public/lsp-servers-config.json index 7b2df8e..727fc4e 100644 --- a/public/lsp-servers-config.json +++ b/public/lsp-servers-config.json @@ -24,6 +24,7 @@ }, "settings": { "java": { + "home": "/usr/lib/jvm/java-17-openjdk", "autobuild": { "enabled": false }, @@ -44,8 +45,8 @@ }, "runtimes": [ { - "name": "JavaSE-17", - "path": "/usr/lib/jvm/default-runtime", + "name": "JavaJDK-17", + "path": "/usr/lib/jvm/java-17-openjdk", "javadoc": "https://docs.oracle.com/en/java/javase/17/docs/api/", "default": true } @@ -59,7 +60,6 @@ "{user.home}/.config/jdtls/m2/repository/**/*-javadoc.jar", "lib/**/*-javadoc.jar" ], - "silentNotification": true, "project": { "encoding": "ignore", "outputPath": "bin", @@ -133,6 +133,7 @@ "downloadSources": true, "updateSnapshots": true }, + "silentNotification": false, "signatureHelp": { "enabled": true, "description": { @@ -141,6 +142,15 @@ }, "implementationsCodeLens": { "enabled": true + }, + "referencesCodeLens": { + "enabled": true + }, + "progressReports": { + "enabled": false + }, + "saveActions": { + "organizeImports": true } } } diff --git a/src/app/common/constants/button.map.ts b/src/app/common/constants/button.map.ts new file mode 100644 index 0000000..f490bd8 --- /dev/null +++ b/src/app/common/constants/button.map.ts @@ -0,0 +1,5 @@ +export abstract class ButtonMap { + static LEFT: number = 0; + static MIDDLE: number = 1; + static RIGHT: number = 2; +} \ No newline at end of file diff --git a/src/app/common/services/editor/lsp-manager/lsp-manager.service.ts b/src/app/common/services/editor/lsp-manager/lsp-manager.service.ts index ec962c1..69d5730 100644 --- a/src/app/common/services/editor/lsp-manager/lsp-manager.service.ts +++ b/src/app/common/services/editor/lsp-manager/lsp-manager.service.ts @@ -35,10 +35,7 @@ export class LspManagerService { this.languageProviders[mode]?.registerEditor( editor, - { - filePath: editor.session["id"], - joinWorkspaceURI: true - } + editor.session.lspConfig ); } @@ -97,8 +94,13 @@ export class LspManagerService { return; } - this.languageProviders[mode] = AceLanguageClient.for(servers); - // this.languageProviders[mode].requireFilePath = true; + this.languageProviders[mode] = AceLanguageClient.for( + servers, + { + manualSessionControl: true + } + ); + this.languageProviders[mode].changeWorkspaceFolder(this.workspaceFolder); return this.languageProviders[mode]; } @@ -108,11 +110,15 @@ export class LspManagerService { return LanguageProvider.create(worker); } - public setSessionFilePath(session: any, filePath: string = "") { - if ( !session || !filePath ) return; - let mode = this.getMode(session); + public registerSession(editor: any) { + let mode = this.getMode(editor.session); if ( !this.languageProviders[mode] ) return; - this.languageProviders[mode].setSessionFilePath(session, filePath); + + this.languageProviders[mode].registerSession( + editor.session, + editor, + editor.session.lspConfig + ); } public getMode(session: any): string { diff --git a/src/app/common/services/files.service.ts b/src/app/common/services/files.service.ts index 0ab0071..51dc13b 100644 --- a/src/app/common/services/files.service.ts +++ b/src/app/common/services/files.service.ts @@ -111,6 +111,10 @@ export class FilesService { file.session["id"] = path; file.session.setUndoManager( new UndoManager() ); file.session.setMode( getModeForPath( file.path ).mode ); + file.session["lspConfig"] = { + filePath: path, + joinWorkspaceURI: false + } this.files.set(file.path, file); } catch (error) { diff --git a/src/app/editor/code-view/view.base.ts b/src/app/editor/code-view/view.base.ts index 4b41fc6..3ff14bf 100644 --- a/src/app/editor/code-view/view.base.ts +++ b/src/app/editor/code-view/view.base.ts @@ -46,6 +46,9 @@ export class CodeViewBase { public debounceId: number = -1; public debounceWait: number = 800; + @ViewChild('contextMenu') contextMenu!: ElementRef; + public showContextMenu: boolean = false; + constructor() { } diff --git a/src/app/editor/code-view/view.component.css b/src/app/editor/code-view/view.component.css index 4349a02..daa9d03 100644 --- a/src/app/editor/code-view/view.component.css +++ b/src/app/editor/code-view/view.component.css @@ -25,4 +25,24 @@ border-style: solid; border-width: thin; border-color: rgba(124, 124, 124, 1); -} \ No newline at end of file +} + + +.contextMenu { + display: inline-table; + z-index: 500; + position: absolute; + min-width: 2em; + padding: 0.2em; + top: 0em; + right: 0em; +} + +.contextMenu li:hover { + background-color: rgba(0, 124, 0, 0.64); + cursor: pointer; +} + +.contextMenu li { + padding: 0em 0.2em; +} diff --git a/src/app/editor/code-view/view.component.html b/src/app/editor/code-view/view.component.html index a086340..563bcb4 100644 --- a/src/app/editor/code-view/view.component.html +++ b/src/app/editor/code-view/view.component.html @@ -1,2 +1,15 @@
+ + \ No newline at end of file diff --git a/src/app/editor/code-view/view.component.ts b/src/app/editor/code-view/view.component.ts index 57d8720..631932e 100644 --- a/src/app/editor/code-view/view.component.ts +++ b/src/app/editor/code-view/view.component.ts @@ -25,6 +25,7 @@ import { CodeViewBase } from './view.base'; import { NewtonFile } from '../../common/types/file.type'; import { EditorType } from '../../common/types/editor.type'; import { ServiceMessage } from '../../common/types/service-message.type'; +import { ButtonMap } from '../../common/constants/button.map'; @@ -159,10 +160,30 @@ export class CodeViewComponent extends CodeViewBase { this.updateInfoBar(); }); - this.editor.on("click", () => { + this.editor.on("click", (event) => { this.updateInfoBar(); }); + this.editor.addEventListener("mousedown", (event) => { + if (ButtonMap.LEFT === event.domEvent.button) { + this.showContextMenu = false; + } else if (ButtonMap.RIGHT === event.domEvent.button) { + let menuElm = this.contextMenu.nativeElement; + let pageX = event.domEvent.pageX; + let pageY = event.domEvent.pageY; + + const origin = { + left: pageX + 5, + top: pageY - 5 + }; + + menuElm.style.left = `${origin.left}px`; + menuElm.style.top = `${origin.top}px`; + this.showContextMenu = true; + + } + }); + this.editor.on("input", () => { this.updateInfoBar(); }); @@ -219,6 +240,28 @@ export class CodeViewComponent extends CodeViewBase { } + public prettyJSON() { + let data = JSON.parse(this.editor.session.getValue()); + this.editor.session.setValue( + JSON.stringify(data, null, 4) + ); + } + + public hideContextMenu() { + this.showContextMenu = false; + } + + public contextMenuClicked(event: any) { + this.showContextMenu = false; + + const command = event.target.getAttribute("command"); + const args = event.target.getAttribute("args"); + + if (!command) return; + + this[command]( (args) ? args : null ); + } + public assignSession(file: NewtonFile) { if (!file) return; @@ -229,8 +272,13 @@ export class CodeViewComponent extends CodeViewBase { public cloneSession(file: NewtonFile) { if (!file) return; - this.activeFile = file; - let session = this.aceApi.createEditSession(file.session.getValue()); + this.activeFile = file; + let session = this.aceApi.createEditSession(file.session.getValue()); + session["$config"] = { + "lsp": { + "filePath": file.path + } + } session.setMode( file.session.getMode()["$id"] ); this.editor.setSession(session); diff --git a/src/app/editor/lsp-manager/lsp-manager.component.ts b/src/app/editor/lsp-manager/lsp-manager.component.ts index 1c8404a..d0d0ada 100644 --- a/src/app/editor/lsp-manager/lsp-manager.component.ts +++ b/src/app/editor/lsp-manager/lsp-manager.component.ts @@ -101,12 +101,6 @@ export class LspManagerComponent { public registerEditorToLanguageClient() { this.lspManagerService.registerEditorToLSPClient(this.editor); -/* - this.lspManagerService.setSessionFilePath( - this.editor.session, - this.activeFile.path - ); -*/ } @@ -148,13 +142,7 @@ export class LspManagerComponent { this.editor.setSession(message.rawData.editor.getSession()) this.activeFile = message.rawData.activeFile; -/* - this.lspManagerService.setSessionFilePath( - this.editor.session, - this.activeFile.path - ); -*/ - + this.lspManagerService.registerSession(this.editor); } private closeFile(message: ServiceMessage) { diff --git a/src/app/editor/tabs/tabs.component.css b/src/app/editor/tabs/tabs.component.css index 99bd6d0..f4735ec 100644 --- a/src/app/editor/tabs/tabs.component.css +++ b/src/app/editor/tabs/tabs.component.css @@ -42,6 +42,7 @@ margin-left: 2em; margin-right: 2em; font-size: 4em; + align-self: center; } .close-button { diff --git a/src/assets/css/overrides.css b/src/assets/css/overrides.css index 6060860..0ed615a 100644 --- a/src/assets/css/overrides.css +++ b/src/assets/css/overrides.css @@ -10,6 +10,10 @@ body { overflow: hidden; } +ul, li { + list-style: none; +} + /* IDs */