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
8 changes: 4 additions & 4 deletions 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 package.json
Original file line number Diff line number Diff line change
Expand Up @@ -1718,7 +1718,7 @@
},
"devDependencies": {
"@eslint/js": "^9.39.2",
"@intersystems-community/intersystems-servermanager": "^3.14.0",
"@intersystems-community/intersystems-servermanager": "^3.14.1",
"@types/istextorbinary": "2.3.1",
"@types/minimatch": "6.0.0",
"@types/mocha": "^10.0.10",
Expand Down
28 changes: 16 additions & 12 deletions src/api/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import axios from "axios";
import * as httpsModule from "https";
import * as vscode from "vscode";
import * as semver from "semver";
import {
import BasicAuthorization, {
getResolvedConnectionSpec,
config,
extensionContext,
Expand Down Expand Up @@ -57,7 +57,7 @@ export interface ConnectionSettings {
port: number;
superserverPort?: number;
pathPrefix?: string;
ns: string;
ns: string | undefined;
auth: Authorization;
docker?: boolean;
dockerService?: string;
Expand Down Expand Up @@ -171,7 +171,7 @@ export class AtelierAPI {
webServer: { scheme, host, port, pathPrefix = "" },
auth,
} = connSpec;
this._config.auth = auth;
this._config.auth = auth ?? new BasicAuthorization();
this._config.https = scheme == "https";
this._config.host = host;
this._config.port = port;
Expand Down Expand Up @@ -200,7 +200,7 @@ export class AtelierAPI {

public terminalUrl(): string {
const { host, https, port, apiVersion, pathPrefix } = this.config;
return apiVersion >= 7
return apiVersion! >= 7
? `${https ? "wss" : "ws"}://${host}:${port}${pathPrefix}/api/atelier/v${apiVersion}/%25SYS/terminal`
: "";
}
Expand Down Expand Up @@ -232,7 +232,11 @@ export class AtelierAPI {

private setConnection(workspaceFolderName: string, namespace?: string): void {
this.configName = workspaceFolderName;
const conn = config("conn", workspaceFolderName);
const rawConn = config("conn", workspaceFolderName);
const conn = {
...rawConn,
auth: new BasicAuthorization(rawConn.username, rawConn.password),
};
let serverName = workspaceFolderName.toLowerCase();
if (config("intersystems.servers", workspaceFolderName).has(serverName)) {
this.externalServer = true;
Expand All @@ -254,7 +258,7 @@ export class AtelierAPI {
webServer: { scheme, host, port, pathPrefix = "" },
auth,
superServer,
} = getResolvedConnectionSpec(serverName, config("intersystems.servers", workspaceFolderName).get(serverName));
} = getResolvedConnectionSpec(serverName, config("intersystems.servers", workspaceFolderName).get(serverName))!;
this._config = {
serverName,
active: this.externalServer ? !inactiveServerIds.has(serverName) : conn.active,
Expand Down Expand Up @@ -333,7 +337,7 @@ export class AtelierAPI {
if (!active || !port || !host) {
return Promise.reject();
}
if (minVersion > apiVersion) {
if (minVersion > apiVersion!) {
return Promise.reject(`${path} not supported by API version ${apiVersion}`);
}
const originalPath = path;
Expand All @@ -348,7 +352,7 @@ export class AtelierAPI {
if (!params) {
return "";
}
const result = [];
const result: string[] = [];
Object.keys(params).forEach((key) => {
const value = params[key];
if (typeof value === "boolean") {
Expand Down Expand Up @@ -379,7 +383,7 @@ export class AtelierAPI {

const cookies = this.cookies;
const mapKey = this.mapKey();
let auth: Promise<any>;
let auth: Promise<any> | undefined;
let authRequest = authRequestMap.get(mapKey);
if (cookies.length || (method === "HEAD" && !originalPath)) {
// Only send basic authorization if username and password specified (including blank, for unauthenticated access)
Expand Down Expand Up @@ -417,7 +421,7 @@ export class AtelierAPI {
}
};
try {
cookie = await auth;
cookie = await auth!;
reqTs = new Date();
const response = await axios.request({
method,
Expand Down Expand Up @@ -598,7 +602,7 @@ export class AtelierAPI {
.slice(data.version.indexOf(") ") + 2)
.split(" ")
.shift()
).version;
)!.version;
if (this.ns && this.ns.length && !data.namespaces.includes(this.ns) && checkNs) {
throw {
code: "WrongNamespace",
Expand Down Expand Up @@ -649,7 +653,7 @@ export class AtelierAPI {
const params: Record<string, string> = {};
name = this.transformNameIfCsp(name);
if (
this.config.apiVersion >= 4 &&
this.config.apiVersion! >= 4 &&
vscode.workspace
.getConfiguration(
"objectscript",
Expand Down
24 changes: 13 additions & 11 deletions src/commands/addServerNamespaceToWorkspace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ import { isfsConfig, IsfsUriParam } from "../utils/FileProviderUtil";
* @param message The prefix of the message to show when the server manager API can't be found.
* @returns An object containing `serverName` and `namespace`, or `undefined`.
*/
async function pickServerAndNamespace(message?: string): Promise<{ serverName: string; namespace: string }> {
async function pickServerAndNamespace(
message?: string
): Promise<{ serverName: string; namespace: string } | undefined> {
if (!serverManagerApi) {
vscode.window.showErrorMessage(
`${
Expand All @@ -29,7 +31,7 @@ async function pickServerAndNamespace(message?: string): Promise<{ serverName: s
}
// Get user's choice of server
const options: vscode.QuickPickOptions = { ignoreFocusOut: true };
const serverName: string = await serverManagerApi.pickServer(undefined, options);
const serverName: string | undefined = await serverManagerApi.pickServer(undefined, options);
if (!serverName) {
return;
}
Expand All @@ -40,13 +42,13 @@ async function pickServerAndNamespace(message?: string): Promise<{ serverName: s
return { serverName, namespace };
}

async function pickNamespaceOnServer(serverName: string): Promise<string> {
async function pickNamespaceOnServer(serverName: string): Promise<string | undefined> {
// Get its namespace list
const uri = vscode.Uri.parse(`isfs://${serverName}:%sys/`);
await resolveConnectionSpec(serverName);
// Prepare a displayable form of its connection spec as a hint to the user.
// This will never return the default value (second parameter) because we only just resolved the connection spec.
const connSpec = getResolvedConnectionSpec(serverName, undefined);
const connSpec = getResolvedConnectionSpec(serverName, undefined)!;
const connDisplayString = `${connSpec.webServer.scheme}://${connSpec.webServer.host}:${connSpec.webServer.port}/${connSpec.webServer.pathPrefix}`;
// Connect and fetch namespaces
const api = new AtelierAPI(uri);
Expand Down Expand Up @@ -81,9 +83,9 @@ async function pickNamespaceOnServer(serverName: string): Promise<string> {
export async function addServerNamespaceToWorkspace(resource?: vscode.Uri): Promise<void> {
const TITLE = "Add server namespace to workspace";
let serverName = "";
let namespace = "";
if (filesystemSchemas.includes(resource?.scheme)) {
serverName = resource.authority.split(":")[0];
let namespace: string | undefined = "";
if (filesystemSchemas.includes(resource?.scheme as string)) {
serverName = resource!.authority.split(":")[0];
if (serverName) {
const ANOTHER = "Choose another server";
const choice = await vscode.window.showQuickPick([`Add a '${serverName}' namespace`, ANOTHER], {
Expand Down Expand Up @@ -111,7 +113,7 @@ export async function addServerNamespaceToWorkspace(resource?: vscode.Uri): Prom
}
}
const wsFolders = vscode.workspace.workspaceFolders ?? [];
let scheme: string;
let scheme: string | undefined;
if (wsFolders.length && wsFolders.some((wf) => notIsfs(wf.uri))) {
// Don't allow the creation of an editable ISFS folder
// if the workspace contains non-ISFS folders already
Expand Down Expand Up @@ -221,7 +223,7 @@ async function modifyWsFolderUri(uri: vscode.Uri): Promise<vscode.Uri | undefine
}

let newParams = "";
let newPath = uri.path;
let newPath: string | undefined = uri.path;
if (filterType == "csp") {
// Prompt for a specific web app
let cspApps = cspAppsForUri(uri);
Expand All @@ -243,7 +245,7 @@ async function modifyWsFolderUri(uri: vscode.Uri): Promise<vscode.Uri | undefine
}
}
newPath = await new Promise<string | undefined>((resolve) => {
let result: string;
let result: string | undefined;
const allItem: vscode.QuickPickItem = { label: "All" };
const quickPick = vscode.window.createQuickPick();
quickPick.title = "Pick a specific web application to show, or show all";
Expand Down Expand Up @@ -352,7 +354,7 @@ async function modifyWsFolderUri(uri: vscode.Uri): Promise<vscode.Uri | undefine
}

export async function modifyWsFolder(wsFolderUri?: vscode.Uri): Promise<void> {
let wsFolder: vscode.WorkspaceFolder;
let wsFolder: vscode.WorkspaceFolder | null | undefined;
if (!wsFolderUri) {
// Select a workspace folder to modify
wsFolder = await getWsFolder("Pick the workspace folder to modify", false, true);
Expand Down
29 changes: 15 additions & 14 deletions src/commands/compile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ export async function importFile(
if (!file) return;
const api = new AtelierAPI(file.uri);
if (!api.active) return Promise.reject();
if (file.name.split(".").pop().toLowerCase() === "cls" && !skipDeplCheck) {
if (file.name.split(".").pop()!.toLowerCase() === "cls" && !skipDeplCheck) {
if (await isClassDeployed(file.name, api)) {
vscode.window.showErrorMessage(`Cannot import ${file.name} because it is deployed on the server.`, "Dismiss");
return Promise.reject();
Expand Down Expand Up @@ -207,10 +207,10 @@ function updateOthers(others: string[], baseUri: vscode.Uri) {
}
others.forEach((item) => {
const uri = DocumentContentProvider.getUri(item, undefined, undefined, undefined, workspaceFolder?.uri);
if (filesystemSchemas.includes(uri.scheme)) {
fileSystemProvider.fireFileChanged(uri);
} else if (uri.scheme == OBJECTSCRIPT_FILE_SCHEMA) {
documentContentProvider.update(uri);
if (filesystemSchemas.includes(uri!.scheme)) {
fileSystemProvider.fireFileChanged(uri!);
} else if (uri!.scheme == OBJECTSCRIPT_FILE_SCHEMA) {
documentContentProvider.update(uri!);
}
});
}
Expand All @@ -234,7 +234,7 @@ export async function loadChanges(
Promise.allSettled(
data.result.content.map(async (doc) => {
if (doc.status.length) return;
const file = files.find((f) => f.name == doc.name);
const file = files.find((f) => f.name == doc.name)!;
const mtime = Number(new Date(doc.ts + "Z"));
workspaceState.update(`${file.uniqueId}:mtime`, mtime > 0 ? mtime : undefined);
if (notIsfs(file.uri)) {
Expand Down Expand Up @@ -312,8 +312,8 @@ function updateStorage(content: string[], storage: string[]): string[] {

function storageToMap(storage: string[]): Map<string, string> {
const map: Map<string, string> = new Map();
let k: string;
let v = [];
let k: string | undefined;
let v: string[] = [];
for (const line of storage) {
if (line.startsWith("Storage ")) {
k = line.slice("Storage ".length, line.length);
Expand Down Expand Up @@ -412,7 +412,7 @@ export async function importAndCompile(document?: vscode.TextDocument, askFlags
}
}

export async function compileOnly(document?: vscode.TextDocument, askFlags = false): Promise<any> {
export async function compileOnly(document?: vscode.TextDocument | null, askFlags = false): Promise<any> {
document =
document ||
(vscode.window.activeTextEditor && vscode.window.activeTextEditor.document
Expand Down Expand Up @@ -468,7 +468,7 @@ export async function namespaceCompile(): Promise<any> {
.then(() => {
// Always fetch server changes, even when compile failed or got cancelled
const file = currentFile();
return loadChanges([file]);
return loadChanges([file!]);
})
);
}
Expand Down Expand Up @@ -526,7 +526,7 @@ export async function compileExplorerItems(nodes: NodeBase[]): Promise<any> {
const conf = vscode.workspace.getConfiguration("objectscript", wsFolder);
const api = new AtelierAPI(wsFolder.uri);
if (namespace) api.setNamespace(namespace);
const docs = [];
const docs: string[] = [];
for (const node of nodes) {
if (node instanceof PackageNode) {
switch (node.category) {
Expand Down Expand Up @@ -659,7 +659,7 @@ export async function importArbitraryFiles(): Promise<any> {
});
if (!uris?.length) return;
// Filter out non-importable files
uris = uris.filter((uri) => supportedExts.includes(uri.path.split(".").pop().toLowerCase()));
uris = uris.filter((uri) => supportedExts.includes(uri.path.split(".").pop()!.toLowerCase()));
if (uris.length == 0) {
vscode.window.showErrorMessage("No selected files are importable.", "Dismiss");
return;
Expand Down Expand Up @@ -689,6 +689,7 @@ export async function importArbitraryFiles(): Promise<any> {
}
})
.filter(notNull)
.map((f) => f!)
);
if (filesToList.length == 0) {
vscode.window.showErrorMessage("Failed to read the text of every selected file.", "Dismiss");
Expand Down Expand Up @@ -754,9 +755,9 @@ export async function importArbitraryFiles(): Promise<any> {
}
});
if (readOnly.length) {
docsToImport = docsToImport.filter((qpi) => {
docsToImport = docsToImport!.filter((qpi) => {
const nameSplit = qpi.label.split(".");
return !readOnly.includes(`${nameSplit.slice(0, -1).join(".")}.${nameSplit.pop().toUpperCase()}`);
return !readOnly.includes(`${nameSplit.slice(0, -1).join(".")}.${nameSplit.pop()!.toUpperCase()}`);
});
}
});
Expand Down
Loading