Skip to content
Merged
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
6 changes: 3 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -597,4 +597,4 @@
}
]
}
}
}
29 changes: 27 additions & 2 deletions src/client/clientErrorHandler.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import * as fs from "fs-extra";
import { commands, ExtensionContext, window, workspace } from "vscode";
import { commands, ConfigurationTarget, ExtensionContext, window, workspace } from "vscode";
import { CloseAction, ErrorAction, ErrorHandler, Message } from "vscode-languageclient";
import { ClientCommandConstants } from "../commands/commandConstants";
import { HEAP_DUMP_LOCATION } from "../server/java/jvmArguments";
import { Telemetry } from "../telemetry";
import glob = require("glob");
import { totalmem } from "os";

/**
* An error handler that restarts the language server,
Expand Down Expand Up @@ -77,8 +78,9 @@ export async function cleanUpHeapDumps(context: ExtensionContext): Promise<void>
*/
async function showOOMMessage(): Promise<void> {
const DOCS = 'More info...';
const DOUBLE = 'Double allocated memory';
const result = await window.showErrorMessage('The XML Language Server crashed due to an Out Of Memory Error, and will not be restarted. ', //
DOCS);
DOUBLE, DOCS);
if (result === DOCS) {
Telemetry.sendTelemetry(Telemetry.OPEN_OOM_DOCS_EVT);
await commands.executeCommand(ClientCommandConstants.OPEN_DOCS,
Expand All @@ -87,10 +89,13 @@ async function showOOMMessage(): Promise<void> {
section: 'the-language-server-crashes-due-to-an-out-of-memory-error'
}
);
} else if (result === DOUBLE) {
doubleAllocatedMemory();
}
}

const HEAP_DUMP_FOLDER_EXTRACTOR = new RegExp(`${HEAP_DUMP_LOCATION}(?:'([^']+)'|"([^"]+)"|([^\\s]+))`);
const MAX_HEAP_SIZE_EXTRACTOR = new RegExp(`-Xmx([0-9]+)[kKmMgG]`);

/**
* Returns the heap dump folder defined in the user's preferences, or undefined if the user does not set the heap dump folder
Expand Down Expand Up @@ -122,4 +127,24 @@ function getXmxFromSettings(): string {
}
}
return 'DEFAULT';
}

/**
* Double the memory allocated to lemminx in the vmargs parameter
*/
async function doubleAllocatedMemory() {
let vmargs: string = workspace.getConfiguration('xml.server').get('vmargs', null);
const results = MAX_HEAP_SIZE_EXTRACTOR.exec(vmargs);
if (results && results[0]) {
const maxMemArg: string = results[0];
const maxMemValue: number = Number(results[1]);
const newMaxMemArg: string = maxMemArg.replace(maxMemValue.toString(), (maxMemValue * 2).toString());
vmargs = vmargs.replace(maxMemArg, newMaxMemArg);
await workspace.getConfiguration().update("xml.server.vmargs", vmargs, ConfigurationTarget.Global);
} else {
// by default, many JVM take 1/4 of the physical memory as -Xmx
// in the case it crashes, set -Xmx to half of total physical memory, in megabytes
vmargs = `-Xmx ${Math.trunc(totalmem()/2/1000000)}m ${vmargs}`;
await workspace.getConfiguration().update("xml.server.vmargs", vmargs, ConfigurationTarget.Global);
}
}
2 changes: 1 addition & 1 deletion src/client/xmlClient.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { TelemetryEvent } from '@redhat-developer/vscode-redhat-telemetry/lib';
import { commands, ExtensionContext, extensions, Position, TextDocument, TextEditor, Uri, window, workspace } from 'vscode';
import { commands, ConfigurationChangeEvent, ExtensionContext, extensions, Position, TextDocument, TextEditor, Uri, window, workspace } from 'vscode';
import { Command, ConfigurationParams, ConfigurationRequest, DidChangeConfigurationNotification, ExecuteCommandParams, LanguageClientOptions, MessageType, NotificationType, RequestType, RevealOutputChannelOn, TextDocumentPositionParams } from "vscode-languageclient";
import { Executable, LanguageClient } from 'vscode-languageclient/node';
import { XMLFileAssociation } from '../api/xmlExtensionApi';
Expand Down
3 changes: 3 additions & 0 deletions src/settings/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ export function subscribeJDKChangeConfiguration() {
if(hasPreferenceChanged(oldXMLConfig, newXMLConfig, "java.home")) { // checks "xml.java.home", not "java.home"
createReloadWindowMessage("`xml.java.home` path has changed. Please restart VS Code.");
}
if (params.affectsConfiguration("xml.server.vmargs")) {
createReloadWindowMessage("Arguments to the JVM have changed. Please reload VS Code to apply this change.");
}
// update to newest version of config
oldXMLConfig = newXMLConfig;
return;
Expand Down