Skip to content

Add command for opening InterSystems documents #1398

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 3 commits into from
Jul 12, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
9 changes: 9 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 Down Expand Up @@ -1179,6 +1183,11 @@
"category": "ObjectScript",
"command": "vscode-objectscript.compileIsfs",
"title": "Compile"
},
{
"category": "ObjectScript",
"command": "vscode-objectscript.openISCDocument",
"title": "Open InterSystems Document..."
}
],
"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, "to open");
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