Skip to content

Commit 0629936

Browse files
committed
correct work status bar with docker
1 parent a4617f9 commit 0629936

File tree

8 files changed

+71
-31
lines changed

8 files changed

+71
-31
lines changed

src/api/index.ts

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ export interface ConnectionSettings {
3232
ns: string;
3333
username: string;
3434
password: string;
35+
docker: boolean;
36+
dockerService?: string;
3537
}
3638

3739
export class AtelierAPI {
@@ -60,6 +62,8 @@ export class AtelierAPI {
6062
: workspaceState.get(this.configName + ":port", this._config.port);
6163
const password = workspaceState.get(this.configName + ":password", this._config.password);
6264
const apiVersion = workspaceState.get(this.configName + ":apiVersion", DEFAULT_API_VERSION);
65+
const docker = workspaceState.get(this.configName + ":docker", false);
66+
const dockerService = workspaceState.get<string>(this.configName + ":dockerService");
6367
return {
6468
serverName,
6569
active,
@@ -71,6 +75,8 @@ export class AtelierAPI {
7175
ns,
7276
username,
7377
password,
78+
docker,
79+
dockerService,
7480
};
7581
}
7682

@@ -179,6 +185,7 @@ export class AtelierAPI {
179185
username,
180186
password,
181187
pathPrefix,
188+
docker: false,
182189
};
183190

184191
// Report server as inactive when no namespace has been determined,
@@ -199,6 +206,12 @@ export class AtelierAPI {
199206
return new Cache(extensionContext, `API:${host}:${port}`);
200207
}
201208

209+
public get connInfo(): string {
210+
const { host, port, docker, dockerService } = this.config;
211+
const ns = this.ns.toUpperCase();
212+
return (docker ? "docker" + (dockerService ? `:${dockerService}:${port}` : "") : `${host}:${port}`) + `[${ns}]`;
213+
}
214+
202215
public async request(
203216
minVersion: number,
204217
method: string,
@@ -276,7 +289,6 @@ export class AtelierAPI {
276289
}
277290
auth = authRequest;
278291
}
279-
const connInfo = `${host}:${port}[${this.ns}]`;
280292

281293
try {
282294
const cookie = await auth;
@@ -302,7 +314,7 @@ export class AtelierAPI {
302314
throw { statusCode: response.status, message: response.statusText };
303315
}
304316
await this.updateCookies(response.headers.raw()["set-cookie"] || []);
305-
panel.text = `${connInfo}`;
317+
panel.text = `${this.connInfo}`;
306318
panel.tooltip = `Connected as ${username}`;
307319
if (method === "HEAD") {
308320
authRequestMap.delete(target);
@@ -346,7 +358,7 @@ export class AtelierAPI {
346358
}
347359
} catch (error) {
348360
if (error.error && error.error.code === "ECONNREFUSED") {
349-
panel.text = `${connInfo} $(debug-disconnect)`;
361+
panel.text = `${this.connInfo} $(debug-disconnect)`;
350362
panel.tooltip = "Disconnected";
351363
workspaceState.update(this.configName + ":host", undefined);
352364
workspaceState.update(this.configName + ":port", undefined);

src/commands/serverActions.ts

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
import * as vscode from "vscode";
2-
import { config, workspaceState, checkConnection, FILESYSTEM_SCHEMA, FILESYSTEM_READONLY_SCHEMA } from "../extension";
2+
import {
3+
config,
4+
workspaceState,
5+
checkConnection,
6+
FILESYSTEM_SCHEMA,
7+
FILESYSTEM_READONLY_SCHEMA,
8+
explorerProvider,
9+
} from "../extension";
310
import { connectionTarget, terminalWithDocker, currentFile } from "../utils";
411
import { mainCommandMenu, mainSourceControlMenu } from "./studio";
512
import { AtelierAPI } from "../api";
@@ -8,9 +15,10 @@ type ServerAction = { detail: string; id: string; label: string };
815
export async function serverActions(): Promise<void> {
916
const { apiTarget, configName: workspaceFolder } = connectionTarget();
1017
const api = new AtelierAPI(apiTarget);
11-
const { active, host = "", ns = "", https, port = 0, username, password } = api.config;
12-
if (host === "") {
13-
return vscode.commands.executeCommand("workbench.view.extension.ObjectScriptView");
18+
const { active, host = "", ns = "", https, port = 0, username, password, docker } = api.config;
19+
const explorerCount = (await explorerProvider.getChildren()).length;
20+
if (!explorerCount && (!docker || host === "")) {
21+
await vscode.commands.executeCommand("ObjectScriptExplorer.focus");
1422
}
1523
const { links } = config("conn");
1624
const nsEncoded = encodeURIComponent(ns);

src/explorer/explorer.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,8 @@ export class ObjectScriptExplorerProvider implements vscode.TreeDataProvider<Nod
6464
placeHolder: `Choose a namespace on ${api.config.host}:${api.config.port} to add to ObjectScript Explorer`,
6565
})
6666
)
67-
.then((ns) => this.showExtra4Workspace(workspaceFolder, ns.label));
67+
.then((ns) => this.showExtra4Workspace(workspaceFolder, ns.label))
68+
.catch(() => null);
6869
}
6970

7071
public showExtra4Workspace(workspaceFolder: string, ns: string): void {

src/explorer/models/nodeBase.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,6 @@ export class NodeBase {
3535
this.extraNode = extraNode;
3636
}
3737

38-
public get connInfo(): string {
39-
return `${this.conn.host}:${this.conn.port}[${this.namespace}]`;
40-
}
41-
4238
public getTreeItem(): vscode.TreeItem {
4339
return {
4440
collapsibleState: vscode.TreeItemCollapsibleState.None,

src/explorer/models/workspaceNode.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,17 @@ export class WorkspaceNode extends NodeBase {
1919
const flags = [];
2020
this.options.generated && flags.push(":generated:");
2121
this.options.system && flags.push(":system:");
22+
const { host, port, docker, dockerService } = this.conn;
23+
const serverInfo = docker
24+
? "docker" + (dockerService ? `:${dockerService}:${port}` : "")
25+
: `${host}${port ? ":" + port : ""}`;
26+
const connInfo = this.extraNode
27+
? `[${this.namespace}] on ${serverInfo}`
28+
: `${this.label} (${serverInfo}[${this.namespace}])`;
2229
return {
2330
collapsibleState: vscode.TreeItemCollapsibleState.Expanded,
2431
contextValue: `${this.uniqueId}${flags.join("")}`,
25-
label: this.extraNode
26-
? `[${this.namespace}] on ${this.conn.host}:${this.conn.port}`
27-
: `${this.label} (${this.connInfo})`,
32+
label: connInfo,
2833
iconPath: new vscode.ThemeIcon(this.extraNode ? "database" : "server-environment"),
2934
};
3035
}

src/extension.ts

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -201,12 +201,15 @@ export async function checkConnection(clearCookies = false, uri?: vscode.Uri): P
201201
let api = new AtelierAPI(apiTarget, false);
202202
const { active, host = "", port = 0, username, ns = "" } = api.config;
203203
vscode.commands.executeCommand("setContext", "vscode-objectscript.connectActive", active);
204+
if (!panel.text) {
205+
panel.text = `${PANEL_LABEL}`;
206+
}
204207
if (!host.length && !port && !ns.length) {
205208
panel.text = `${PANEL_LABEL}`;
206209
panel.tooltip = `No connection configured`;
207210
return;
208211
}
209-
let connInfo = `${host}:${port}[${ns}]`;
212+
let connInfo = api.connInfo;
210213
if (!active) {
211214
if (!host.length || !port || !ns.length) {
212215
connInfo = `incompletely specified server ${connInfo}`;
@@ -215,12 +218,12 @@ export async function checkConnection(clearCookies = false, uri?: vscode.Uri): P
215218
panel.tooltip = `Connection to ${connInfo} is disabled`;
216219
return;
217220
}
218-
panel.text = connInfo;
219-
panel.tooltip = `Connected as ${username}`;
221+
220222
if (!workspaceState.get(configName + ":port") && !api.externalServer) {
221223
try {
222-
const { port: dockerPort, docker: withDocker } = await portFromDockerCompose();
224+
const { port: dockerPort, docker: withDocker, service } = await portFromDockerCompose();
223225
workspaceState.update(configName + ":docker", withDocker);
226+
workspaceState.update(configName + ":dockerService", service);
224227
if (withDocker) {
225228
if (!dockerPort) {
226229
const errorMessage = `Something is wrong with your docker-compose connection settings, or your service is not running.`;
@@ -241,6 +244,8 @@ export async function checkConnection(clearCookies = false, uri?: vscode.Uri): P
241244
} catch (error) {
242245
outputChannel.appendError(error);
243246
workspaceState.update(configName + ":docker", true);
247+
panel.text = `${PANEL_LABEL} $(error)`;
248+
panel.tooltip = error;
244249
return;
245250
}
246251
}
@@ -262,6 +267,8 @@ export async function checkConnection(clearCookies = false, uri?: vscode.Uri): P
262267
api
263268
.serverInfo()
264269
.then((info) => {
270+
panel.text = api.connInfo;
271+
panel.tooltip = `Connected as ${username}`;
265272
const hasHS = info.result.content.features.find((el) => el.name === "HEALTHSHARE" && el.enabled) !== undefined;
266273
reporter &&
267274
reporter.sendTelemetryEvent("connected", {
@@ -454,12 +461,12 @@ export async function activate(context: vscode.ExtensionContext): Promise<any> {
454461
posPanel.show();
455462

456463
panel = vscode.window.createStatusBarItem(vscode.StatusBarAlignment.Left, 1);
457-
458-
const debugAdapterFactory = new ObjectScriptDebugAdapterDescriptorFactory();
459-
464+
panel.text = `${PANEL_LABEL}`;
460465
panel.command = "vscode-objectscript.serverActions";
461466
panel.show();
462467

468+
const debugAdapterFactory = new ObjectScriptDebugAdapterDescriptorFactory();
469+
463470
// Check one time (flushing cookies) each connection that is used by the workspace.
464471
// This gets any prompting for missing credentials done upfront, for simplicity.
465472
const toCheck = new Map<string, vscode.Uri>();
@@ -675,6 +682,8 @@ export async function activate(context: vscode.ExtensionContext): Promise<any> {
675682

676683
context.subscriptions.push(
677684
reporter,
685+
panel,
686+
posPanel,
678687
vscode.extensions.onDidChange(async () => {
679688
const languageServerExt2 = languageServer(false);
680689
if (typeof languageServerExt !== typeof languageServerExt2) {

src/providers/FileSystemPovider/TextSearchProvider.ts

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import * as vscode from "vscode";
22
import { SearchResult, SearchMatch } from "../../api/atelier";
33
import { AtelierAPI } from "../../api";
44
import { DocumentContentProvider } from "../DocumentContentProvider";
5+
import { outputChannel } from "../../utils";
56

67
export class TextSearchProvider implements vscode.TextSearchProvider {
78
/**
@@ -34,12 +35,16 @@ export class TextSearchProvider implements vscode.TextSearchProvider {
3435
files.map(async (file) => {
3536
const fileName = file.doc;
3637
const uri = DocumentContentProvider.getUri(fileName, "", "", true, options.folder);
37-
const document = await vscode.workspace.openTextDocument(uri);
38-
return {
39-
...file,
40-
uri,
41-
document,
42-
};
38+
try {
39+
const document = await vscode.workspace.openTextDocument(uri);
40+
return {
41+
...file,
42+
uri,
43+
document,
44+
};
45+
} catch (_ex) {
46+
return null;
47+
}
4348
})
4449
)
4550
.then((files) => Promise.all(files))
@@ -70,6 +75,10 @@ export class TextSearchProvider implements vscode.TextSearchProvider {
7075
});
7176
});
7277
return { limitHit: counter >= options.maxResults };
78+
})
79+
.catch((error) => {
80+
outputChannel.appendLine(error);
81+
return null;
7382
});
7483
}
7584
}

src/utils/index.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -255,13 +255,13 @@ export function notNull(el: any): boolean {
255255
return el !== null;
256256
}
257257

258-
export async function portFromDockerCompose(): Promise<{ port: number; docker: boolean }> {
258+
export async function portFromDockerCompose(): Promise<{ port: number; docker: boolean; service?: string }> {
259259
const { "docker-compose": dockerCompose = {} } = config("conn");
260260
const { service, file = "docker-compose.yml", internalPort = 52773, envFile } = dockerCompose;
261261
if (!internalPort || !file || !service || service === "") {
262262
return { docker: false, port: null };
263263
}
264-
const result = { port: null, docker: true };
264+
const result = { port: null, docker: true, service };
265265
const workspaceFolderPath = workspaceFolderUri().fsPath;
266266
const workspaceRootPath = vscode.workspace.workspaceFolders[0].uri.fsPath;
267267

@@ -305,7 +305,7 @@ export async function portFromDockerCompose(): Promise<{ port: number; docker: b
305305
if (!port) {
306306
reject(`Port ${internalPort} not published for service '${service}'.`);
307307
}
308-
resolve({ port: parseInt(port, 10), docker: true });
308+
resolve({ port: parseInt(port, 10), docker: true, service });
309309
});
310310
});
311311
});

0 commit comments

Comments
 (0)