Skip to content

Commit

Permalink
Merge pull request #393 from KxSystems/fix-unnamed-alias
Browse files Browse the repository at this point in the history
Fix unnamed alias
  • Loading branch information
Philip-Carneiro-KX authored Aug 6, 2024
2 parents b7a244a + d607c8f commit e482e5a
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 1 deletion.
3 changes: 3 additions & 0 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ import { KdbResultsViewProvider } from "./services/resultsPanelProvider";
import {
checkLocalInstall,
checkOpenSslInstalled,
fixUnnamedAlias,
getInsights,
getServers,
initializeLocalServers,
Expand Down Expand Up @@ -147,6 +148,8 @@ export async function activate(context: ExtensionContext) {
"datasource",
);

fixUnnamedAlias();

commands.executeCommand("setContext", "kdb.QHOME", env.QHOME);

window.registerTreeDataProvider("kdb-servers", ext.serverProvider);
Expand Down
40 changes: 40 additions & 0 deletions src/utils/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,46 @@ export function getServers(): Server | undefined {
return workspace.getConfiguration().get("kdb.servers");
}

// TODO: Remove this on 1.9.0 release
/* istanbul ignore next */
export function fixUnnamedAlias(): void {
const servers = getServers();
const insights = getInsights();
let counter = 1;

if (servers) {
const updatedServers: Server = {};
for (const key in servers) {
if (servers.hasOwnProperty(key)) {
const server = servers[key];
if (server.serverAlias === "") {
server.serverAlias = `unnamedServer-${counter}`;
counter++;
}
updatedServers[server.serverAlias] = server;
}
}
updateServers(updatedServers);
ext.serverProvider.refresh(servers);
}

if (insights) {
const updatedInsights: Insights = {};
for (const key in insights) {
if (insights.hasOwnProperty(key)) {
const insight = insights[key];
if (insight.alias === "") {
insight.alias = `unnamedServer-${counter}`;
counter++;
}
updatedInsights[insight.alias] = insight;
}
}
updateInsights(updatedInsights);
ext.serverProvider.refreshInsights(insights);
}
}

export function getHideDetailedConsoleQueryOutput(): void {
const setting = workspace
.getConfiguration()
Expand Down
1 change: 0 additions & 1 deletion test/suite/commands.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ import { WorkspaceTreeProvider } from "../../src/services/workspaceTreeProvider"
import { GetDataError } from "../../src/models/data";
import * as clientCommand from "../../src/commands/clientCommands";
import { LanguageClient } from "vscode-languageclient/node";
import { MetaContentProvider } from "../../src/services/metaContentProvider";

describe("dataSourceCommand", () => {
afterEach(() => {
Expand Down

0 comments on commit e482e5a

Please sign in to comment.