Skip to content

Commit

Permalink
Use default web application for CodeLens links (#1393)
Browse files Browse the repository at this point in the history
  • Loading branch information
isc-bsaviano committed Jul 5, 2024
1 parent 43724cd commit e770ec8
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 15 deletions.
29 changes: 16 additions & 13 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,6 @@ import { FileDecorationProvider } from "./providers/FileDecorationProvider";
import { RESTDebugPanel } from "./commands/restDebugPanel";
import { modifyWsFolder } from "./commands/addServerNamespaceToWorkspace";
import { WebSocketTerminalProfileProvider, launchWebSocketTerminal } from "./commands/webSocketTerminal";
import { getCSPToken } from "./utils/getCSPToken";
import { setUpTestController } from "./commands/unitTest";

const packageJson = vscode.extensions.getExtension(extensionId).packageJSON;
Expand Down Expand Up @@ -1384,20 +1383,24 @@ export async function activate(context: vscode.ExtensionContext): Promise<any> {
vscode.commands.registerCommand(
"vscode-objectscript.openPathInBrowser",
async (path: string, docUri: vscode.Uri) => {
if (typeof path == "string" && docUri && docUri instanceof vscode.Uri) {
if (typeof path == "string" && docUri instanceof vscode.Uri) {
const api = new AtelierAPI(docUri);
let uri = vscode.Uri.parse(
`${api.config.https ? "https" : "http"}://${api.config.host}:${api.config.port}${
api.config.pathPrefix
}${path}`
// Get the default web application for this namespace.
// If it can't be determined, fall back to the /csp/<namespace> web application.
const app: string =
(await api
.getCSPApps(true)
.then((data) => data.result.content.find((a) => a.default)?.name)
.catch(() => {
// Swallow errors
})) ?? `/csp/${api.ns}`;
vscode.env.openExternal(
vscode.Uri.parse(
`${api.config.https ? "https" : "http"}://${api.config.host}:${api.config.port}${
api.config.pathPrefix
}${app}${path}`
)
);
const token = await getCSPToken(api, path.split("?")[0]).catch(() => "");
if (token.length > 0) {
uri = uri.with({
query: uri.query.length ? `${uri.query}&CSPCHD=${token}` : `CSPCHD=${token}`,
});
}
vscode.env.openExternal(uri);
}
}
),
Expand Down
4 changes: 2 additions & 2 deletions src/providers/ObjectScriptCodeLensProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ export class ObjectScriptCodeLensProvider implements vscode.CodeLensProvider {
command: "vscode-objectscript.openPathInBrowser",
tooltip: "Open graphical editor in an external browser",
arguments: [
`/csp/${api.config.ns.toLowerCase()}/EnsPortal.${
`/EnsPortal.${
xdataName == "BPL" ? `BPLEditor.zen?BP=${className}.BPL` : `DTLEditor.zen?DT=${className}.DTL`
}`,
document.uri,
Expand All @@ -87,7 +87,7 @@ export class ObjectScriptCodeLensProvider implements vscode.CodeLensProvider {
title: "Test KPI",
command: "vscode-objectscript.openPathInBrowser",
tooltip: "Open testing page in an external browser",
arguments: [`/csp/${api.config.ns.toLowerCase()}/${className}.cls`, document.uri],
arguments: [`/${className}.cls`, document.uri],
};
}
if (cmd) result.push(new vscode.CodeLens(new vscode.Range(i, 0, i, 80), cmd));
Expand Down

0 comments on commit e770ec8

Please sign in to comment.