Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ private List<String> buildCommand(String launcherJar, String configDir, String d
cmd.add("-Dlog.protocol=true");
cmd.add("-Dlog.level=ALL");
cmd.add("-noverify");
cmd.add("-Xmx512m");
cmd.add("-Xmx" + DirigibleConfig.JAVA_LSP_MAX_HEAP.getStringValue());
cmd.add("-jar");
cmd.add(launcherJar);
cmd.add("-configuration");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
<script type="text/javascript" src="/services/web/platform-core/ui/platform/layout-hub.js"></script>
<script type="text/javascript" src="/services/web/platform-core/ui/platform/status-bar-hub.js"></script>
<script type="text/javascript" src="/services/web/platform-core/ui/platform/theming-hub.js"></script>
<script type="text/javascript" src="/services/web/platform-core/ui/platform/dialog-hub.js"></script>
<script type="text/javascript" src="/services/web/service-workspace/workspace-hub.js"></script>
<script type="text/javascript" src="/webjars/monaco-editor/min/vs/loader.js"></script>
<script type="text/javascript" src="js/assignmentsParser.js"></script>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,74 @@ const themingHub = new ThemingHub();
const statusBarHub = new StatusBarHub();
const layoutHub = new LayoutHub();
const workspaceHub = new WorkspaceHub();
const dialogHub = new DialogHub();

// Member picker used by the Java LSP client for "Generate getters/setters/constructor/toString".
// Returns the labels the user kept, or null when the dialog is cancelled.
window.javaLspMemberPicker = (title, labels) => {
if (!Array.isArray(labels) || labels.length === 0) return Promise.resolve([]);
const form = {};
labels.forEach((label, i) => {
form[`m${i}`] = { label: label, controlType: 'checkbox', value: true };
});
return dialogHub.showFormDialog({
title: title,
form: form,
submitLabel: 'Generate',
cancelLabel: 'Cancel',
}).then((result) => {
if (!result) return null;
return labels.filter((_label, i) => result[`m${i}`]);
});
};

// Cross-file navigation target for the Java LSP client (Go to Definition / Find References to a file
// that isn't open). Opens the file in the IDE and reveals the line via the shared reveal topic; the
// re-post covers the case where the target editor iframe is still mounting.
window.javaLspOpenFile = (path, line, column) => {
layoutHub.openEditor({ path: path });
if (line && line > 0) {
const data = { filePath: path, line: line, column: column || 1 };
themingHub.postMessage({ topic: 'editor.reveal.line', data: data });
setTimeout(() => themingHub.postMessage({ topic: 'editor.reveal.line', data: data }), 1200);
}
};

// Persists a Java cross-file rename computed by the LSP client: writes the edited files (CSRF-guarded),
// performs any file rename the refactor implies (a public type renames its own .java file), switches the
// current tab when the file being edited is the one renamed, and asks other open editors to reload.
window.javaLspPersistRename = async ({ currentPath, currentContent, currentNewPath, writes, renames }) => {
const writeFile = (path, content, method) => fetch(`${WORKSPACE_API}${path}`, {
method: method,
body: content,
headers: { 'X-Requested-With': 'Fetch', 'X-CSRF-Token': csrfToken, 'Dirigible-Editor': 'Monaco', 'Content-Type': 'text/plain' },
});
const removeFile = (path) => fetch(`${WORKSPACE_API}${path}`, {
method: 'DELETE',
headers: { 'X-Requested-With': 'Fetch', 'X-CSRF-Token': csrfToken, 'Dirigible-Editor': 'Monaco' },
});

for (const write of (writes || [])) {
if (!write.path) continue;
await writeFile(write.path, write.content, 'PUT');
themingHub.postMessage({ topic: 'monaco.file.reload', data: { path: write.path } });
}
for (const rename of (renames || [])) {
if (!rename.oldPath || !rename.newPath) continue;
await writeFile(rename.newPath, rename.content, 'POST');
await removeFile(rename.oldPath);
workspaceHub.announceFileRenamed({ oldPath: rename.oldPath, newPath: rename.newPath });
}
if (currentNewPath && currentPath) {
await writeFile(currentNewPath, currentContent, 'POST');
await removeFile(currentPath);
workspaceHub.announceFileRenamed({ oldPath: currentPath, newPath: currentNewPath });
layoutHub.openEditor({ path: currentNewPath });
layoutHub.closeEditor({ path: currentPath });
} else if (currentContent != null && currentPath) {
await DirigibleEditor.fileIO.saveText(currentContent, currentPath);
}
};

const brandingInfo = getBrandingInfo();

Expand Down Expand Up @@ -656,7 +724,10 @@ class DirigibleEditor {
wordWrap: DirigibleEditor.getWordWrap(),
minimap: {
autohide: DirigibleEditor.isMinimapAutohideEnabled(),
}
},
// Show the code-action lightbulb whenever any action (incl. refactor assists like
// "Assign parameter to new field", Extract, ...) is available, not just on diagnostics.
lightbulb: { enabled: 'on' },
};
if (TypeScriptUtils.isTypeScriptFile(fileName)) {
// @ts-ignore
Expand Down Expand Up @@ -799,6 +870,26 @@ class DirigibleEditor {
},
});

// Reload this editor's content from disk when another file was changed by a cross-file Java
// rename. Skip dirty editors so unsaved work is never clobbered.
themingHub.addMessageListener({
topic: 'monaco.file.reload',
handler: async (msg) => {
const { path } = msg || {};
if (!path || path !== editorParameters.resourcePath || DirigibleEditor.dirty) return;
try {
const reloaded = await new FileIO().loadText(editorParameters.resourcePath, true);
DirigibleEditor.sourceBeingChangedProgramatically = true;
editor.getModel().setValue(reloaded.modified);
DirigibleEditor.lastSavedVersionId = editor.getModel().getAlternativeVersionId();
DirigibleEditor.dirty = false;
DirigibleEditor.sourceBeingChangedProgramatically = false;
} catch (e) {
console.error('[java-lsp] could not reload after rename', e);
}
},
});

// Restore breakpoint glyphs from the debug view's persisted state
themingHub.addMessageListener({
topic: 'java.debug.breakpoints',
Expand Down Expand Up @@ -832,6 +923,28 @@ class DirigibleEditor {
EditorActionsProvider._toggleAutoFormattingActionRegistration = editor.addAction(EditorActionsProvider.createToggleAutoFormattingAction());
}

if (this.fileType === 'java' && !this.readOnly) {
// Surface the JDT.LS source actions explicitly; rename (F2), references (Shift+F12),
// format, and quick-fix (Ctrl+.) are already in Monaco's context menu via the registered
// language providers.
editor.addAction({
id: 'java.organizeImports',
label: 'Java: Organize Imports',
keybindings: [monaco.KeyMod.Shift | monaco.KeyMod.Alt | monaco.KeyCode.KeyO],
contextMenuGroupId: '1_modification',
contextMenuOrder: 2.5,
run: (ed) => ed.trigger('java-lsp', 'editor.action.codeAction', { kind: 'source.organizeImports', apply: 'first' }),
});
editor.addAction({
id: 'java.sourceAction',
label: 'Java: Generate / Source Action...',
keybindings: [monaco.KeyMod.CtrlCmd | monaco.KeyMod.Alt | monaco.KeyCode.KeyS],
contextMenuGroupId: '1_modification',
contextMenuOrder: 2.6,
run: (ed) => ed.trigger('java-lsp', 'editor.action.codeAction', { kind: 'source', apply: 'never' }),
});
}

DirigibleEditor.computeDiff.onmessage = function (event) {
lineDecorations = editor.deltaDecorations(lineDecorations, event.data);
};
Expand Down
Loading
Loading