@@ -25,6 +25,25 @@ function showNotification(title, body) {
25
25
}
26
26
}
27
27
28
+
29
+ // Append the argument to the array if the condition is true
30
+ function conditionalAppendArgumentsToArray ( conditional , array , arg ) {
31
+ // If the passed conditional is true
32
+ if ( conditional ) {
33
+ // If the array is empty return an array with just the passed argument.
34
+ if ( array == '' ) {
35
+ return [ arg ] ;
36
+ } else {
37
+ // Otherwise append to the existing array and return.
38
+ array . push ( arg ) ;
39
+ return array ;
40
+ }
41
+ } else {
42
+ // If conditional is false, transparently return the passed array.
43
+ return array ;
44
+ }
45
+ }
46
+
28
47
// Parse JSON from a string and return an JSON object.
29
48
function parseJSON ( string ) {
30
49
if ( string == undefined ) {
@@ -124,7 +143,10 @@ function getSettings() {
124
143
"exclude" : parseSpaceSeparated ( getPreference ( 'pyls.plugins.pycodestyle.exclude' ) ) ,
125
144
"filename" : parseSpaceSeparated ( getPreference ( 'pyls.plugins.pycodestyle.filename' ) ) ,
126
145
"select" : parseSpaceSeparated ( getPreference ( 'pyls.plugins.pycodestyle.select' ) ) ,
127
- "ignore" : parseSpaceSeparated ( getPreference ( 'pyls.plugins.pycodestyle.ignore' ) ) ,
146
+ "ignore" : conditionalAppendArgumentsToArray (
147
+ getPreference ( 'pyls.plugins.pycodestyle.disableLineLength' ) ,
148
+ parseSpaceSeparated ( getPreference ( 'pyls.plugins.pycodestyle.ignore' ) ) ,
149
+ "E501" ) ,
128
150
"hangClosing" : getPreference ( 'pyls.plugins.pycodestyle.hangClosing' ) ,
129
151
"maxLineLength" : getPreference ( 'pyls.plugins.pycodestyle.maxLineLength' )
130
152
} ,
@@ -181,6 +203,9 @@ function getSettings() {
181
203
class PythonLanguageServer {
182
204
constructor ( ) {
183
205
this . addPreferenceObservers ( ) ;
206
+ // First start.
207
+ showNotification ( "Starting extension." ) ;
208
+ this . start ( getPreference ( 'pyls.executable' , '/usr/local/bin/pyls' ) ) ;
184
209
}
185
210
186
211
addPreferenceObservers ( ) {
@@ -217,6 +242,7 @@ class PythonLanguageServer {
217
242
'pyls.plugins.pycodestyle.select' ,
218
243
'pyls.plugins.pycodestyle.ignore' ,
219
244
'pyls.plugins.pycodestyle.hangClosing' ,
245
+ 'pyls.plugins.pycodestyle.disableLineLength' ,
220
246
'pyls.plugins.pycodestyle.maxLineLength' ,
221
247
'pyls.plugins.pydocstyle.convention' ,
222
248
'pyls.plugins.pydocstyle.addIgnore' ,
@@ -235,7 +261,7 @@ class PythonLanguageServer {
235
261
'pyls.plugins.pyls_black.enabled'
236
262
] ;
237
263
for ( var i of keys ) {
238
- nova . config . observe ( i , async function ( newValue , oldValue ) {
264
+ nova . config . onDidChange ( i , async function ( newValue , oldValue ) {
239
265
console . log ( "Syncing preferences." ) ;
240
266
if ( this . languageClient ) {
241
267
this . languageClient . sendNotification ( "workspace/didChangeConfiguration" , getSettings ( ) )
@@ -249,18 +275,13 @@ class PythonLanguageServer {
249
275
'pyls.logPath'
250
276
] ;
251
277
for ( var i of reloadKeys ) {
252
- nova . config . observe ( i , async function ( newValue , oldValue ) {
278
+ nova . config . onDidChange ( i , async function ( newValue , oldValue ) {
253
279
if ( this . languageClient ) {
254
280
showNotification ( "Stopping extension." ) ;
255
- await this . languageClient . stop ( ) ;
256
-
281
+ await this . stop ( ) ;
257
282
nova . subscriptions . remove ( this . languageClient ) ;
258
283
await this . start ( getPreference ( 'pyls.executable' , '/usr/local/bin/pyls' ) ) ;
259
-
260
- nova . subscriptions . add ( client ) ;
261
284
} else {
262
- // First start.
263
- showNotification ( "Starting extension." ) ;
264
285
await this . start ( getPreference ( 'pyls.executable' , '/usr/local/bin/pyls' ) ) ;
265
286
}
266
287
} , this ) ;
@@ -270,7 +291,7 @@ class PythonLanguageServer {
270
291
'pyls.plugins.jedi.workspace.environment'
271
292
] ;
272
293
for ( var i of workspaceKeys ) {
273
- nova . workspace . config . observe ( i , async function ( newValue , oldValue ) {
294
+ nova . workspace . config . onDidChange ( i , async function ( newValue , oldValue ) {
274
295
showNotification ( "Syncing Workspace Preferences." ) ;
275
296
if ( this . languageClient ) {
276
297
this . languageClient . sendNotification ( "workspace/didChangeConfiguration" , getSettings ( ) )
@@ -285,10 +306,7 @@ class PythonLanguageServer {
285
306
}
286
307
287
308
async start ( path ) {
288
- if ( this . languageClient ) {
289
- await this . languageClient . stop ( ) ;
290
- nova . subscriptions . remove ( this . languageClient ) ;
291
- }
309
+ this . stop ( ) ;
292
310
293
311
// Create the client
294
312
var serverOptions = {
@@ -304,6 +322,7 @@ class PythonLanguageServer {
304
322
// The set of document syntaxes for which the server is valid
305
323
syntaxes : [ 'python' ] ,
306
324
} ;
325
+
307
326
var client = new LanguageClient ( 'PyLS' , 'Python Language Server' , serverOptions , clientOptions ) ;
308
327
309
328
try {
0 commit comments