Skip to content

Commit 1738d15

Browse files
author
Arnold Trakhtenberg
authored
Release 2.1.2 (#24)
* Update deps (#20) * upgrade dependencies * add resolution for lodash * don't install yarn * prettier * update tasks * remove devDep on yarn * Add null guard to flag autocompletion checks (#21) * add test case * don't install yarn * Add null guard to flag autocompletion checks * Clean up logging (#22) * upgrade dependencies * add resolution for lodash * don't install yarn * prettier * update tasks * remove devDep on yarn * use arrow function for lexical this scoping * clean up error logging * lint * use a warn instead of error * fix * use latest launchdarkly sdk (#23) * Prepare 2.1.2 * add extra check to null guard
1 parent caaa4dd commit 1738d15

File tree

9 files changed

+401
-602
lines changed

9 files changed

+401
-602
lines changed

.circleci/config.yml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,6 @@ jobs:
77
steps:
88
- checkout
99
- run: echo "Node version:" `node --version`
10-
- run:
11-
name: Install yarn globally
12-
command: 'sudo npm install -g yarn@latest'
1310
- restore_cache:
1411
key: dependency-cache-{{ checksum "package.json" }}
1512
- run:

.vscode/launch.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
"stopOnEntry": false,
1111
"sourceMaps": true,
1212
"outFiles": ["${workspaceRoot}/out/src/**/*.js"],
13-
"preLaunchTask": "npm"
13+
"preLaunchTask": "yarn"
1414
},
1515
{
1616
"name": "Launch Tests",
@@ -21,7 +21,7 @@
2121
"stopOnEntry": false,
2222
"sourceMaps": true,
2323
"outFiles": ["${workspaceRoot}/out/test/**/*.js"],
24-
"preLaunchTask": "npm"
24+
"preLaunchTask": "test-compile"
2525
}
2626
]
2727
}

.vscode/tasks.json

Lines changed: 25 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -8,23 +8,29 @@
88

99
// A task runner that calls a custom npm script that compiles the extension.
1010
{
11-
"version": "0.1.0",
12-
13-
// we want to run npm
14-
"command": "npm",
15-
16-
// the command is a shell script
17-
"isShellCommand": true,
18-
19-
// show the output window only if unrecognized errors occur.
20-
"showOutput": "silent",
21-
22-
// we run the custom script "compile" as defined in package.json
23-
"args": ["run", "compile", "--loglevel", "silent"],
24-
25-
// The tsc compiler is started in watching mode
26-
"isBackground": true,
27-
28-
// use the standard tsc in watch mode problem matcher to find compile problems in the output.
29-
"problemMatcher": "$tsc-watch"
11+
"version": "2.0.0",
12+
"tasks": [
13+
{
14+
"label": "yarn",
15+
"command": "yarn",
16+
"type": "shell",
17+
"presentation": {
18+
"reveal": "silent"
19+
},
20+
"args": ["run", "compile", "--loglevel", "silent"],
21+
"isBackground": true,
22+
"problemMatcher": "$tsc-watch"
23+
},
24+
{
25+
"label": "test-compile",
26+
"command": "yarn",
27+
"type": "shell",
28+
"presentation": {
29+
"reveal": "silent"
30+
},
31+
"args": ["test-compile"],
32+
"isBackground": true,
33+
"problemMatcher": "$tsc-watch"
34+
}
35+
]
3036
}

CHANGELOG.md

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

33
All notable changes to the "launchdarkly" extension will be documented in this file.
44

5+
## [2.1.2] - 2019-12-26
6+
7+
### Fixed
8+
9+
- Fixed an error log when cursor position was in an invalid state
10+
11+
### Changed
12+
- Cleaned up debug logging
13+
- The extension will no longer initially display a warning message when not configured.
14+
515
## [2.1.1] - 2019-06-24
616

717
### Changed

package.json

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "launchdarkly",
33
"displayName": "LaunchDarkly",
44
"description": "View LaunchDarkly feature flags in your editor.",
5-
"version": "2.1.1",
5+
"version": "2.1.2",
66
"publisher": "launchdarkly",
77
"engines": {
88
"vscode": "^1.34.0"
@@ -93,9 +93,9 @@
9393
"vscode:prepublish": "webpack --mode production",
9494
"compile": "webpack --mode none",
9595
"watch": "webpack --mode none --watch",
96-
"test-compile": "tsc -p ./",
96+
"test-compile": "tsc -p ./ && cp ./package.json ./out/package.json",
9797
"postinstall": "node ./node_modules/vscode/bin/install",
98-
"test": "yarn run prettier:check && yarn run test-compile && cp ./package.json ./out/package.json && node ./node_modules/vscode/bin/test",
98+
"test": "yarn run prettier:check && yarn run test-compile && node ./node_modules/vscode/bin/test",
9999
"prettier:write": "prettier --single-quote true --print-width 120 --use-tabs true --trailing-comma all --write \"{src,tests}/**/*.ts\"",
100100
"prettier:check": "prettier --single-quote true --print-width 120 --use-tabs true --trailing-comma all --list-different \"{src,tests}/**/*.ts\""
101101
},
@@ -109,19 +109,19 @@
109109
"typescript": "^2.4.2",
110110
"vscode": "^1.1.34",
111111
"webpack": "4.35.0",
112-
"webpack-cli": "3.3.5",
113-
"yarn": "^1.17.0"
112+
"webpack-cli": "3.3.5"
114113
},
115114
"dependencies": {
116115
"@types/lodash": "4.14.116",
117116
"@types/opn": "5.1.0",
118117
"eventsource": "^1.0.5",
119-
"ldclient-node": "^5.8.0",
118+
"launchdarkly-node-server-sdk": "5.10.0",
120119
"lodash.kebabcase": "4.1.1",
121120
"opn": "5.3.0",
122121
"request": "2.88.0"
123122
},
124123
"resolutions": {
125-
"node.extend": "^1.1.7"
124+
"node.extend": "^1.1.7",
125+
"lodash": "^4.17.12"
126126
}
127-
}
127+
}

src/flags.ts

Lines changed: 32 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import * as vscode from 'vscode';
22
import * as request from 'request';
33
import { kebabCase } from 'lodash';
4-
import { LDFlagValue, LDFeatureStore, LDStreamProcessor } from 'ldclient-node';
5-
import InMemoryFeatureStore = require('ldclient-node/feature_store');
6-
import StreamProcessor = require('ldclient-node/streaming');
7-
import Requestor = require('ldclient-node/requestor');
4+
import { LDFlagValue, LDFeatureStore, LDStreamProcessor } from 'launchdarkly-node-server-sdk';
5+
import InMemoryFeatureStore = require('launchdarkly-node-server-sdk/feature_store');
6+
import StreamProcessor = require('launchdarkly-node-server-sdk/streaming');
7+
import Requestor = require('launchdarkly-node-server-sdk/requestor');
88
import * as url from 'url';
99
import opn = require('opn');
1010

@@ -73,7 +73,11 @@ export function generateHoverString(flag: LDFlagValue) {
7373
Default variation: ${JSON.stringify(flag.variations[flag.fallthrough.variation])}
7474
Off variation: ${JSON.stringify(flag.variations[flag.offVariation])}
7575
${plural(flag.prerequisites.length, 'prerequisite', 'prerequisites')}
76-
${plural(flag.targets.reduce((acc, curr) => acc + curr.values.length, 0), 'user target', 'user targets')}
76+
${plural(
77+
flag.targets.reduce((acc, curr) => acc + curr.values.length, 0),
78+
'user target',
79+
'user targets',
80+
)}
7781
${plural(flag.rules.length, 'rule', 'rules')}`;
7882
}
7983

@@ -83,15 +87,17 @@ function plural(count: number, singular: string, plural: string) {
8387

8488
export function isPrecedingCharStringDelimeter(document: vscode.TextDocument, position: vscode.Position) {
8589
const range = document.getWordRangeAtPosition(position, FLAG_KEY_REGEX);
86-
90+
if (!range || !range.start || range.start.character === 0) {
91+
return false;
92+
}
8793
const c = new vscode.Range(
8894
range.start.line,
8995
candidateTextStartLocation(range.start.character),
9096
range.start.line,
9197
range.start.character,
9298
);
9399
const candidate = document.getText(c).trim();
94-
return STRING_DELIMETERS.indexOf(candidate) >= 0;
100+
return STRING_DELIMETERS.indexOf(candidate) !== -1;
95101
}
96102

97103
const candidateTextStartLocation = (char: number) => (char === 1 ? 0 : char - 2);
@@ -109,30 +115,29 @@ export class LDFlagManager implements IFlagManager {
109115
constructor(ctx: vscode.ExtensionContext, settings: IConfiguration) {
110116
this.settings = Object.assign({}, settings);
111117
let config = this.config(settings);
112-
if (settings.sdkKey) {
113-
this.updateProcessor = StreamProcessor(settings.sdkKey, config, Requestor(settings.sdkKey, config));
114-
this.start();
115-
} else {
116-
vscode.window.showWarningMessage(
117-
'[LaunchDarkly] sdkKey is not set. LaunchDarkly language support is unavailable.',
118-
);
118+
if (!settings.sdkKey) {
119+
console.warn('LaunchDarkly sdkKey is not set. Language support is unavailable.');
120+
return;
119121
}
122+
123+
this.updateProcessor = StreamProcessor(settings.sdkKey, config, Requestor(settings.sdkKey, config));
124+
this.start();
120125
}
121126

122127
start() {
123128
this.updateProcessor &&
124-
this.updateProcessor.start(function(err) {
129+
this.updateProcessor.start(err => {
125130
if (err) {
126-
console.log(err);
127-
let errMsg = `[LaunchDarkly] Unexpected error retrieving flags.${
128-
this.settings.baseUri != DEFAULT_BASE_URI || this.settings.streamUri != DEFAULT_STREAM_URI
129-
? ' Please make sure your configured base and stream URIs are correct'
130-
: ''
131-
}`;
132-
vscode.window.showErrorMessage(errMsg);
133-
} else {
134-
process.nextTick(function() {});
131+
let errMsg;
132+
if (err.message) {
133+
errMsg = `Error retrieving feature flags: ${err.message}.`;
134+
} else {
135+
console.error(err);
136+
errMsg = `Unexpected error retrieving flags.`;
137+
}
138+
vscode.window.showErrorMessage(`[LaunchDarkly] ${errMsg}`);
135139
}
140+
process.nextTick(function() {});
136141
});
137142
}
138143

@@ -157,9 +162,9 @@ export class LDFlagManager implements IFlagManager {
157162
streamUri: settings.streamUri,
158163
featureStore: this.store,
159164
logger: {
160-
debug: msg => {
161-
console.log(msg);
162-
},
165+
debug: console.log,
166+
warn: console.warn,
167+
error: console.error,
163168
},
164169
userAgent: 'VSCodeExtension/' + package_json.version,
165170
};

test/flags.test.ts

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,41 +26,53 @@ suite('flags tests', () => {
2626
);
2727
});
2828

29-
test('isPrecedingCharStringDelimeter', () => {
30-
let uri = vscode.Uri.file(path.join(testPath, 'test.txt'));
29+
test('isPrecedingCharStringDelimeter', async () => {
30+
// TODO: generate the test data in this file
31+
const uri = vscode.Uri.file(path.join(testPath, 'test.txt'));
3132
const tests = [
3233
{
34+
name: "single-quote delim",
3335
expected: true,
3436
line: 0,
3537
char: 1,
3638
},
3739
{
40+
name: "double-quote delim",
3841
expected: true,
3942
line: 1,
4043
char: 1,
4144
},
4245
{
46+
name: "backtick delim",
4347
expected: true,
4448
line: 2,
4549
char: 1,
4650
},
4751
{
52+
name: "not start of line",
4853
expected: true,
4954
line: 3,
5055
char: 2,
5156
},
5257
{
58+
name: "delim preceded by another char",
5359
expected: false,
5460
line: 4,
5561
char: 2,
5662
},
63+
{
64+
name: "doesn't match flag key regex",
65+
expected: false,
66+
line: 6,
67+
char: 2,
68+
}
5769
];
5870

59-
vscode.workspace.openTextDocument(uri).then(document => {
60-
tests.forEach(t => {
61-
let pos = new vscode.Position(t.line, t.char);
62-
assert.equal(flags.isPrecedingCharStringDelimeter(document, pos), t.expected);
63-
});
71+
const document = await vscode.workspace.openTextDocument(uri);
72+
tests.forEach(t => {
73+
const pos = new vscode.Position(t.line, t.char);
74+
assert.equal(flags.isPrecedingCharStringDelimeter(document, pos), t.expected, t.name);
6475
});
76+
6577
});
6678
});

test/test.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,5 @@
33
`someFlagKey`
44
'someFlagKey'
55
a'someFlagKey'
6+
'someFlagKey'a
7+
%$#$^

0 commit comments

Comments
 (0)