Skip to content
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
14 changes: 7 additions & 7 deletions client/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"vscode-languageclient": "^9.0.1"
},
"devDependencies": {
"@intersystems-community/intersystems-servermanager": "^3.14.0",
"@intersystems-community/intersystems-servermanager": "^3.14.1",
"@types/semver": "^7.7.0",
"@types/vscode": "1.93.0"
}
Expand Down
22 changes: 11 additions & 11 deletions client/src/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import { client } from "./extension";
*/
export async function overrideClassMembers() {
// Get the open document and check that it's an ObjectScript class
const openDoc = window.activeTextEditor.document;
const openDoc = window.activeTextEditor!.document;
if (openDoc.languageId != "objectscript-class") {
// Can only override members in a class
return;
Expand All @@ -48,7 +48,7 @@ export async function overrideClassMembers() {
}

// Check that we can insert new class members at the cursor position
const selection = window.activeTextEditor.selection;
const selection = window.activeTextEditor!.selection;
let cursorvalid = false;
let docposvalid = false;
if (openDoc.lineAt(selection.active.line).isEmptyOrWhitespace && selection.isEmpty) {
Expand Down Expand Up @@ -175,10 +175,10 @@ export async function selectImportPackage(uri: string, classname: string) {
selectedPackage = allimportpackages[0];
} else {
// Ask the user to select an import package
selectedPackage = await window.showQuickPick(allimportpackages, {
selectedPackage = (await window.showQuickPick(allimportpackages, {
title: "Pick the package to import",
canPickMany: false,
});
}))!;
if (!selectedPackage) {
// No package was selected
return;
Expand Down Expand Up @@ -206,7 +206,7 @@ export async function extractMethod(
newmethodtype: string,
) {
// Get the list of class member names
const symbols = await commands.executeCommand("vscode.executeDocumentSymbolProvider", Uri.parse(uri));
const symbols: any[] = await commands.executeCommand("vscode.executeDocumentSymbolProvider", Uri.parse(uri));
const clsmembers: string[] = [];
for (let clsmember = 0; clsmember < symbols[0].children.length; clsmember++) {
clsmembers.push(symbols[0].children[clsmember].name);
Expand Down Expand Up @@ -261,20 +261,20 @@ export async function extractMethod(
await workspace.applyEdit(await client.protocol2CodeConverter.asWorkspaceEdit(lspWorkspaceEdit));

// Highlight and scroll to new extracted method
const activeEditor = window.activeTextEditor;
const activeEditor = window.activeTextEditor!;
if (activeEditor.document.uri.toString() === uri) {
// Selection of the extracted method
const anchor = lspWorkspaceEdit.changes[uri][0].range.start;
const anchor = lspWorkspaceEdit.changes![uri][0].range.start;
let methodstring: string = "";
for (let edit = 0; edit < lspWorkspaceEdit.changes[uri].length - 2; edit++) {
methodstring += lspWorkspaceEdit.changes[uri][edit].newText;
for (let edit = 0; edit < lspWorkspaceEdit.changes![uri].length - 2; edit++) {
methodstring += lspWorkspaceEdit.changes![uri][edit].newText;
}
const methodsize = methodstring.split("\n").length - 1;
const range: Range = new Range(new Position(anchor.line + 1, 0), new Position(anchor.line + methodsize, 1));

// Selection of the method call
const anchor2 = lspWorkspaceEdit.changes[uri][lspWorkspaceEdit.changes[uri].length - 1].range.start;
const linesize = lspWorkspaceEdit.changes[uri][lspWorkspaceEdit.changes[uri].length - 1].newText.length;
const anchor2 = lspWorkspaceEdit.changes![uri][lspWorkspaceEdit.changes![uri].length - 1].range.start;
const linesize = lspWorkspaceEdit.changes![uri][lspWorkspaceEdit.changes![uri].length - 1].newText.length;
const range2: Range = new Range(
new Position(anchor2.line + methodsize + 1, anchor2.character),
new Position(anchor2.line + methodsize + 1, anchor2.character + linesize + 1),
Expand Down
60 changes: 59 additions & 1 deletion client/src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import { makeRESTRequest } from "./makeRESTRequest";
import { ISCEmbeddedContentProvider, requestForwardingMiddleware } from "./requestForwarding";
import type { ServerSpec, ProtocolMethods } from "../../common/out/types";
import type { Disposable } from "vscode-languageclient";
import { Authorization, ResolvedAuthorization } from '@intersystems-community/intersystems-servermanager';

export let client: {
onRequest<K extends keyof ProtocolMethods>(
Expand Down Expand Up @@ -168,7 +169,8 @@ export async function activate(context: ExtensionContext) {
// for a missing password via the Server Manager's authentication provider.
async function resolveServerSpec(uri: Uri) {
const wsFolderUriString = workspace.getWorkspaceFolder(uri)?.uri.toString();
const { auth, ...serverSpec } = objectScriptApi.serverForUri(uri);
const serverSpec = objectScriptApi.serverForUri(uri)!;
const auth = serverSpec.auth ?? new BasicAuthorization(serverSpec.username, serverSpec.password);
if (
// Server was resolved
serverSpec.host !== "" &&
Expand Down Expand Up @@ -455,3 +457,59 @@ export async function deactivate(): Promise<void> {
}
await Promise.allSettled(promises);
}


// A copy of the BasicAuthorization class from ServerManager
// We use it to patch older version of getServerSpec.
export default class BasicAuthorization implements Authorization {
#username?: string;
#password?: string;
constructor(username?: string, password?: string) {
this.#username = username;
this.#password = password;
}

public get username(): string {
return this.#username || "";
}

public get password(): string | undefined {
return this.#password;
}

public get accessToken(): string | undefined {
return this.#password;
}

public get httpAuthorizationHeader(): string {
return `Basic ${Buffer.from(`${this.#username}:${this.#password}`).toString("base64")}`;
}

public resolved(): this is ResolvedAuthorization {
return this.username !== "" && this.#password !== undefined;
}

public resolve(param: { accessToken: string; username?: string }): this is ResolvedAuthorization {
this.#username = param.username ?? this.#username;
this.#password = param.accessToken ?? this.#password;
return this.resolved();
}

public clear(): asserts this is Authorization {
this.#password = undefined;
}

public get credentials(): { auth: { username: string; password: string }; headers?: Record<string, string> } {
return {
auth: {
username: this.username,
password: this.password!,
},
headers: {},
};
}

public clone(): BasicAuthorization {
return new BasicAuthorization(this.#username, this.#password);
}
}
4 changes: 2 additions & 2 deletions client/src/requestForwarding.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,15 +140,15 @@ export const requestForwardingMiddleware: Middleware = {
};

export class ISCEmbeddedContentProvider implements TextDocumentContentProvider {
constructor() {}
constructor() { }

provideTextDocumentContent(uri: Uri): ProviderResult<string> {
// Get the isclexer language number and position from the URI authority
const language: number = Number(uri.authority.split(":")[0]);
const positionText = uri.authority.split(":")[1];
const position = new Position(Number(positionText.split("-")[0]), Number(positionText.split("-")[1]));
// Use the language number to isolate the original URI
let originalUri: string;
let originalUri: string | undefined;
if (language == 11) {
// Language is JavaScript so the extension is .js
originalUri = uri.path.slice(1).slice(0, -3);
Expand Down
3 changes: 2 additions & 1 deletion client/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
"target": "es6",
"outDir": "out",
"rootDir": "src",
"sourceMap": true
"sourceMap": true,
"strictNullChecks": true,
},
"include": ["src"],
"exclude": ["node_modules", ".vscode-test"]
Expand Down
28 changes: 0 additions & 28 deletions common/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions common/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@
"declarationMap": true,
"strict": true,
"esModuleInterop": true,
"skipLibCheck": true
},
"skipLibCheck": true,
"strictNullChecks": true,
},
"include": ["src"],
"exclude": ["node_modules", "out"]
}
Loading