Skip to content

Commit

Permalink
Add command for opening InterSystems documents (#1398)
Browse files Browse the repository at this point in the history
  • Loading branch information
isc-bsaviano authored Jul 12, 2024
1 parent bbbe1d8 commit c426c7a
Show file tree
Hide file tree
Showing 5 changed files with 321 additions and 59 deletions.
15 changes: 15 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,10 @@
{
"command": "vscode-objectscript.compileIsfs",
"when": "false"
},
{
"command": "vscode-objectscript.openISCDocument",
"when": "vscode-objectscript.connectActive && workspaceFolderCount != 0"
}
],
"view/title": [
Expand All @@ -355,6 +359,11 @@
"command": "vscode-objectscript.explorer.project.openOtherServerNs",
"when": "view == ObjectScriptProjectsExplorer && vscode-objectscript.projectsExplorerRootCount > 0",
"group": "navigation"
},
{
"command": "vscode-objectscript.openISCDocument",
"when": "view == workbench.explorer.fileView && vscode-objectscript.connectActive && workspaceFolderCount != 0",
"group": "navigation"
}
],
"view/item/context": [
Expand Down Expand Up @@ -1179,6 +1188,12 @@
"category": "ObjectScript",
"command": "vscode-objectscript.compileIsfs",
"title": "Compile"
},
{
"category": "ObjectScript",
"command": "vscode-objectscript.openISCDocument",
"title": "Open InterSystems Document...",
"icon": "$(go-to-file)"
}
],
"keybindings": [
Expand Down
19 changes: 16 additions & 3 deletions src/api/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ export class AtelierAPI {
const target = `${username}@${host}:${port}`;
let auth: Promise<any>;
let authRequest = authRequestMap.get(target);
if (cookies.length || method === "HEAD") {
if (cookies.length || (method === "HEAD" && !originalPath)) {
auth = Promise.resolve(cookies);

// Only send basic authorization if username and password specified (including blank, for unauthenticated access)
Expand Down Expand Up @@ -367,8 +367,16 @@ export class AtelierAPI {
}
await this.updateCookies(response.headers.raw()["set-cookie"] || []);
if (method === "HEAD") {
authRequestMap.delete(target);
return this.cookies;
if (!originalPath) {
authRequestMap.delete(target);
return this.cookies;
} else if (response.status >= 400) {
// The HEAD /doc request errored out
throw { statusCode: response.status, message: response.statusText, errorText: "" };
} else {
// The HEAD /doc request succeeded
return response.headers.get("ETAG");
}
}

// Not Modified
Expand Down Expand Up @@ -492,6 +500,11 @@ export class AtelierAPI {
});
}

// api v1+
public headDoc(name: string): Promise<string> {
return this.request(1, "HEAD", `${this.ns}/doc/${name}`);
}

// api v1+
public getDoc(name: string, format?: string, mtime?: number): Promise<Atelier.Response<Atelier.Document>> {
let params = {};
Expand Down
26 changes: 26 additions & 0 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ import { RESTDebugPanel } from "./commands/restDebugPanel";
import { modifyWsFolder } from "./commands/addServerNamespaceToWorkspace";
import { WebSocketTerminalProfileProvider, launchWebSocketTerminal } from "./commands/webSocketTerminal";
import { setUpTestController } from "./commands/unitTest";
import { pickDocument } from "./utils/documentPicker";

const packageJson = vscode.extensions.getExtension(extensionId).packageJSON;
const extensionVersion = packageJson.version;
Expand Down Expand Up @@ -1405,6 +1406,31 @@ export async function activate(context: vscode.ExtensionContext): Promise<any> {
}
),
vscode.commands.registerCommand("vscode-objectscript.compileIsfs", (uri) => fileSystemProvider.compile(uri)),
vscode.commands.registerCommand("vscode-objectscript.openISCDocument", async () => {
const workspaceFolders = vscode.workspace.workspaceFolders || [];
let wsFolder: vscode.WorkspaceFolder;
if (workspaceFolders.length == 1) {
// Use the current connection
wsFolder = workspaceFolders[0];
} else if (workspaceFolders.length > 1) {
// Pick from the workspace folders
wsFolder = await vscode.window.showWorkspaceFolderPick();
}
if (!wsFolder) return;
const api = new AtelierAPI(wsFolder.uri);
if (!api.active) {
vscode.window.showErrorMessage(
"'Open InterSystems Document...' command requires an active server connection.",
"Dismiss"
);
return;
}
const doc = await pickDocument(api, "Open a document");
if (!doc) return;
vscode.window.showTextDocument(
DocumentContentProvider.getUri(doc, undefined, undefined, undefined, wsFolder.uri)
);
}),
...setUpTestController(),

/* Anything we use from the VS Code proposed API */
Expand Down
Loading

0 comments on commit c426c7a

Please sign in to comment.