@@ -376,24 +376,30 @@ local function tryModifySpecifiedConfig(uri, finalChanges)
376
376
if # finalChanges == 0 then
377
377
return false
378
378
end
379
+ log .info (' tryModifySpecifiedConfig' , uri , inspect (finalChanges ))
379
380
local workspace = require ' workspace'
380
381
local scp = scope .getScope (uri )
381
382
if scp :get (' lastLocalType' ) ~= ' json' then
383
+ log .info (' lastLocalType ~= json' )
382
384
return false
383
385
end
384
386
local validChanges = getValidChanges (uri , finalChanges )
385
387
if # validChanges == 0 then
388
+ log .info (' No valid changes' )
386
389
return false
387
390
end
388
391
local path = workspace .getAbsolutePath (uri , CONFIGPATH )
389
392
if not path then
393
+ log .info (' Can not get absolute path' )
390
394
return false
391
395
end
392
396
local newJson = editConfigJson (uri , path , validChanges )
393
397
if not newJson then
398
+ log .info (' Can not edit config json' )
394
399
return false
395
400
end
396
401
util .saveFile (path , newJson )
402
+ log .info (' Apply changes to config file' , inspect (validChanges ))
397
403
removeAppliedChanges (finalChanges , validChanges )
398
404
return true
399
405
end
@@ -402,31 +408,38 @@ local function tryModifyRC(uri, finalChanges, create)
402
408
if # finalChanges == 0 then
403
409
return false
404
410
end
411
+ log .info (' tryModifyRC' , uri , inspect (finalChanges ))
405
412
local workspace = require ' workspace'
406
413
local path = workspace .getAbsolutePath (uri , ' .luarc.jsonc' )
407
414
if not path then
415
+ log .info (' Can not get absolute path of .luarc.jsonc' )
408
416
return false
409
417
end
410
418
path = fs .exists (fs .path (path )) and path or workspace .getAbsolutePath (uri , ' .luarc.json' )
411
419
if not path then
420
+ log .info (' Can not get absolute path of .luarc.json' )
412
421
return false
413
422
end
414
423
local buf = util .loadFile (path )
415
424
if not buf and not create then
425
+ log .info (' Can not load .luarc.json and not create' )
416
426
return false
417
427
end
418
428
local validChanges = getValidChanges (uri , finalChanges )
419
429
if # validChanges == 0 then
430
+ log .info (' No valid changes' )
420
431
return false
421
432
end
422
433
if not buf then
423
434
util .saveFile (path , ' ' )
424
435
end
425
436
local newJson = editConfigJson (uri , path , validChanges )
426
437
if not newJson then
438
+ log .info (' Can not edit config json' )
427
439
return false
428
440
end
429
441
util .saveFile (path , newJson )
442
+ log .info (' Apply changes to .luarc.json' , inspect (validChanges ))
430
443
removeAppliedChanges (finalChanges , validChanges )
431
444
return true
432
445
end
@@ -435,6 +448,7 @@ local function tryModifyClient(uri, finalChanges)
435
448
if # finalChanges == 0 then
436
449
return false
437
450
end
451
+ log .info (' tryModifyClient' , uri , inspect (finalChanges ))
438
452
if not m .getOption ' changeConfiguration' then
439
453
return false
440
454
end
@@ -447,12 +461,14 @@ local function tryModifyClient(uri, finalChanges)
447
461
end
448
462
end
449
463
if # scpChanges == 0 then
464
+ log .info (' No changes in client scope' )
450
465
return false
451
466
end
452
467
proto .notify (' $/command' , {
453
468
command = ' lua.config' ,
454
469
data = scpChanges ,
455
470
})
471
+ log .info (' Apply client changes' , uri , inspect (scpChanges ))
456
472
removeAppliedChanges (finalChanges , scpChanges )
457
473
return true
458
474
end
@@ -462,7 +478,9 @@ local function tryModifyClientGlobal(finalChanges)
462
478
if # finalChanges == 0 then
463
479
return
464
480
end
481
+ log .info (' tryModifyClientGlobal' , inspect (finalChanges ))
465
482
if not m .getOption ' changeConfiguration' then
483
+ log .info (' Client dose not support modifying config' )
466
484
return
467
485
end
468
486
local changes = {}
@@ -471,10 +489,15 @@ local function tryModifyClientGlobal(finalChanges)
471
489
changes [# changes + 1 ] = change
472
490
end
473
491
end
492
+ if # changes == 0 then
493
+ log .info (' No global changes' )
494
+ return
495
+ end
474
496
proto .notify (' $/command' , {
475
497
command = ' lua.config' ,
476
498
data = changes ,
477
499
})
500
+ log .info (' Apply client global changes' , inspect (changes ))
478
501
removeAppliedChanges (finalChanges , changes )
479
502
end
480
503
@@ -522,6 +545,7 @@ function m.setConfig(changes, onlyMemory)
522
545
if # finalChanges == 0 then
523
546
return
524
547
end
548
+ log .info (' Modify config' , inspect (finalChanges ))
525
549
xpcall (function ()
526
550
local ws = require ' workspace'
527
551
tryModifyClientGlobal (finalChanges )
@@ -541,6 +565,7 @@ function m.setConfig(changes, onlyMemory)
541
565
end
542
566
if # finalChanges > 0 then
543
567
m .showMessage (' Warning' , lang .script (' CONFIG_MODIFY_FAIL' , buildMaunuallyMessage (finalChanges )))
568
+ log .warn (' Config modify fail' , inspect (finalChanges ))
544
569
end
545
570
end
546
571
end , log .error )
0 commit comments