Skip to content

Commit 04f04da

Browse files
authored
Show servers defined in workspace folder settings in Current tree UI (#273)
1 parent a3e94a6 commit 04f04da

File tree

5 files changed

+32
-20
lines changed

5 files changed

+32
-20
lines changed

package-lock.json

Lines changed: 7 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@
5353
"node-cmd": "^5.0.0"
5454
},
5555
"devDependencies": {
56-
"@intersystems-community/intersystems-servermanager": "^3.8.0",
56+
"@intersystems-community/intersystems-servermanager": "^3.10.2",
5757
"@types/glob": "^7.1.1",
5858
"@types/mocha": "^9.0.0",
5959
"@types/node": "^20.14.0",

src/api/getServerSummary.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ export function getServerSummary(name: string, scope?: vscode.ConfigurationScope
88
if (!server) {
99
return undefined;
1010
}
11-
return { name, description: server.description || "", detail: serverDetail(server) };
11+
return { name, description: server.description || "", detail: serverDetail(server), scope };
1212
}
1313

1414
export function serverDetail(connSpec: IServerSpec): string {

src/commonActivate.ts

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,8 @@ export function commonActivate(context: vscode.ExtensionContext, view: ServerMan
170170
vscode.commands.registerCommand(`${extensionId}.editSettings`, (server?: ServerTreeItem) => {
171171
// Attempt to open the correct JSON file
172172
server = server instanceof ServerTreeItem ? server : undefined;
173-
const servers = vscode.workspace.getConfiguration("intersystems").inspect<{ [key: string]: any }>("servers");
173+
const scope: vscode.ConfigurationScope = server?.params?.serverSummary?.scope;
174+
const servers = vscode.workspace.getConfiguration("intersystems", scope).inspect<{ [key: string]: any }>("servers");
174175
const openJSONArg = { revealSetting: { key: "intersystems.servers" } };
175176
const revealServer = (): void => {
176177
// Find the start of the server's settings block
@@ -191,7 +192,19 @@ export function commonActivate(context: vscode.ExtensionContext, view: ServerMan
191192
}
192193
}
193194
};
194-
if (server && servers?.workspaceValue?.hasOwnProperty(server.name)) {
195+
// Only WorkspaceFolder objects have an index.
196+
if (server && servers?.workspaceFolderValue?.hasOwnProperty(server.name) && typeof (<vscode.WorkspaceFolder>scope)?.index == "number") {
197+
// Open the workspace folder settings file. Need to use showTextDocument because the
198+
// "workbench.action.openFolderSettingsFile" command always prompts the user.
199+
vscode.window.showTextDocument(
200+
vscode.Uri.joinPath((<vscode.WorkspaceFolder>scope).uri, ".vscode", "settings.json"),
201+
// Need these two properties to mimic the workbench commands' behavior
202+
{ preview: false, selection: new vscode.Range(0, 0, 0, 0) }
203+
).then(revealServer, () => {
204+
// If there's an error, fall back to showing the UI
205+
vscode.commands.executeCommand("workbench.action.openSettings", `@ext:${extensionId}`);
206+
});
207+
} else if (server && servers?.workspaceValue?.hasOwnProperty(server.name)) {
195208
// Open the workspace settings file
196209
vscode.commands.executeCommand("workbench.action.openWorkspaceSettingsFile", openJSONArg).then(revealServer);
197210
} else if (server && servers?.globalValue?.hasOwnProperty(server.name)) {

src/ui/serverManagerView.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ export class SMTreeItem extends vscode.TreeItem {
230230
public readonly parent: SMTreeItem | undefined;
231231
// tslint:disable-next-line: ban-types
232232
private readonly _getChildren?: Function;
233-
private readonly _params?: any;
233+
public readonly params?: any;
234234

235235
constructor(item: ISMItem) {
236236
const collapsibleState = item.getChildren
@@ -247,12 +247,12 @@ export class SMTreeItem extends vscode.TreeItem {
247247
this.iconPath = new vscode.ThemeIcon(item.codiconName);
248248
}
249249
this._getChildren = item.getChildren;
250-
this._params = item.params;
250+
this.params = item.params;
251251
}
252252

253253
public async getChildren(): Promise<SMTreeItem[] | undefined> {
254254
if (this._getChildren) {
255-
return await this._getChildren(this, this._params);
255+
return await this._getChildren(this, this.params);
256256
} else {
257257
return;
258258
}
@@ -280,7 +280,7 @@ async function currentServers(element: SMTreeItem, params?: any): Promise<Server
280280
await Promise.all(workspaceFolders.map(async (folder) => {
281281
const serverName = folder.uri.authority.split(":")[0];
282282
if (["isfs", "isfs-readonly"].includes(folder.uri.scheme)) {
283-
const serverSummary = getServerSummary(serverName);
283+
const serverSummary = getServerSummary(serverName, folder);
284284
if (serverSummary) {
285285
children.set(
286286
serverName,
@@ -306,7 +306,7 @@ async function currentServers(element: SMTreeItem, params?: any): Promise<Server
306306
}
307307
}
308308
else if (connServer) {
309-
const serverSummary = getServerSummary(connServer);
309+
const serverSummary = getServerSummary(connServer, folder);
310310
if (serverSummary) {
311311
children.set(
312312
connServer,
@@ -369,7 +369,7 @@ export class ServerTreeItem extends SMTreeItem {
369369
.replace(/[\n\t]/g, " ")
370370
.replace(/[\r\f\b]/g, "")
371371
.replace(/[\\`*_{}[\]()#+\-.!]/g, "\\$&")
372-
.substr(0, 90)
372+
.slice(0, 90)
373373
.trim();
374374
// Wrap detail (a uri string) as a null link to prevent it from being linkified
375375
const wrappedDetail = `[${serverSummary.detail}]()`;
@@ -428,12 +428,12 @@ async function serverFeatures(element: ServerTreeItem, params?: any): Promise<Fe
428428
}
429429

430430
async function specFromServerSummary(serverSummary: IServerName): Promise<IServerSpec | undefined> {
431-
const { name, description, detail } = serverSummary;
431+
const { name, description, detail, scope } = serverSummary;
432432
const dockerDetail = detail.match(/^http:\/\/localhost:(\d+)\/$/);
433433
if (dockerDetail) {
434434
return { name, description, webServer: { scheme: "http", host: "127.0.0.1", port: parseInt(dockerDetail[1], 10), pathPrefix: "" } };
435435
}
436-
return getServerSpec(name);
436+
return getServerSpec(name, scope);
437437
}
438438

439439
// tslint:disable-next-line: max-classes-per-file

0 commit comments

Comments
 (0)