Skip to content

Commit 10ce3a7

Browse files
committed
vscode-extension: create one output channel for the language server and reuse it after restarting the language server
This prevents a bunch of separate ActionScript & MXML items in drop-down in the Output view
1 parent 64c208c commit 10ce3a7

1 file changed

Lines changed: 59 additions & 56 deletions

File tree

vscode-extension/src/main/ts/extension.ts

Lines changed: 59 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,10 @@ let pendingQuickCompileAndRun = false;
7979
let as3mxmlCodeIntelligenceReady = false;
8080
let actionScriptTaskProvider: ActionScriptTaskProvider;
8181
let animateTaskProvider: AnimateTaskProvider;
82+
let as3mxmlOutputChannel: vscode.OutputChannel | undefined;
8283

8384
function getValidatedEditorSDKConfiguration(
84-
javaExecutablePath: string | null
85+
javaExecutablePath: string | null,
8586
): string | null {
8687
if (!savedContext) {
8788
return null;
@@ -93,7 +94,7 @@ function getValidatedEditorSDKConfiguration(
9394
return validateEditorSDK(
9495
savedContext.extensionPath,
9596
javaExecutablePath,
96-
result
97+
result,
9798
);
9899
}
99100

@@ -233,7 +234,7 @@ function restartServer() {
233234
vscode.commands.executeCommand(
234235
"setContext",
235236
"as3mxml.codeIntelligenceReady",
236-
as3mxmlCodeIntelligenceReady
237+
as3mxmlCodeIntelligenceReady,
237238
);
238239
languageClient.stop().then(
239240
() => {
@@ -250,12 +251,15 @@ function restartServer() {
250251
vscode.commands.executeCommand("workbench.action.reloadWindow");
251252
}
252253
});
253-
}
254+
},
254255
);
255256
}
256257

257258
export function activate(context: vscode.ExtensionContext) {
258259
savedContext = context;
260+
as3mxmlOutputChannel = vscode.window.createOutputChannel(
261+
"ActionScript & MXML",
262+
);
259263
checkForProjectsToImport();
260264
const javaSettingsPath: string | undefined | null = vscode.workspace
261265
.getConfiguration("as3mxml")
@@ -266,10 +270,10 @@ export function activate(context: vscode.ExtensionContext) {
266270
editorSDKHome = getValidatedEditorSDKConfiguration(javaExecutablePath);
267271
frameworkSDKHome = getFrameworkSDKPathWithFallbacks();
268272
context.subscriptions.push(
269-
vscode.workspace.onDidChangeConfiguration(onDidChangeConfiguration)
273+
vscode.workspace.onDidChangeConfiguration(onDidChangeConfiguration),
270274
);
271275
context.subscriptions.push(
272-
vscode.window.onDidChangeVisibleTextEditors(onDidChangeVisibleTextEditors)
276+
vscode.window.onDidChangeVisibleTextEditors(onDidChangeVisibleTextEditors),
273277
);
274278
context.subscriptions.push(
275279
vscode.workspace.onDidSaveTextDocument((textDocument) => {
@@ -283,9 +287,9 @@ export function activate(context: vscode.ExtensionContext) {
283287
updateRoyaleTargetStatusBarItem();
284288
vscode.commands.executeCommand(
285289
"as3mxml.setRoyalePreferredTarget",
286-
getRoyalePreferredTarget(context)
290+
getRoyalePreferredTarget(context),
287291
);
288-
})
292+
}),
289293
);
290294

291295
context.subscriptions.push(
@@ -341,20 +345,20 @@ export function activate(context: vscode.ExtensionContext) {
341345
},
342346
},
343347
],
344-
})
348+
}),
345349
);
346350

347351
context.subscriptions.push(
348352
vscode.commands.registerCommand(
349353
"as3mxml.createNewProject",
350-
createNewProject
351-
)
354+
createNewProject,
355+
),
352356
);
353357
context.subscriptions.push(
354358
vscode.commands.registerCommand(
355359
"as3mxml.selectWorkspaceSDK",
356-
selectWorkspaceSDK
357-
)
360+
selectWorkspaceSDK,
361+
),
358362
);
359363
context.subscriptions.push(
360364
vscode.commands.registerCommand(
@@ -364,35 +368,35 @@ export function activate(context: vscode.ExtensionContext) {
364368
updateRoyaleTargetStatusBarItem();
365369
vscode.commands.executeCommand(
366370
"as3mxml.setRoyalePreferredTarget",
367-
getRoyalePreferredTarget(savedContext)
371+
getRoyalePreferredTarget(savedContext),
368372
);
369-
}
370-
)
373+
},
374+
),
371375
);
372376
context.subscriptions.push(
373-
vscode.commands.registerCommand("as3mxml.restartServer", restartServer)
377+
vscode.commands.registerCommand("as3mxml.restartServer", restartServer),
374378
);
375379
context.subscriptions.push(
376380
vscode.commands.registerCommand(
377381
"as3mxml.logCompilerShellOutput",
378-
logCompilerShellOutput
379-
)
382+
logCompilerShellOutput,
383+
),
380384
);
381385
context.subscriptions.push(
382386
vscode.commands.registerCommand(
383387
"as3mxml.saveSessionPassword",
384-
saveSessionPassword
385-
)
388+
saveSessionPassword,
389+
),
386390
);
387391
context.subscriptions.push(
388392
vscode.commands.registerCommand("as3mxml.importFlashBuilderProject", () => {
389393
pickProjectInWorkspace(true, false);
390-
})
394+
}),
391395
);
392396
context.subscriptions.push(
393397
vscode.commands.registerCommand("as3mxml.importFlashDevelopProject", () => {
394398
pickProjectInWorkspace(false, true);
395-
})
399+
}),
396400
);
397401
context.subscriptions.push(
398402
vscode.commands.registerCommand("as3mxml.quickCompileAndDebug", () => {
@@ -407,10 +411,9 @@ export function activate(context: vscode.ExtensionContext) {
407411
commands.some((command) => command === "as3mxml.getActiveProjectURIs")
408412
) {
409413
vscode.commands
410-
.executeCommand<string[] | undefined>(
411-
"as3mxml.getActiveProjectURIs",
412-
true
413-
)
414+
.executeCommand<
415+
string[] | undefined
416+
>("as3mxml.getActiveProjectURIs", true)
414417
.then((uris: string[] | undefined) => {
415418
if (!uris || uris.length === 0) {
416419
//no projects with asconfig.json files
@@ -425,9 +428,9 @@ export function activate(context: vscode.ExtensionContext) {
425428
fs.existsSync(
426429
path.resolve(
427430
workspaceFolder.uri.fsPath,
428-
FILE_NAME_ASCONFIG_JSON
429-
)
430-
)
431+
FILE_NAME_ASCONFIG_JSON,
432+
),
433+
),
431434
)
432435
) {
433436
//skip the message if there aren't any workspace folders
@@ -441,11 +444,11 @@ export function activate(context: vscode.ExtensionContext) {
441444
logCompilerShellOutput(
442445
QUICK_COMPILE_AND_DEBUG_INIT_MESSAGE,
443446
true,
444-
false
447+
false,
445448
);
446449
}
447450
});
448-
})
451+
}),
449452
);
450453
context.subscriptions.push(
451454
vscode.commands.registerCommand("as3mxml.quickCompileAndRun", () => {
@@ -460,10 +463,9 @@ export function activate(context: vscode.ExtensionContext) {
460463
commands.some((command) => command === "as3mxml.getActiveProjectURIs")
461464
) {
462465
vscode.commands
463-
.executeCommand<string[] | undefined>(
464-
"as3mxml.getActiveProjectURIs",
465-
true
466-
)
466+
.executeCommand<
467+
string[] | undefined
468+
>("as3mxml.getActiveProjectURIs", true)
467469
.then((uris: string[] | undefined) => {
468470
if (!uris || uris.length === 0) {
469471
//no projects with asconfig.json files
@@ -478,9 +480,9 @@ export function activate(context: vscode.ExtensionContext) {
478480
fs.existsSync(
479481
path.resolve(
480482
workspaceFolder.uri.fsPath,
481-
FILE_NAME_ASCONFIG_JSON
482-
)
483-
)
483+
FILE_NAME_ASCONFIG_JSON,
484+
),
485+
),
484486
)
485487
) {
486488
//skip the message if there aren't any workspace folders
@@ -494,20 +496,20 @@ export function activate(context: vscode.ExtensionContext) {
494496
logCompilerShellOutput(
495497
QUICK_COMPILE_AND_RUN_INIT_MESSAGE,
496498
true,
497-
false
499+
false,
498500
);
499501
return;
500502
}
501503
});
502-
})
504+
}),
503505
);
504506

505507
//don't activate these things unless we're in a workspace
506508
if (vscode.workspace.workspaceFolders !== undefined) {
507509
context.subscriptions.push(
508510
vscode.window.createTreeView("actionScriptSourcePaths", {
509511
treeDataProvider: new ActionScriptSourcePathDataProvider(),
510-
})
512+
}),
511513
);
512514
}
513515

@@ -520,22 +522,22 @@ export function activate(context: vscode.ExtensionContext) {
520522

521523
actionScriptTaskProvider = new ActionScriptTaskProvider(
522524
context,
523-
javaExecutablePath
525+
javaExecutablePath,
524526
);
525527
context.subscriptions.push(
526-
vscode.tasks.registerTaskProvider("actionscript", actionScriptTaskProvider)
528+
vscode.tasks.registerTaskProvider("actionscript", actionScriptTaskProvider),
527529
);
528530

529531
animateTaskProvider = new AnimateTaskProvider(context, javaExecutablePath);
530532
context.subscriptions.push(
531-
vscode.tasks.registerTaskProvider("animate", animateTaskProvider)
533+
vscode.tasks.registerTaskProvider("animate", animateTaskProvider),
532534
);
533535

534536
context.subscriptions.push(
535537
vscode.workspace.registerTextDocumentContentProvider(
536538
"swc",
537-
new SWCTextDocumentContentProvider()
538-
)
539+
new SWCTextDocumentContentProvider(),
540+
),
539541
);
540542

541543
startClient();
@@ -642,6 +644,7 @@ function startClient() {
642644
//this is just the default behavior, but we need to define both
643645
protocol2Code: (value) => vscode.Uri.parse(value),
644646
},
647+
outputChannel: as3mxmlOutputChannel,
645648
initializationOptions: {
646649
preferredRoyaleTarget: getRoyalePreferredTarget(savedContext),
647650
notifyActiveProject: true,
@@ -673,7 +676,7 @@ function startClient() {
673676
];
674677
if (frameworkSDKHome) {
675678
args.unshift(
676-
"-Droyalelib=" + path.join(frameworkSDKHome, "frameworks")
679+
"-Droyalelib=" + path.join(frameworkSDKHome, "frameworks"),
677680
);
678681
}
679682
if (process.platform === "darwin") {
@@ -708,7 +711,7 @@ function startClient() {
708711
vscode.commands.executeCommand(
709712
"setContext",
710713
"as3mxml.codeIntelligenceReady",
711-
as3mxmlCodeIntelligenceReady
714+
as3mxmlCodeIntelligenceReady,
712715
);
713716
isLanguageClientReady = false;
714717
// NOTE: isLanguageClientReady and as3mxmlCodeIntelligenceReady mean
@@ -723,19 +726,19 @@ function startClient() {
723726
"actionscript",
724727
"ActionScript & MXML Language Server",
725728
executable,
726-
clientOptions
729+
clientOptions,
727730
);
728731
savedLanguageClient.onNotification(
729732
"as3mxml/logCompilerShellOutput",
730733
(notification: string) => {
731734
logCompilerShellOutput(notification, false, false);
732-
}
735+
},
733736
);
734737
savedLanguageClient.onNotification(
735738
"as3mxml/clearCompilerShellOutput",
736739
() => {
737740
logCompilerShellOutput(null, false, true);
738-
}
741+
},
739742
);
740743
savedLanguageClient.onNotification(
741744
"as3mxml/setActionScriptActive",
@@ -744,11 +747,11 @@ function startClient() {
744747
vscode.commands.executeCommand(
745748
"setContext",
746749
"as3mxml.codeIntelligenceReady",
747-
as3mxmlCodeIntelligenceReady
750+
as3mxmlCodeIntelligenceReady,
748751
);
749752
refreshSDKStatusBarItemVisibility();
750753
refreshRoyaleTargetStatusBarItemVisibility();
751-
}
754+
},
752755
);
753756

754757
try {
@@ -763,7 +766,7 @@ function startClient() {
763766
isLanguageClientReady = true;
764767
vscode.commands.executeCommand(
765768
"as3mxml.setRoyalePreferredTarget",
766-
getRoyalePreferredTarget(savedContext)
769+
getRoyalePreferredTarget(savedContext),
767770
);
768771
if (pendingQuickCompileAndDebug) {
769772
vscode.commands.executeCommand("as3mxml.quickCompileAndDebug");
@@ -773,6 +776,6 @@ function startClient() {
773776
pendingQuickCompileAndDebug = false;
774777
pendingQuickCompileAndRun = false;
775778
});
776-
}
779+
},
777780
);
778781
}

0 commit comments

Comments
 (0)