Skip to content

Commit 6cd52cf

Browse files
committed
Add 'Open Java extension log file' command
Signed-off-by: Fred Bricon <fbricon@gmail.com>
1 parent 1445ee1 commit 6cd52cf

4 files changed

Lines changed: 31 additions & 7 deletions

File tree

package.json

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -390,7 +390,12 @@
390390
},
391391
{
392392
"command": "java.open.serverLog",
393-
"title": "Open Java Language Server log file",
393+
"title": "Open Java language server log file",
394+
"category": "Java"
395+
},
396+
{
397+
"command": "java.open.clientLog",
398+
"title": "Open Java extension log file",
394399
"category": "Java"
395400
},
396401
{

src/commands.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,12 @@ export namespace Commands {
7474
*/
7575
export const OPEN_SERVER_LOG = 'java.open.serverLog';
7676

77+
/**
78+
* Open Java client Log file
79+
*/
80+
export const OPEN_CLIENT_LOG = 'java.open.clientLog';
81+
82+
7783
/**
7884
* Open Java formatter settings
7985
*/

src/extension.ts

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,16 @@ let lastStatus;
2626
let languageClient: LanguageClient;
2727
const jdtEventEmitter = new EventEmitter<Uri>();
2828
const cleanWorkspaceFileName = '.cleanWorkspace';
29+
let clientLogFile;
2930

3031
export function activate(context: ExtensionContext): Promise<ExtensionAPI> {
3132

3233
let storagePath = context.storagePath;
3334
if (!storagePath) {
3435
storagePath = getTempWorkspace();
3536
}
36-
37-
initializeLogFile(path.join(storagePath, 'client.log'));
37+
clientLogFile = path.join(storagePath, 'client.log');
38+
initializeLogFile(clientLogFile);
3839

3940
enableJavadocSymbols();
4041

@@ -331,6 +332,8 @@ export function activate(context: ExtensionContext): Promise<ExtensionAPI> {
331332

332333
context.subscriptions.push(commands.registerCommand(Commands.OPEN_SERVER_LOG, () => openServerLogFile(workspacePath)));
333334

335+
context.subscriptions.push(commands.registerCommand(Commands.OPEN_CLIENT_LOG, () => openClientLogFile(clientLogFile)));
336+
334337
const extensionPath = context.extensionPath;
335338
context.subscriptions.push(commands.registerCommand(Commands.OPEN_FORMATTER, async () => openFormatter(extensionPath)));
336339

@@ -491,11 +494,20 @@ function deleteDirectory(dir) {
491494

492495
function openServerLogFile(workspacePath): Thenable<boolean> {
493496
const serverLogFile = path.join(workspacePath, '.metadata', '.log');
494-
if (!fs.existsSync(serverLogFile)) {
495-
return window.showWarningMessage('Java Language Server has not started logging.').then(() => false);
497+
return openLogFile(serverLogFile, 'Could not open Java Language Server log file');
498+
}
499+
500+
function openClientLogFile(logFile): Thenable<boolean> {
501+
return openLogFile(logFile, 'Could not open Java extension log file');
502+
}
503+
504+
505+
function openLogFile(logFile, openingFailureWarning:string ): Thenable<boolean> {
506+
if (!fs.existsSync(logFile)) {
507+
return window.showWarningMessage('No log file available').then(() => false);
496508
}
497509

498-
return workspace.openTextDocument(serverLogFile)
510+
return workspace.openTextDocument(logFile)
499511
.then(doc => {
500512
if (!doc) {
501513
return false;
@@ -506,7 +518,7 @@ function openServerLogFile(workspacePath): Thenable<boolean> {
506518
}, () => false)
507519
.then(didOpen => {
508520
if (!didOpen) {
509-
window.showWarningMessage('Could not open Java Language Server log file');
521+
window.showWarningMessage(openingFailureWarning);
510522
}
511523
return didOpen;
512524
});

test/extension.test.ts

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

0 commit comments

Comments
 (0)