Skip to content

Commit fe9be08

Browse files
authored
Add button to show Output if it's not visible for compile errors (#1543)
1 parent 9d292ea commit fe9be08

File tree

5 files changed

+37
-62
lines changed

5 files changed

+37
-62
lines changed

src/commands/compile.ts

+13-29
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import { DocumentContentProvider } from "../providers/DocumentContentProvider";
1414
import {
1515
base64EncodeContent,
1616
classNameRegex,
17+
compileErrorMsg,
1718
cspAppsForUri,
1819
CurrentBinaryFile,
1920
currentFile,
@@ -291,12 +292,7 @@ export async function compile(docs: CurrentFile[], flags?: string): Promise<any>
291292
return docs;
292293
})
293294
.catch(() => {
294-
if (!conf.get("suppressCompileErrorMessages")) {
295-
vscode.window.showErrorMessage(
296-
"Compilation failed. Check the 'ObjectScript' Output channel for details.",
297-
"Dismiss"
298-
);
299-
}
295+
compileErrorMsg(conf);
300296
// Always fetch server changes, even when compile failed or got cancelled
301297
return docs;
302298
})
@@ -483,9 +479,9 @@ export async function importFolder(uri: vscode.Uri, noCompile = false): Promise<
483479
}
484480

485481
export async function compileExplorerItems(nodes: NodeBase[]): Promise<any> {
486-
const { workspaceFolder, namespace } = nodes[0];
487-
const flags = config().compileFlags;
488-
const api = new AtelierAPI(workspaceFolder);
482+
const { workspaceFolderUri, namespace } = nodes[0];
483+
const conf = vscode.workspace.getConfiguration("objectscript", workspaceFolderUri);
484+
const api = new AtelierAPI(workspaceFolderUri);
489485
api.setNamespace(namespace);
490486
const docs = [];
491487
for (const node of nodes) {
@@ -512,23 +508,16 @@ export async function compileExplorerItems(nodes: NodeBase[]): Promise<any> {
512508
},
513509
(progress, token: vscode.CancellationToken) =>
514510
api
515-
.asyncCompile(docs, token, flags)
511+
.asyncCompile(docs, token, conf.get<string>("compileFlags"))
516512
.then((data) => {
517513
const info = nodes.length > 1 ? "" : `${nodes[0].fullName}: `;
518514
if (data.status && data.status.errors && data.status.errors.length) {
519515
throw new Error(`${info}Compile error`);
520-
} else if (!config("suppressCompileMessages")) {
516+
} else if (!conf.get("suppressCompileMessages")) {
521517
vscode.window.showInformationMessage(`${info}Compilation succeeded.`, "Dismiss");
522518
}
523519
})
524-
.catch(() => {
525-
if (!config("suppressCompileErrorMessages")) {
526-
vscode.window.showErrorMessage(
527-
"Compilation failed. Check the 'ObjectScript' Output channel for details.",
528-
"Dismiss"
529-
);
530-
}
531-
})
520+
.catch(() => compileErrorMsg(conf))
532521
);
533522
}
534523

@@ -585,6 +574,8 @@ async function importFileFromContent(
585574

586575
/** Prompt the user to compile documents after importing them */
587576
async function promptForCompile(imported: string[], api: AtelierAPI, refresh: boolean): Promise<void> {
577+
// This cast is safe because the only two callers intialize api with a workspace folder URI
578+
const conf = vscode.workspace.getConfiguration("objectscript", <vscode.Uri>api.wsOrFile);
588579
// Prompt the user for compilation
589580
if (imported.length) {
590581
return vscode.window
@@ -606,23 +597,16 @@ async function promptForCompile(imported: string[], api: AtelierAPI, refresh: bo
606597
},
607598
(progress, token: vscode.CancellationToken) =>
608599
api
609-
.asyncCompile(imported, token, config("compileFlags"))
600+
.asyncCompile(imported, token, conf.get<string>("compileFlags"))
610601
.then((data) => {
611602
const info = imported.length > 1 ? "" : `${imported[0]}: `;
612603
if (data.status && data.status.errors && data.status.errors.length) {
613604
throw new Error(`${info}Compile error`);
614-
} else if (!config("suppressCompileMessages")) {
605+
} else if (!conf.get("suppressCompileMessages")) {
615606
vscode.window.showInformationMessage(`${info}Compilation succeeded.`, "Dismiss");
616607
}
617608
})
618-
.catch(() => {
619-
if (!config("suppressCompileErrorMessages")) {
620-
vscode.window.showErrorMessage(
621-
"Compilation failed. Check the 'ObjectScript' Output channel for details.",
622-
"Dismiss"
623-
);
624-
}
625-
})
609+
.catch(() => compileErrorMsg(conf))
626610
.finally(() => {
627611
if (refresh) {
628612
// Refresh the files explorer to show the new files

src/commands/project.ts

+2-9
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { AtelierAPI } from "../api";
33
import { config, filesystemSchemas, projectsExplorerProvider, schemas } from "../extension";
44
import { compareConns } from "../providers/DocumentContentProvider";
55
import { isfsDocumentName } from "../providers/FileSystemProvider/FileSystemProvider";
6-
import { getWsServerConnection, handleError, notIsfs, notNull } from "../utils";
6+
import { compileErrorMsg, getWsServerConnection, handleError, notIsfs, notNull } from "../utils";
77
import { exportList } from "./export";
88
import { OtherStudioAction, StudioActions } from "./studio";
99
import { NodeBase, ProjectNode, ProjectRootNode, RoutineNode, CSPFileNode, ClassNode } from "../explorer/nodes";
@@ -996,14 +996,7 @@ export async function compileProjectContents(node: ProjectNode): Promise<any> {
996996
vscode.window.showInformationMessage("Compilation succeeded.", "Dismiss");
997997
}
998998
})
999-
.catch(() => {
1000-
if (!conf.get("suppressCompileErrorMessages")) {
1001-
vscode.window.showErrorMessage(
1002-
"Compilation failed. Check the 'ObjectScript' Output channel for details.",
1003-
"Dismiss"
1004-
);
1005-
}
1006-
})
999+
.catch(() => compileErrorMsg(conf))
10071000
);
10081001
}
10091002

src/extension.ts

+2-8
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ export const macLangId = "objectscript";
2424
export const intLangId = "objectscript-int";
2525
export const incLangId = "objectscript-macros";
2626
export const cspLangId = "objectscript-csp";
27+
export const outputLangId = "vscode-objectscript-output";
2728

2829
import * as url from "url";
2930
import path = require("path");
@@ -1032,10 +1033,6 @@ export async function activate(context: vscode.ExtensionContext): Promise<any> {
10321033
}
10331034
}
10341035
}),
1035-
1036-
vscode.commands.registerCommand("vscode-objectscript.output", () => {
1037-
outputChannel.show(true);
1038-
}),
10391036
vscode.commands.registerCommand("vscode-objectscript.compile", () => importAndCompile(false)),
10401037
vscode.commands.registerCommand("vscode-objectscript.touchBar.compile", () => importAndCompile(false)),
10411038
vscode.commands.registerCommand("vscode-objectscript.compileWithFlags", () => importAndCompile(true)),
@@ -1244,10 +1241,7 @@ export async function activate(context: vscode.ExtensionContext): Promise<any> {
12441241
),
12451242
vscode.commands.registerCommand("vscode-objectscript.compileOnly", () => compileOnly(false)),
12461243
vscode.commands.registerCommand("vscode-objectscript.compileOnlyWithFlags", () => compileOnly(true)),
1247-
vscode.languages.registerDocumentLinkProvider(
1248-
{ language: "vscode-objectscript-output" },
1249-
new DocumentLinkProvider()
1250-
),
1244+
vscode.languages.registerDocumentLinkProvider({ language: outputLangId }, new DocumentLinkProvider()),
12511245
vscode.commands.registerCommand("vscode-objectscript.editOthers", () => viewOthers(true)),
12521246
vscode.commands.registerCommand("vscode-objectscript.showClassDocumentationPreview", () =>
12531247
DocumaticPreviewPanel.create()

src/providers/FileSystemProvider/FileSystemProvider.ts

+2-15
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import {
1717
stringifyError,
1818
base64EncodeContent,
1919
openCustomEditors,
20+
compileErrorMsg,
2021
} from "../../utils";
2122
import { FILESYSTEM_READONLY_SCHEMA, FILESYSTEM_SCHEMA, intLangId, macLangId, workspaceState } from "../../extension";
2223
import { addIsfsFileToProject, modifyProject } from "../../commands/project";
@@ -803,21 +804,7 @@ export class FileSystemProvider implements vscode.FileSystemProvider {
803804
vscode.window.showInformationMessage(`${info}Compilation succeeded.`, "Dismiss");
804805
}
805806
})
806-
.catch(() => {
807-
if (!conf.get("suppressCompileErrorMessages")) {
808-
vscode.window
809-
.showErrorMessage(
810-
"Compilation failed. Check 'ObjectScript' Output channel for details.",
811-
"Show",
812-
"Dismiss"
813-
)
814-
.then((action) => {
815-
if (action === "Show") {
816-
outputChannel.show(true);
817-
}
818-
});
819-
}
820-
})
807+
.catch(() => compileErrorMsg(conf))
821808
);
822809
// Tell the client to update all "other" files affected by compilation
823810
const workspaceFolder = workspaceFolderOfUri(uri);

src/utils/index.ts

+18-1
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,13 @@ import {
1212
OBJECTSCRIPT_FILE_SCHEMA,
1313
documentContentProvider,
1414
filesystemSchemas,
15+
outputLangId,
1516
} from "../extension";
1617
import { getCategory } from "../commands/export";
1718
import { isCSP, isfsDocumentName } from "../providers/FileSystemProvider/FileSystemProvider";
1819
import { AtelierAPI } from "../api";
1920

20-
export const outputChannel = vscode.window.createOutputChannel("ObjectScript", "vscode-objectscript-output");
21+
export const outputChannel = vscode.window.createOutputChannel("ObjectScript", outputLangId);
2122

2223
/**
2324
* A map of all CSP web apps in a server-namespace.
@@ -968,6 +969,22 @@ export async function replaceFile(uri: vscode.Uri, content: string | string[] |
968969
if (!success) throw `Failed to create or replace contents of file '${uri.toString(true)}'`;
969970
}
970971

972+
/** Show the compilation failure error message if required. */
973+
export function compileErrorMsg(conf: vscode.WorkspaceConfiguration): void {
974+
if (conf.get("suppressCompileErrorMessages")) return;
975+
vscode.window
976+
.showErrorMessage(
977+
"Compilation failed. Check 'ObjectScript' Output channel for details.",
978+
!vscode.window.visibleTextEditors.some((e) => e.document.languageId == outputLangId) ? "Show" : undefined,
979+
"Dismiss"
980+
)
981+
.then((action) => {
982+
if (action == "Show") {
983+
outputChannel.show(true);
984+
}
985+
});
986+
}
987+
971988
class Semaphore {
972989
/** Queue of tasks waiting to acquire the semaphore */
973990
private _tasks: (() => void)[] = [];

0 commit comments

Comments
 (0)