1
1
import * as vscode from 'vscode' ;
2
2
import * as request from 'request' ;
3
3
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' ) ;
8
8
import * as url from 'url' ;
9
9
import opn = require( 'opn' ) ;
10
10
@@ -73,7 +73,11 @@ export function generateHoverString(flag: LDFlagValue) {
73
73
Default variation: ${ JSON . stringify ( flag . variations [ flag . fallthrough . variation ] ) }
74
74
Off variation: ${ JSON . stringify ( flag . variations [ flag . offVariation ] ) }
75
75
${ 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
+ ) }
77
81
${ plural ( flag . rules . length , 'rule' , 'rules' ) } ` ;
78
82
}
79
83
@@ -83,15 +87,17 @@ function plural(count: number, singular: string, plural: string) {
83
87
84
88
export function isPrecedingCharStringDelimeter ( document : vscode . TextDocument , position : vscode . Position ) {
85
89
const range = document . getWordRangeAtPosition ( position , FLAG_KEY_REGEX ) ;
86
-
90
+ if ( ! range || ! range . start || range . start . character === 0 ) {
91
+ return false ;
92
+ }
87
93
const c = new vscode . Range (
88
94
range . start . line ,
89
95
candidateTextStartLocation ( range . start . character ) ,
90
96
range . start . line ,
91
97
range . start . character ,
92
98
) ;
93
99
const candidate = document . getText ( c ) . trim ( ) ;
94
- return STRING_DELIMETERS . indexOf ( candidate ) >= 0 ;
100
+ return STRING_DELIMETERS . indexOf ( candidate ) !== - 1 ;
95
101
}
96
102
97
103
const candidateTextStartLocation = ( char : number ) => ( char === 1 ? 0 : char - 2 ) ;
@@ -109,30 +115,29 @@ export class LDFlagManager implements IFlagManager {
109
115
constructor ( ctx : vscode . ExtensionContext , settings : IConfiguration ) {
110
116
this . settings = Object . assign ( { } , settings ) ;
111
117
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 ;
119
121
}
122
+
123
+ this . updateProcessor = StreamProcessor ( settings . sdkKey , config , Requestor ( settings . sdkKey , config ) ) ;
124
+ this . start ( ) ;
120
125
}
121
126
122
127
start ( ) {
123
128
this . updateProcessor &&
124
- this . updateProcessor . start ( function ( err ) {
129
+ this . updateProcessor . start ( err => {
125
130
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 } ` ) ;
135
139
}
140
+ process . nextTick ( function ( ) { } ) ;
136
141
} ) ;
137
142
}
138
143
@@ -157,9 +162,9 @@ export class LDFlagManager implements IFlagManager {
157
162
streamUri : settings . streamUri ,
158
163
featureStore : this . store ,
159
164
logger : {
160
- debug : msg => {
161
- console . log ( msg ) ;
162
- } ,
165
+ debug : console . log ,
166
+ warn : console . warn ,
167
+ error : console . error ,
163
168
} ,
164
169
userAgent : 'VSCodeExtension/' + package_json . version ,
165
170
} ;
0 commit comments