Skip to content

Commit b0fc51a

Browse files
author
Tim Etchells
committed
Write connections to ExtensionContext not Settings
Fixes #22
1 parent cee8439 commit b0fc51a

File tree

6 files changed

+15
-14
lines changed

6 files changed

+15
-14
lines changed

dev/package.json

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,6 @@
4040
"type": "object",
4141
"title": "Microclimate Tools",
4242
"properties": {
43-
"microclimate.connections": {
44-
"type": "array",
45-
"default": [],
46-
"description": "%settingDesc_connections%"
47-
},
4843
"microclimate.openLogsOnChange.app": {
4944
"type": "boolean",
5045
"default": false,

dev/package.nls.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,6 @@
9898
"cmdID_validate": "ext.mc.validate",
9999
"cmdTitle_validate": "Validate",
100100

101-
"settingDesc_connections": "URLs of Microclimate instances to connect to. Not intended to be manually edited.",
102101
"settingDesc_showLogOnChange_app": "When a Microclimate project's open application logs change, bring that log to the front",
103102
"settingDesc_showLogOnChange_build": "When a Microclimate project's open build logs change, bring that log to the front",
104103

dev/src/extension.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ export async function activate(context: vscode.ExtensionContext): Promise<void>
2727

2828
// Initialize our globals
2929
global.__extRoot = context.extensionPath;
30+
// Declared as 'any' type, but will always be assigned globalState which is a vscode.Memento
31+
global.extGlobalState = context.globalState;
32+
3033
Log.setLogFilePath(context);
3134
Log.i("Finished activating logger");
3235

dev/src/global.d.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2018 IBM Corporation and others.
2+
* Copyright (c) 2018, 2019 IBM Corporation and others.
33
* All rights reserved. This program and the accompanying materials
44
* are made available under the terms of the Eclipse Public License v2.0
55
* which accompanies this distribution, and is available at
@@ -21,6 +21,11 @@ declare namespace NodeJS {
2121
// so files don't each have to write their own logic to locate it using relative paths.
2222
// This is the folder which contains /src and /res, for example.
2323
__extRoot: string,
24+
25+
// For some reason, importing anything at the top of this file causes all the properties declared here to not work anymore.
26+
// So, we use 'any' for extGlobalState - but it's a vscode.Memento.
27+
// extGlobalState: vscode.Memento
28+
extGlobalState: any
2429
}
2530
}
2631

dev/src/microclimate/connection/ConnectionManager.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -143,10 +143,8 @@ export default class ConnectionManager {
143143
}
144144

145145
public static loadConnections(): MCUtil.IConnectionInfo[] {
146-
const loaded = vscode.workspace.getConfiguration(Settings.CONFIG_SECTION)
147-
.get(Settings.CONNECTIONS_KEY, []);
148-
149-
// Logger.log("LOADED CONNECTIONS", loaded);
146+
const globalState = global.extGlobalState as vscode.Memento;
147+
const loaded = globalState.get<MCUtil.IConnectionInfo[]>(Settings.CONNECTIONS_KEY) || [];
150148
return loaded;
151149
}
152150

@@ -158,8 +156,9 @@ export default class ConnectionManager {
158156

159157
Log.i("Saving connections", connectionInfos);
160158
try {
161-
return vscode.workspace.getConfiguration(Settings.CONFIG_SECTION)
162-
.update(Settings.CONNECTIONS_KEY, connectionInfos, vscode.ConfigurationTarget.Global);
159+
const globalState = global.extGlobalState as vscode.Memento;
160+
// connectionInfos must not contain cyclic references (ie, JSON.stringify succeeds)
161+
await globalState.update(Settings.CONNECTIONS_KEY, connectionInfos);
163162
}
164163
catch (err) {
165164
const msg = Translator.t(StringNamespaces.DEFAULT, "errorSavingConnections", { err: err.toString() });

dev/src/microclimate/project/Requester.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2019 IBM Corporation and others.
2+
* Copyright (c) 2018, 2019 IBM Corporation and others.
33
* All rights reserved. This program and the accompanying materials
44
* are made available under the terms of the Eclipse Public License v2.0
55
* which accompanies this distribution, and is available at

0 commit comments

Comments
 (0)