Skip to content

Commit 0bd0a7d

Browse files
authored
serverForUri should either set ns or be undefined (#1843)
1 parent 5ca3391 commit 0bd0a7d

3 files changed

Lines changed: 26 additions & 21 deletions

File tree

‎src/api/index.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ export interface ConnectionSettings {
5858
port: number;
5959
superserverPort?: number;
6060
pathPrefix?: string;
61-
ns: string | undefined;
61+
ns?: string;
6262
auth: Authorization;
6363
docker?: boolean;
6464
dockerService?: string;
@@ -254,7 +254,7 @@ export class AtelierAPI {
254254
serverName = "";
255255
}
256256

257-
const ns = namespace ? namespace.toUpperCase() : conn.ns ? (conn.ns as string).toUpperCase() : undefined;
257+
const ns = namespace?.toUpperCase() || conn.ns?.toUpperCase();
258258
if (serverName !== "") {
259259
const {
260260
webServer: { scheme, host, port, pathPrefix = "" },

‎src/extension.ts‎

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2004,7 +2004,7 @@ export async function activate(context: vscode.ExtensionContext): Promise<server
20042004

20052005
// This function is exported as one of our API functions but is also used internally
20062006
// for example to implement the async variant capable of resolving docker port number.
2007-
function serverForUri(uri: vscode.Uri): serverManager.ServerForUri {
2007+
function serverForUri(uri: vscode.Uri): serverManager.ServerForUri | undefined {
20082008
const { apiTarget, configName } = connectionTarget(uri);
20092009
const configNameLower = configName.toLowerCase();
20102010
const api = new AtelierAPI(apiTarget);
@@ -2030,27 +2030,32 @@ function serverForUri(uri: vscode.Uri): serverManager.ServerForUri {
20302030
)
20312031
.get("password");
20322032
password && auth.resolve({ accessToken: password });
2033-
return {
2034-
serverName,
2035-
active,
2036-
...(https ? ({ https: true, scheme: "https" } as const) : ({ scheme: "http" } as const)),
2037-
host,
2038-
port,
2039-
superserverPort,
2040-
pathPrefix: pathPrefix!,
2041-
auth,
2042-
username: auth.username,
2043-
password: auth.password,
2044-
namespace: ns!,
2045-
apiVersion: (active ? apiVersion : undefined)!,
2046-
serverVersion: (active ? serverVersion : undefined)!,
2047-
};
2033+
if (ns) {
2034+
return {
2035+
serverName,
2036+
active,
2037+
...(https ? ({ https: true, scheme: "https" } as const) : ({ scheme: "http" } as const)),
2038+
host,
2039+
port,
2040+
superserverPort,
2041+
pathPrefix: pathPrefix || "",
2042+
auth,
2043+
username: auth.username,
2044+
password: auth.password,
2045+
namespace: ns,
2046+
apiVersion: (active ? apiVersion : undefined)!,
2047+
serverVersion: (active ? serverVersion : undefined)!,
2048+
};
2049+
}
20482050
}
20492051

20502052
// An async variant capable of resolving docker port number.
20512053
// It is exported as one of our API functions but is also used internally.
2052-
async function asyncServerForUri(uri: vscode.Uri): Promise<serverManager.ServerForUri> {
2054+
async function asyncServerForUri(uri: vscode.Uri): Promise<serverManager.ServerForUri | undefined> {
20532055
const server = serverForUri(uri);
2056+
if (!server) {
2057+
return;
2058+
}
20542059
if (!server.port) {
20552060
let { apiTarget } = connectionTarget(uri);
20562061
if (apiTarget instanceof vscode.Uri) {

‎src/providers/DocumentContentProvider.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ import { getUrisForDocument } from "../utils/documentIndex";
99
import { isfsConfig, IsfsUriParam } from "../utils/FileProviderUtil";
1010

1111
export function compareConns(
12-
conn1: { ns: any; server?: any; host: any; port: any; "docker-compose"?: any },
13-
conn2: { ns: any; server?: any; host: any; port: any; "docker-compose"?: any }
12+
conn1: { ns?: string; server?: any; host: any; port: any; "docker-compose"?: any },
13+
conn2: { ns?: string; server?: any; host: any; port: any; "docker-compose"?: any }
1414
): boolean {
1515
if (conn1.ns === conn2.ns) {
1616
// Same namespace name

0 commit comments

Comments
 (0)