Skip to content

Add button to show Output channel if it's not visible for compile errors #1543

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 1, 2025
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
42 changes: 13 additions & 29 deletions src/commands/compile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { DocumentContentProvider } from "../providers/DocumentContentProvider";
import {
base64EncodeContent,
classNameRegex,
compileErrorMsg,
cspAppsForUri,
CurrentBinaryFile,
currentFile,
Expand Down Expand Up @@ -291,12 +292,7 @@ export async function compile(docs: CurrentFile[], flags?: string): Promise<any>
return docs;
})
.catch(() => {
if (!conf.get("suppressCompileErrorMessages")) {
vscode.window.showErrorMessage(
"Compilation failed. Check the 'ObjectScript' Output channel for details.",
"Dismiss"
);
}
compileErrorMsg(conf);
// Always fetch server changes, even when compile failed or got cancelled
return docs;
})
Expand Down Expand Up @@ -483,9 +479,9 @@ export async function importFolder(uri: vscode.Uri, noCompile = false): Promise<
}

export async function compileExplorerItems(nodes: NodeBase[]): Promise<any> {
const { workspaceFolder, namespace } = nodes[0];
const flags = config().compileFlags;
const api = new AtelierAPI(workspaceFolder);
const { workspaceFolderUri, namespace } = nodes[0];
const conf = vscode.workspace.getConfiguration("objectscript", workspaceFolderUri);
const api = new AtelierAPI(workspaceFolderUri);
api.setNamespace(namespace);
const docs = [];
for (const node of nodes) {
Expand All @@ -512,23 +508,16 @@ export async function compileExplorerItems(nodes: NodeBase[]): Promise<any> {
},
(progress, token: vscode.CancellationToken) =>
api
.asyncCompile(docs, token, flags)
.asyncCompile(docs, token, conf.get<string>("compileFlags"))
.then((data) => {
const info = nodes.length > 1 ? "" : `${nodes[0].fullName}: `;
if (data.status && data.status.errors && data.status.errors.length) {
throw new Error(`${info}Compile error`);
} else if (!config("suppressCompileMessages")) {
} else if (!conf.get("suppressCompileMessages")) {
vscode.window.showInformationMessage(`${info}Compilation succeeded.`, "Dismiss");
}
})
.catch(() => {
if (!config("suppressCompileErrorMessages")) {
vscode.window.showErrorMessage(
"Compilation failed. Check the 'ObjectScript' Output channel for details.",
"Dismiss"
);
}
})
.catch(() => compileErrorMsg(conf))
);
}

Expand Down Expand Up @@ -585,6 +574,8 @@ async function importFileFromContent(

/** Prompt the user to compile documents after importing them */
async function promptForCompile(imported: string[], api: AtelierAPI, refresh: boolean): Promise<void> {
// This cast is safe because the only two callers intialize api with a workspace folder URI
const conf = vscode.workspace.getConfiguration("objectscript", <vscode.Uri>api.wsOrFile);
// Prompt the user for compilation
if (imported.length) {
return vscode.window
Expand All @@ -606,23 +597,16 @@ async function promptForCompile(imported: string[], api: AtelierAPI, refresh: bo
},
(progress, token: vscode.CancellationToken) =>
api
.asyncCompile(imported, token, config("compileFlags"))
.asyncCompile(imported, token, conf.get<string>("compileFlags"))
.then((data) => {
const info = imported.length > 1 ? "" : `${imported[0]}: `;
if (data.status && data.status.errors && data.status.errors.length) {
throw new Error(`${info}Compile error`);
} else if (!config("suppressCompileMessages")) {
} else if (!conf.get("suppressCompileMessages")) {
vscode.window.showInformationMessage(`${info}Compilation succeeded.`, "Dismiss");
}
})
.catch(() => {
if (!config("suppressCompileErrorMessages")) {
vscode.window.showErrorMessage(
"Compilation failed. Check the 'ObjectScript' Output channel for details.",
"Dismiss"
);
}
})
.catch(() => compileErrorMsg(conf))
.finally(() => {
if (refresh) {
// Refresh the files explorer to show the new files
Expand Down
11 changes: 2 additions & 9 deletions src/commands/project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { AtelierAPI } from "../api";
import { config, filesystemSchemas, projectsExplorerProvider, schemas } from "../extension";
import { compareConns } from "../providers/DocumentContentProvider";
import { isfsDocumentName } from "../providers/FileSystemProvider/FileSystemProvider";
import { getWsServerConnection, handleError, notIsfs, notNull } from "../utils";
import { compileErrorMsg, getWsServerConnection, handleError, notIsfs, notNull } from "../utils";
import { exportList } from "./export";
import { OtherStudioAction, StudioActions } from "./studio";
import { NodeBase, ProjectNode, ProjectRootNode, RoutineNode, CSPFileNode, ClassNode } from "../explorer/nodes";
Expand Down Expand Up @@ -996,14 +996,7 @@ export async function compileProjectContents(node: ProjectNode): Promise<any> {
vscode.window.showInformationMessage("Compilation succeeded.", "Dismiss");
}
})
.catch(() => {
if (!conf.get("suppressCompileErrorMessages")) {
vscode.window.showErrorMessage(
"Compilation failed. Check the 'ObjectScript' Output channel for details.",
"Dismiss"
);
}
})
.catch(() => compileErrorMsg(conf))
);
}

Expand Down
10 changes: 2 additions & 8 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export const macLangId = "objectscript";
export const intLangId = "objectscript-int";
export const incLangId = "objectscript-macros";
export const cspLangId = "objectscript-csp";
export const outputLangId = "vscode-objectscript-output";

import * as url from "url";
import path = require("path");
Expand Down Expand Up @@ -1032,10 +1033,6 @@ export async function activate(context: vscode.ExtensionContext): Promise<any> {
}
}
}),

vscode.commands.registerCommand("vscode-objectscript.output", () => {
outputChannel.show(true);
}),
vscode.commands.registerCommand("vscode-objectscript.compile", () => importAndCompile(false)),
vscode.commands.registerCommand("vscode-objectscript.touchBar.compile", () => importAndCompile(false)),
vscode.commands.registerCommand("vscode-objectscript.compileWithFlags", () => importAndCompile(true)),
Expand Down Expand Up @@ -1244,10 +1241,7 @@ export async function activate(context: vscode.ExtensionContext): Promise<any> {
),
vscode.commands.registerCommand("vscode-objectscript.compileOnly", () => compileOnly(false)),
vscode.commands.registerCommand("vscode-objectscript.compileOnlyWithFlags", () => compileOnly(true)),
vscode.languages.registerDocumentLinkProvider(
{ language: "vscode-objectscript-output" },
new DocumentLinkProvider()
),
vscode.languages.registerDocumentLinkProvider({ language: outputLangId }, new DocumentLinkProvider()),
vscode.commands.registerCommand("vscode-objectscript.editOthers", () => viewOthers(true)),
vscode.commands.registerCommand("vscode-objectscript.showClassDocumentationPreview", () =>
DocumaticPreviewPanel.create()
Expand Down
17 changes: 2 additions & 15 deletions src/providers/FileSystemProvider/FileSystemProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {
stringifyError,
base64EncodeContent,
openCustomEditors,
compileErrorMsg,
} from "../../utils";
import { FILESYSTEM_READONLY_SCHEMA, FILESYSTEM_SCHEMA, intLangId, macLangId, workspaceState } from "../../extension";
import { addIsfsFileToProject, modifyProject } from "../../commands/project";
Expand Down Expand Up @@ -803,21 +804,7 @@ export class FileSystemProvider implements vscode.FileSystemProvider {
vscode.window.showInformationMessage(`${info}Compilation succeeded.`, "Dismiss");
}
})
.catch(() => {
if (!conf.get("suppressCompileErrorMessages")) {
vscode.window
.showErrorMessage(
"Compilation failed. Check 'ObjectScript' Output channel for details.",
"Show",
"Dismiss"
)
.then((action) => {
if (action === "Show") {
outputChannel.show(true);
}
});
}
})
.catch(() => compileErrorMsg(conf))
);
// Tell the client to update all "other" files affected by compilation
const workspaceFolder = workspaceFolderOfUri(uri);
Expand Down
19 changes: 18 additions & 1 deletion src/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,13 @@ import {
OBJECTSCRIPT_FILE_SCHEMA,
documentContentProvider,
filesystemSchemas,
outputLangId,
} from "../extension";
import { getCategory } from "../commands/export";
import { isCSP, isfsDocumentName } from "../providers/FileSystemProvider/FileSystemProvider";
import { AtelierAPI } from "../api";

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

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

/** Show the compilation failure error message if required. */
export function compileErrorMsg(conf: vscode.WorkspaceConfiguration): void {
if (conf.get("suppressCompileErrorMessages")) return;
vscode.window
.showErrorMessage(
"Compilation failed. Check 'ObjectScript' Output channel for details.",
!vscode.window.visibleTextEditors.some((e) => e.document.languageId == outputLangId) ? "Show" : undefined,
"Dismiss"
)
.then((action) => {
if (action == "Show") {
outputChannel.show(true);
}
});
}

class Semaphore {
/** Queue of tasks waiting to acquire the semaphore */
private _tasks: (() => void)[] = [];
Expand Down