Skip to content

Use default web application for CodeLens links #1393

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
Jul 5, 2024
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
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 @@ -1387,20 +1386,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