Skip to content

Commit c426c7a

Browse files
authored
Add command for opening InterSystems documents (#1398)
1 parent bbbe1d8 commit c426c7a

File tree

5 files changed

+321
-59
lines changed

5 files changed

+321
-59
lines changed

package.json

+15
Original file line numberDiff line numberDiff line change
@@ -338,6 +338,10 @@
338338
{
339339
"command": "vscode-objectscript.compileIsfs",
340340
"when": "false"
341+
},
342+
{
343+
"command": "vscode-objectscript.openISCDocument",
344+
"when": "vscode-objectscript.connectActive && workspaceFolderCount != 0"
341345
}
342346
],
343347
"view/title": [
@@ -355,6 +359,11 @@
355359
"command": "vscode-objectscript.explorer.project.openOtherServerNs",
356360
"when": "view == ObjectScriptProjectsExplorer && vscode-objectscript.projectsExplorerRootCount > 0",
357361
"group": "navigation"
362+
},
363+
{
364+
"command": "vscode-objectscript.openISCDocument",
365+
"when": "view == workbench.explorer.fileView && vscode-objectscript.connectActive && workspaceFolderCount != 0",
366+
"group": "navigation"
358367
}
359368
],
360369
"view/item/context": [
@@ -1179,6 +1188,12 @@
11791188
"category": "ObjectScript",
11801189
"command": "vscode-objectscript.compileIsfs",
11811190
"title": "Compile"
1191+
},
1192+
{
1193+
"category": "ObjectScript",
1194+
"command": "vscode-objectscript.openISCDocument",
1195+
"title": "Open InterSystems Document...",
1196+
"icon": "$(go-to-file)"
11821197
}
11831198
],
11841199
"keybindings": [

src/api/index.ts

+16-3
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,7 @@ export class AtelierAPI {
314314
const target = `${username}@${host}:${port}`;
315315
let auth: Promise<any>;
316316
let authRequest = authRequestMap.get(target);
317-
if (cookies.length || method === "HEAD") {
317+
if (cookies.length || (method === "HEAD" && !originalPath)) {
318318
auth = Promise.resolve(cookies);
319319

320320
// Only send basic authorization if username and password specified (including blank, for unauthenticated access)
@@ -367,8 +367,16 @@ export class AtelierAPI {
367367
}
368368
await this.updateCookies(response.headers.raw()["set-cookie"] || []);
369369
if (method === "HEAD") {
370-
authRequestMap.delete(target);
371-
return this.cookies;
370+
if (!originalPath) {
371+
authRequestMap.delete(target);
372+
return this.cookies;
373+
} else if (response.status >= 400) {
374+
// The HEAD /doc request errored out
375+
throw { statusCode: response.status, message: response.statusText, errorText: "" };
376+
} else {
377+
// The HEAD /doc request succeeded
378+
return response.headers.get("ETAG");
379+
}
372380
}
373381

374382
// Not Modified
@@ -492,6 +500,11 @@ export class AtelierAPI {
492500
});
493501
}
494502

503+
// api v1+
504+
public headDoc(name: string): Promise<string> {
505+
return this.request(1, "HEAD", `${this.ns}/doc/${name}`);
506+
}
507+
495508
// api v1+
496509
public getDoc(name: string, format?: string, mtime?: number): Promise<Atelier.Response<Atelier.Document>> {
497510
let params = {};

src/extension.ts

+26
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@ import { RESTDebugPanel } from "./commands/restDebugPanel";
139139
import { modifyWsFolder } from "./commands/addServerNamespaceToWorkspace";
140140
import { WebSocketTerminalProfileProvider, launchWebSocketTerminal } from "./commands/webSocketTerminal";
141141
import { setUpTestController } from "./commands/unitTest";
142+
import { pickDocument } from "./utils/documentPicker";
142143

143144
const packageJson = vscode.extensions.getExtension(extensionId).packageJSON;
144145
const extensionVersion = packageJson.version;
@@ -1405,6 +1406,31 @@ export async function activate(context: vscode.ExtensionContext): Promise<any> {
14051406
}
14061407
),
14071408
vscode.commands.registerCommand("vscode-objectscript.compileIsfs", (uri) => fileSystemProvider.compile(uri)),
1409+
vscode.commands.registerCommand("vscode-objectscript.openISCDocument", async () => {
1410+
const workspaceFolders = vscode.workspace.workspaceFolders || [];
1411+
let wsFolder: vscode.WorkspaceFolder;
1412+
if (workspaceFolders.length == 1) {
1413+
// Use the current connection
1414+
wsFolder = workspaceFolders[0];
1415+
} else if (workspaceFolders.length > 1) {
1416+
// Pick from the workspace folders
1417+
wsFolder = await vscode.window.showWorkspaceFolderPick();
1418+
}
1419+
if (!wsFolder) return;
1420+
const api = new AtelierAPI(wsFolder.uri);
1421+
if (!api.active) {
1422+
vscode.window.showErrorMessage(
1423+
"'Open InterSystems Document...' command requires an active server connection.",
1424+
"Dismiss"
1425+
);
1426+
return;
1427+
}
1428+
const doc = await pickDocument(api, "Open a document");
1429+
if (!doc) return;
1430+
vscode.window.showTextDocument(
1431+
DocumentContentProvider.getUri(doc, undefined, undefined, undefined, wsFolder.uri)
1432+
);
1433+
}),
14081434
...setUpTestController(),
14091435

14101436
/* Anything we use from the VS Code proposed API */

0 commit comments

Comments
 (0)