@@ -22,6 +22,7 @@ local diag = require 'proto.diagnostic'
22
22
local wssymbol = require ' core.workspace-symbol'
23
23
local findSource = require ' core.find-source'
24
24
local diagnostic = require ' provider.diagnostic'
25
+ local autoRequire = require ' core.completion.auto-require'
25
26
26
27
local diagnosticModes = {
27
28
' disable-next-line' ,
@@ -369,89 +370,37 @@ local function checkModule(state, word, position, results)
369
370
if not config .get (state .uri , ' Lua.completion.autoRequire' ) then
370
371
return
371
372
end
372
- local globals = util .arrayToHash (config .get (state .uri , ' Lua.diagnostics.globals' ))
373
- local locals = guide .getVisibleLocals (state .ast , position )
374
- for uri in files .eachFile (state .uri ) do
375
- if uri == guide .getUri (state .ast ) then
376
- goto CONTINUE
377
- end
378
- local path = furi .decode (uri )
379
- local relativePath = workspace .getRelativePath (path )
380
- local infos = rpath .getVisiblePath (uri , path )
381
- local testedStem = { }
382
- for _ , sr in ipairs (infos ) do
383
- local pattern = sr .searcher
384
- :gsub (" (%p)" , " %%%1" )
385
- :gsub (" %%%?" , " (.-)" )
386
-
387
- local stemName = relativePath
388
- :match (pattern )
389
- :match (" [%a_][%w_]*$" )
390
-
391
- if not stemName or testedStem [stemName ] then
392
- goto INNER_CONTINUE
393
- end
394
- testedStem [stemName ] = true
395
-
396
- if not locals [stemName ]
397
- and not vm .hasGlobalSets (state .uri , ' variable' , stemName )
398
- and not globals [stemName ]
399
- and matchKey (word , stemName ) then
400
- local targetState = files .getState (uri )
401
- if not targetState then
402
- goto INNER_CONTINUE
403
- end
404
- local targetReturns = targetState .ast .returns
405
- if not targetReturns then
406
- goto INNER_CONTINUE
407
- end
408
- local targetSource = targetReturns [1 ] and targetReturns [1 ][1 ]
409
- if not targetSource then
410
- goto INNER_CONTINUE
411
- end
412
- if targetSource .type ~= ' getlocal'
413
- and targetSource .type ~= ' table'
414
- and targetSource .type ~= ' function' then
415
- goto INNER_CONTINUE
416
- end
417
- if targetSource .type == ' getlocal'
418
- and vm .getDeprecated (targetSource .node ) then
419
- goto INNER_CONTINUE
420
- end
421
- results [# results + 1 ] = {
422
- label = stemName ,
423
- kind = define .CompletionItemKind .Variable ,
424
- commitCharacters = { ' .' },
425
- command = {
426
- title = ' autoRequire' ,
427
- command = ' lua.autoRequire' ,
428
- arguments = {
429
- {
430
- uri = guide .getUri (state .ast ),
431
- target = uri ,
432
- name = stemName ,
433
- },
434
- },
373
+ autoRequire .check (state , word , position , function (uri , stemName , targetSource )
374
+ results [# results + 1 ] = {
375
+ label = stemName ,
376
+ kind = define .CompletionItemKind .Variable ,
377
+ commitCharacters = { ' .' },
378
+ command = {
379
+ title = ' autoRequire' ,
380
+ command = ' lua.autoRequire' ,
381
+ arguments = {
382
+ {
383
+ uri = guide .getUri (state .ast ),
384
+ target = uri ,
385
+ name = stemName ,
435
386
},
436
- id = stack ( targetSource , function ( newSource ) --- @async
437
- local md = markdown ()
438
- md : add ( ' md ' , lang . script ( ' COMPLETION_IMPORT_FROM ' , ( ' [%s](%s) ' ): format (
439
- workspace . getRelativePath ( uri ),
440
- uri
441
- )))
442
- md : add ( ' md ' , buildDesc ( newSource ))
443
- return {
444
- detail = buildDetail (newSource ),
445
- description = md ,
446
- -- additionalTextEdits = buildInsertRequire(state, originUri, stemName ),
447
- }
448
- end )
387
+ },
388
+ },
389
+ id = stack ( targetSource , function ( newSource ) --- @async
390
+ local md = markdown ()
391
+ md : add ( ' md ' , lang . script ( ' COMPLETION_IMPORT_FROM ' , ( ' [%s](%s) ' ): format (
392
+ workspace . getRelativePath ( uri ),
393
+ uri
394
+ )))
395
+ md : add ( ' md ' , buildDesc (newSource ))
396
+ return {
397
+ detail = buildDetail ( newSource ),
398
+ description = md ,
399
+ -- additionalTextEdits = buildInsertRequire(state, originUri, stemName),
449
400
}
450
- end
451
- :: INNER_CONTINUE::
452
- end
453
- :: CONTINUE::
454
- end
401
+ end )
402
+ }
403
+ end )
455
404
end
456
405
457
406
local function checkFieldFromFieldToIndex (state , name , src , parent , word , startPos , position )
0 commit comments