Skip to content

Commit

Permalink
Release 2.1.2 (#24)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
Arnold Trakhtenberg authored Dec 27, 2019
1 parent caaa4dd commit 1738d15
Show file tree
Hide file tree
Showing 9 changed files with 401 additions and 602 deletions.
3 changes: 0 additions & 3 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@ jobs:
steps:
- checkout
- run: echo "Node version:" `node --version`
- run:
name: Install yarn globally
command: 'sudo npm install -g yarn@latest'
- restore_cache:
key: dependency-cache-{{ checksum "package.json" }}
- run:
Expand Down
4 changes: 2 additions & 2 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"stopOnEntry": false,
"sourceMaps": true,
"outFiles": ["${workspaceRoot}/out/src/**/*.js"],
"preLaunchTask": "npm"
"preLaunchTask": "yarn"
},
{
"name": "Launch Tests",
Expand All @@ -21,7 +21,7 @@
"stopOnEntry": false,
"sourceMaps": true,
"outFiles": ["${workspaceRoot}/out/test/**/*.js"],
"preLaunchTask": "npm"
"preLaunchTask": "test-compile"
}
]
}
44 changes: 25 additions & 19 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,29 @@

// A task runner that calls a custom npm script that compiles the extension.
{
"version": "0.1.0",

// we want to run npm
"command": "npm",

// the command is a shell script
"isShellCommand": true,

// show the output window only if unrecognized errors occur.
"showOutput": "silent",

// we run the custom script "compile" as defined in package.json
"args": ["run", "compile", "--loglevel", "silent"],

// The tsc compiler is started in watching mode
"isBackground": true,

// use the standard tsc in watch mode problem matcher to find compile problems in the output.
"problemMatcher": "$tsc-watch"
"version": "2.0.0",
"tasks": [
{
"label": "yarn",
"command": "yarn",
"type": "shell",
"presentation": {
"reveal": "silent"
},
"args": ["run", "compile", "--loglevel", "silent"],
"isBackground": true,
"problemMatcher": "$tsc-watch"
},
{
"label": "test-compile",
"command": "yarn",
"type": "shell",
"presentation": {
"reveal": "silent"
},
"args": ["test-compile"],
"isBackground": true,
"problemMatcher": "$tsc-watch"
}
]
}
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,16 @@

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

## [2.1.2] - 2019-12-26

### Fixed

- Fixed an error log when cursor position was in an invalid state

### Changed
- Cleaned up debug logging
- The extension will no longer initially display a warning message when not configured.

## [2.1.1] - 2019-06-24

### Changed
Expand Down
16 changes: 8 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "launchdarkly",
"displayName": "LaunchDarkly",
"description": "View LaunchDarkly feature flags in your editor.",
"version": "2.1.1",
"version": "2.1.2",
"publisher": "launchdarkly",
"engines": {
"vscode": "^1.34.0"
Expand Down Expand Up @@ -93,9 +93,9 @@
"vscode:prepublish": "webpack --mode production",
"compile": "webpack --mode none",
"watch": "webpack --mode none --watch",
"test-compile": "tsc -p ./",
"test-compile": "tsc -p ./ && cp ./package.json ./out/package.json",
"postinstall": "node ./node_modules/vscode/bin/install",
"test": "yarn run prettier:check && yarn run test-compile && cp ./package.json ./out/package.json && node ./node_modules/vscode/bin/test",
"test": "yarn run prettier:check && yarn run test-compile && node ./node_modules/vscode/bin/test",
"prettier:write": "prettier --single-quote true --print-width 120 --use-tabs true --trailing-comma all --write \"{src,tests}/**/*.ts\"",
"prettier:check": "prettier --single-quote true --print-width 120 --use-tabs true --trailing-comma all --list-different \"{src,tests}/**/*.ts\""
},
Expand All @@ -109,19 +109,19 @@
"typescript": "^2.4.2",
"vscode": "^1.1.34",
"webpack": "4.35.0",
"webpack-cli": "3.3.5",
"yarn": "^1.17.0"
"webpack-cli": "3.3.5"
},
"dependencies": {
"@types/lodash": "4.14.116",
"@types/opn": "5.1.0",
"eventsource": "^1.0.5",
"ldclient-node": "^5.8.0",
"launchdarkly-node-server-sdk": "5.10.0",
"lodash.kebabcase": "4.1.1",
"opn": "5.3.0",
"request": "2.88.0"
},
"resolutions": {
"node.extend": "^1.1.7"
"node.extend": "^1.1.7",
"lodash": "^4.17.12"
}
}
}
59 changes: 32 additions & 27 deletions src/flags.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import * as vscode from 'vscode';
import * as request from 'request';
import { kebabCase } from 'lodash';
import { LDFlagValue, LDFeatureStore, LDStreamProcessor } from 'ldclient-node';
import InMemoryFeatureStore = require('ldclient-node/feature_store');
import StreamProcessor = require('ldclient-node/streaming');
import Requestor = require('ldclient-node/requestor');
import { LDFlagValue, LDFeatureStore, LDStreamProcessor } from 'launchdarkly-node-server-sdk';
import InMemoryFeatureStore = require('launchdarkly-node-server-sdk/feature_store');
import StreamProcessor = require('launchdarkly-node-server-sdk/streaming');
import Requestor = require('launchdarkly-node-server-sdk/requestor');
import * as url from 'url';
import opn = require('opn');

Expand Down Expand Up @@ -73,7 +73,11 @@ export function generateHoverString(flag: LDFlagValue) {
Default variation: ${JSON.stringify(flag.variations[flag.fallthrough.variation])}
Off variation: ${JSON.stringify(flag.variations[flag.offVariation])}
${plural(flag.prerequisites.length, 'prerequisite', 'prerequisites')}
${plural(flag.targets.reduce((acc, curr) => acc + curr.values.length, 0), 'user target', 'user targets')}
${plural(
flag.targets.reduce((acc, curr) => acc + curr.values.length, 0),
'user target',
'user targets',
)}
${plural(flag.rules.length, 'rule', 'rules')}`;
}

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

export function isPrecedingCharStringDelimeter(document: vscode.TextDocument, position: vscode.Position) {
const range = document.getWordRangeAtPosition(position, FLAG_KEY_REGEX);

if (!range || !range.start || range.start.character === 0) {
return false;
}
const c = new vscode.Range(
range.start.line,
candidateTextStartLocation(range.start.character),
range.start.line,
range.start.character,
);
const candidate = document.getText(c).trim();
return STRING_DELIMETERS.indexOf(candidate) >= 0;
return STRING_DELIMETERS.indexOf(candidate) !== -1;
}

const candidateTextStartLocation = (char: number) => (char === 1 ? 0 : char - 2);
Expand All @@ -109,30 +115,29 @@ export class LDFlagManager implements IFlagManager {
constructor(ctx: vscode.ExtensionContext, settings: IConfiguration) {
this.settings = Object.assign({}, settings);
let config = this.config(settings);
if (settings.sdkKey) {
this.updateProcessor = StreamProcessor(settings.sdkKey, config, Requestor(settings.sdkKey, config));
this.start();
} else {
vscode.window.showWarningMessage(
'[LaunchDarkly] sdkKey is not set. LaunchDarkly language support is unavailable.',
);
if (!settings.sdkKey) {
console.warn('LaunchDarkly sdkKey is not set. Language support is unavailable.');
return;
}

this.updateProcessor = StreamProcessor(settings.sdkKey, config, Requestor(settings.sdkKey, config));
this.start();
}

start() {
this.updateProcessor &&
this.updateProcessor.start(function(err) {
this.updateProcessor.start(err => {
if (err) {
console.log(err);
let errMsg = `[LaunchDarkly] Unexpected error retrieving flags.${
this.settings.baseUri != DEFAULT_BASE_URI || this.settings.streamUri != DEFAULT_STREAM_URI
? ' Please make sure your configured base and stream URIs are correct'
: ''
}`;
vscode.window.showErrorMessage(errMsg);
} else {
process.nextTick(function() {});
let errMsg;
if (err.message) {
errMsg = `Error retrieving feature flags: ${err.message}.`;
} else {
console.error(err);
errMsg = `Unexpected error retrieving flags.`;
}
vscode.window.showErrorMessage(`[LaunchDarkly] ${errMsg}`);
}
process.nextTick(function() {});
});
}

Expand All @@ -157,9 +162,9 @@ export class LDFlagManager implements IFlagManager {
streamUri: settings.streamUri,
featureStore: this.store,
logger: {
debug: msg => {
console.log(msg);
},
debug: console.log,
warn: console.warn,
error: console.error,
},
userAgent: 'VSCodeExtension/' + package_json.version,
};
Expand Down
26 changes: 19 additions & 7 deletions test/flags.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,41 +26,53 @@ suite('flags tests', () => {
);
});

test('isPrecedingCharStringDelimeter', () => {
let uri = vscode.Uri.file(path.join(testPath, 'test.txt'));
test('isPrecedingCharStringDelimeter', async () => {
// TODO: generate the test data in this file
const uri = vscode.Uri.file(path.join(testPath, 'test.txt'));
const tests = [
{
name: "single-quote delim",
expected: true,
line: 0,
char: 1,
},
{
name: "double-quote delim",
expected: true,
line: 1,
char: 1,
},
{
name: "backtick delim",
expected: true,
line: 2,
char: 1,
},
{
name: "not start of line",
expected: true,
line: 3,
char: 2,
},
{
name: "delim preceded by another char",
expected: false,
line: 4,
char: 2,
},
{
name: "doesn't match flag key regex",
expected: false,
line: 6,
char: 2,
}
];

vscode.workspace.openTextDocument(uri).then(document => {
tests.forEach(t => {
let pos = new vscode.Position(t.line, t.char);
assert.equal(flags.isPrecedingCharStringDelimeter(document, pos), t.expected);
});
const document = await vscode.workspace.openTextDocument(uri);
tests.forEach(t => {
const pos = new vscode.Position(t.line, t.char);
assert.equal(flags.isPrecedingCharStringDelimeter(document, pos), t.expected, t.name);
});

});
});
2 changes: 2 additions & 0 deletions test/test.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,5 @@
`someFlagKey`
'someFlagKey'
a'someFlagKey'
'someFlagKey'a
%$#$^
Loading

0 comments on commit 1738d15

Please sign in to comment.