Skip to content

Commit ebd8d06

Browse files
akaromlfbricon
authored andcommitted
Open client/server logs SxS (#1021)
Signed-off-by: Rome Li <rome.li@microsoft.com>
1 parent 2e4dbb9 commit ebd8d06

4 files changed

Lines changed: 32 additions & 10 deletions

File tree

package.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -398,6 +398,11 @@
398398
"title": "Open Java extension log file",
399399
"category": "Java"
400400
},
401+
{
402+
"command": "java.open.logs",
403+
"title": "Open all log files",
404+
"category": "Java"
405+
},
401406
{
402407
"command": "java.workspace.compile",
403408
"title": "Force Java compilation",

src/commands.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,11 @@ export namespace Commands {
7979
*/
8080
export const OPEN_CLIENT_LOG = 'java.open.clientLog';
8181

82+
/**
83+
* Open Java log files side by side
84+
*/
85+
export const OPEN_LOGS = 'java.open.logs';
86+
8287
/**
8388
* Open Java formatter settings
8489
*/

src/extension.ts

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,12 @@ class ClientErrorHandler implements ErrorHandler {
5757
if (diff <= 3 * 60 * 1000) {
5858
const message = `The ${this.name} server crashed 5 times in the last 3 minutes. The server will not be restarted.`;
5959
logger.error(message);
60-
window.showErrorMessage(message);
60+
const action = "Show logs";
61+
window.showErrorMessage(message, action).then(selection => {
62+
if (selection === action) {
63+
commands.executeCommand(Commands.OPEN_LOGS);
64+
}
65+
});
6166
return CloseAction.DoNotRestart;
6267
}
6368

@@ -376,9 +381,11 @@ export function activate(context: ExtensionContext): Promise<ExtensionAPI> {
376381

377382
context.subscriptions.push(commands.registerCommand(Commands.OPEN_OUTPUT, () => languageClient.outputChannel.show(ViewColumn.Three)));
378383

379-
context.subscriptions.push(commands.registerCommand(Commands.OPEN_SERVER_LOG, () => openServerLogFile(workspacePath)));
384+
context.subscriptions.push(commands.registerCommand(Commands.OPEN_SERVER_LOG, (column: ViewColumn) => openServerLogFile(workspacePath, column)));
380385

381-
context.subscriptions.push(commands.registerCommand(Commands.OPEN_CLIENT_LOG, () => openClientLogFile(clientLogFile)));
386+
context.subscriptions.push(commands.registerCommand(Commands.OPEN_CLIENT_LOG, (column: ViewColumn) => openClientLogFile(clientLogFile, column)));
387+
388+
context.subscriptions.push(commands.registerCommand(Commands.OPEN_LOGS, () => openLogs()));
382389

383390
const extensionPath = context.extensionPath;
384391
context.subscriptions.push(commands.registerCommand(Commands.OPEN_FORMATTER, async () => openFormatter(extensionPath)));
@@ -538,12 +545,12 @@ function deleteDirectory(dir) {
538545
}
539546
}
540547

541-
function openServerLogFile(workspacePath): Thenable<boolean> {
548+
function openServerLogFile(workspacePath, column: ViewColumn = ViewColumn.Active): Thenable<boolean> {
542549
const serverLogFile = path.join(workspacePath, '.metadata', '.log');
543-
return openLogFile(serverLogFile, 'Could not open Java Language Server log file');
550+
return openLogFile(serverLogFile, 'Could not open Java Language Server log file', column);
544551
}
545552

546-
function openClientLogFile(logFile: string): Thenable<boolean> {
553+
function openClientLogFile(logFile: string, column: ViewColumn = ViewColumn.Active): Thenable<boolean> {
547554
return new Promise((resolve) => {
548555
const filename = path.basename(logFile);
549556
const dirname = path.dirname(logFile);
@@ -555,12 +562,17 @@ function openClientLogFile(logFile: string): Thenable<boolean> {
555562
logFile = path.join(dirname, files[files.length - 1]);
556563
}
557564

558-
openLogFile(logFile, 'Could not open Java extension log file').then((result) => resolve(result));
565+
openLogFile(logFile, 'Could not open Java extension log file', column).then((result) => resolve(result));
559566
});
560567
});
561568
}
562569

563-
function openLogFile(logFile, openingFailureWarning: string): Thenable<boolean> {
570+
async function openLogs() {
571+
await commands.executeCommand(Commands.OPEN_CLIENT_LOG, ViewColumn.One);
572+
await commands.executeCommand(Commands.OPEN_SERVER_LOG, ViewColumn.Two);
573+
}
574+
575+
function openLogFile(logFile, openingFailureWarning: string, column: ViewColumn = ViewColumn.Active): Thenable<boolean> {
564576
if (!fs.existsSync(logFile)) {
565577
return window.showWarningMessage('No log file available').then(() => false);
566578
}
@@ -570,8 +582,7 @@ function openLogFile(logFile, openingFailureWarning: string): Thenable<boolean>
570582
if (!doc) {
571583
return false;
572584
}
573-
return window.showTextDocument(doc, window.activeTextEditor ?
574-
window.activeTextEditor.viewColumn : undefined)
585+
return window.showTextDocument(doc, column)
575586
.then(editor => !!editor);
576587
}, () => false)
577588
.then(didOpen => {

test/extension.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ suite('Java Language Extension', () => {
3535
Commands.EXECUTE_WORKSPACE_COMMAND,
3636
Commands.OPEN_SERVER_LOG,
3737
Commands.OPEN_CLIENT_LOG,
38+
Commands.OPEN_LOGS,
3839
Commands.COMPILE_WORKSPACE,
3940
Commands.OPEN_FORMATTER,
4041
Commands.CLEAN_WORKSPACE,

0 commit comments

Comments
 (0)