Skip to content

Commit a06c6cc

Browse files
add quick fix for 1.13.1
1 parent 8a0e344 commit a06c6cc

File tree

5 files changed

+65
-47
lines changed

5 files changed

+65
-47
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@
22

33
All notable changes to the **kdb VS Code extension** are documented in this file.
44

5+
# v1.13.1
6+
7+
### Fixes
8+
9+
- Fixed issue with corrupted settings for VSCode
10+
511
# v1.13.0
612

713
### Enhancements

package-lock.json

Lines changed: 2 additions & 2 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
@@ -3,7 +3,7 @@
33
"displayName": "kdb",
44
"description": "IDE support for kdb product suite including the q programming language",
55
"publisher": "KX",
6-
"version": "1.13.0",
6+
"version": "1.13.1",
77
"engines": {
88
"vscode": "^1.96.0"
99
},

src/utils/core.ts

Lines changed: 28 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -244,16 +244,20 @@ export async function getWorkspaceFolder(
244244
return undefined;
245245
}
246246

247-
export function getServers(): Server | undefined {
247+
export function getServers(): Server {
248248
const servers = workspace.getConfiguration().get<Server>("kdb.servers");
249249

250+
if (!servers) {
251+
updateServers({});
252+
}
253+
250254
return servers
251255
? Object.fromEntries(
252256
Object.entries(servers).sort(([, a], [, b]) =>
253257
a.serverAlias.localeCompare(b.serverAlias),
254258
),
255259
)
256-
: servers;
260+
: {};
257261
}
258262

259263
// TODO: Remove this on 1.9.0 release
@@ -328,28 +332,36 @@ export function setOutputWordWrapper(): void {
328332
}
329333
}
330334

331-
export function getInsights(): Insights | undefined {
335+
export function getInsights(): Insights {
332336
const configuration = workspace.getConfiguration();
333337
const insights = configuration.get<Insights>(
334338
"kdb.insightsEnterpriseConnections",
335339
);
336340

337-
const insightsList: Insights | undefined =
338-
insights && Object.keys(insights).length > 0
339-
? insights
340-
: configuration.get("kdb.insights");
341-
342-
if (!insightsList || Object.keys(insightsList).length === 0) {
343-
return undefined;
344-
}
345-
346-
return insightsList
347-
? Object.fromEntries(
341+
if (insights && Object.keys(insights).length > 0) {
342+
return Object.fromEntries(
343+
Object.entries(insights).sort(([, a], [, b]) =>
344+
a.alias.localeCompare(b.alias),
345+
),
346+
);
347+
} else {
348+
const insightsList = configuration.get<Insights>("kdb.insights");
349+
if (insightsList && Object.keys(insightsList).length > 0) {
350+
updateInsights(insightsList);
351+
configuration.update(
352+
"kdb.insights",
353+
undefined,
354+
ConfigurationTarget.Global,
355+
);
356+
return Object.fromEntries(
348357
Object.entries(insightsList).sort(([, a], [, b]) =>
349358
a.alias.localeCompare(b.alias),
350359
),
351-
)
352-
: insightsList;
360+
);
361+
}
362+
updateInsights({});
363+
return {};
364+
}
353365
}
354366

355367
export async function updateServers(servers: Server): Promise<void> {

test/suite/utils.test.ts

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -361,13 +361,16 @@ describe("Utils", () => {
361361
});
362362

363363
describe("getServers", () => {
364-
let workspaceStub: sinon.SinonStub;
365-
let _getConfigurationStub: sinon.SinonStub;
366-
let getStub: sinon.SinonStub;
364+
let workspaceStub,
365+
_getConfigurationStub,
366+
getStub,
367+
updateServersStub: sinon.SinonStub;
367368

368369
beforeEach(() => {
369370
getStub = sinon.stub();
370-
_getConfigurationStub = sinon.stub().returns({ get: getStub });
371+
_getConfigurationStub = sinon
372+
.stub()
373+
.returns({ get: getStub, update: sinon.stub() });
371374
workspaceStub = sinon
372375
.stub(vscode.workspace, "getConfiguration")
373376
.returns({
@@ -403,18 +406,19 @@ describe("Utils", () => {
403406
throw new Error("Function not implemented.");
404407
},
405408
});
409+
updateServersStub = sinon.stub(coreUtils, "updateServers").resolves();
406410
});
407411

408412
afterEach(() => {
409413
sinon.restore();
410414
});
411415

412-
it("should return undefined when no servers are configured", () => {
413-
getStub.returns(undefined);
414-
416+
it("should return an empty object when no servers are configured", () => {
417+
getStub.returns({});
415418
const result = coreUtils.getServers();
416419

417-
assert.strictEqual(result, undefined);
420+
assert.ok(typeof result === "object");
421+
assert.strictEqual(Object.keys(result).length, 0);
418422
assert.ok(getStub.calledWith("kdb.servers"));
419423
});
420424

@@ -580,7 +584,7 @@ describe("Utils", () => {
580584

581585
coreUtils.getServers();
582586

583-
assert.ok(workspaceStub.calledOnce);
587+
assert.ok(workspaceStub.calledTwice);
584588
assert.ok(workspaceStub.calledWith());
585589
});
586590

@@ -595,13 +599,16 @@ describe("Utils", () => {
595599
});
596600

597601
describe("getInsights", () => {
598-
let workspaceStub: sinon.SinonStub;
599-
let _getConfigurationStub: sinon.SinonStub;
600-
let getStub: sinon.SinonStub;
602+
let workspaceStub,
603+
_getConfigurationStub,
604+
getStub,
605+
updateInsightsStub: sinon.SinonStub;
601606

602607
beforeEach(() => {
603608
getStub = sinon.stub();
604-
_getConfigurationStub = sinon.stub().returns({ get: getStub });
609+
_getConfigurationStub = sinon
610+
.stub()
611+
.returns({ get: getStub, update: sinon.stub() });
605612
workspaceStub = sinon
606613
.stub(vscode.workspace, "getConfiguration")
607614
.returns({
@@ -625,18 +632,9 @@ describe("Utils", () => {
625632
| undefined {
626633
throw new Error("Function not implemented.");
627634
},
628-
update: function (
629-
_section: string,
630-
_value: any,
631-
_configurationTarget?:
632-
| vscode.ConfigurationTarget
633-
| boolean
634-
| null,
635-
_overrideInLanguage?: boolean,
636-
): Thenable<void> {
637-
throw new Error("Function not implemented.");
638-
},
635+
update: sinon.stub(),
639636
});
637+
updateInsightsStub = sinon.stub(coreUtils, "updateInsights").resolves();
640638
});
641639

642640
afterEach(() => {
@@ -651,7 +649,8 @@ describe("Utils", () => {
651649

652650
const result = coreUtils.getInsights();
653651

654-
assert.strictEqual(result, undefined);
652+
assert.ok(typeof result === "object");
653+
assert.strictEqual(Object.keys(result).length, 0);
655654
assert.ok(getStub.calledWith("kdb.insightsEnterpriseConnections"));
656655
assert.ok(getStub.calledWith("kdb.insights"));
657656
});
@@ -767,13 +766,14 @@ describe("Utils", () => {
767766
assert.ok(getStub.calledWith("kdb.insights"));
768767
});
769768

770-
it("should return undefined when both sources are empty", () => {
769+
it("should return empty object when both sources are empty", () => {
771770
getStub.withArgs("kdb.insightsEnterpriseConnections").returns({});
772771
getStub.withArgs("kdb.insights").returns({});
773772

774773
const result = coreUtils.getInsights();
775774

776-
assert.strictEqual(result, undefined);
775+
assert.ok(typeof result === "object");
776+
assert.strictEqual(Object.keys(result).length, 0);
777777
assert.ok(getStub.calledWith("kdb.insightsEnterpriseConnections"));
778778
assert.ok(getStub.calledWith("kdb.insights"));
779779
});
@@ -913,7 +913,7 @@ describe("Utils", () => {
913913

914914
coreUtils.getInsights();
915915

916-
assert.ok(workspaceStub.calledOnce);
916+
assert.ok(workspaceStub.calledTwice);
917917
assert.ok(workspaceStub.calledWith());
918918
});
919919

0 commit comments

Comments
 (0)