@@ -601,23 +601,30 @@ local function checkCommon(ast, word, text, offset, results)
601
601
for _ , data in ipairs (keyWordMap ) do
602
602
used [data [1 ]] = true
603
603
end
604
- if config .config .completion .workspaceWord then
604
+ if config .config .completion .workspaceWord and # word >= 2 then
605
+ local myHead = word :sub (1 , 2 )
605
606
for uri in files .eachFile () do
607
+ if myUri and files .eq (myUri , uri ) then
608
+ goto CONTINUE
609
+ end
606
610
local cache = files .getCache (uri )
607
611
if not cache .commonWords then
608
612
cache .commonWords = {}
609
613
local mark = {}
610
614
for str in files .getText (uri ):gmatch ' ([%a_][%w_]+)' do
611
- if not mark [str ] then
615
+ if # str >= 3 and not mark [str ] then
612
616
mark [str ] = true
613
- cache .commonWords [# cache .commonWords + 1 ] = str
617
+ local head = str :sub (1 , 2 )
618
+ if not cache .commonWords [head ] then
619
+ cache .commonWords [head ] = {}
620
+ end
621
+ cache .commonWords [head ][# cache .commonWords [head ]+ 1 ] = str
614
622
end
615
623
end
616
624
end
617
- for _ , str in ipairs (cache .commonWords ) do
618
- if # str >= 3
619
- and not used [str ]
620
- and (str ~= word or (myUri and not files .eq (myUri , uri ))) then
625
+ for _ , str in ipairs (cache .commonWords [myHead ] or {}) do
626
+ if not used [str ]
627
+ and str ~= word then
621
628
used [str ] = true
622
629
if matchKey (word , str ) then
623
630
results [# results + 1 ] = {
@@ -627,6 +634,7 @@ local function checkCommon(ast, word, text, offset, results)
627
634
end
628
635
end
629
636
end
637
+ :: CONTINUE::
630
638
end
631
639
for uri in files .eachDll () do
632
640
local words = files .getDllWords (uri ) or {}
@@ -642,16 +650,15 @@ local function checkCommon(ast, word, text, offset, results)
642
650
end
643
651
end
644
652
end
645
- else
646
- for str , pos in text :gmatch ' ([%a_][%w_]+)()' do
647
- if # str >= 3 and not used [str ] and pos - 1 ~= offset then
648
- used [str ] = true
649
- if matchKey (word , str ) then
650
- results [# results + 1 ] = {
651
- label = str ,
652
- kind = define .CompletionItemKind .Text ,
653
- }
654
- end
653
+ end
654
+ for str , pos in text :gmatch ' ([%a_][%w_]+)()' do
655
+ if # str >= 3 and not used [str ] and pos - 1 ~= offset then
656
+ used [str ] = true
657
+ if matchKey (word , str ) then
658
+ results [# results + 1 ] = {
659
+ label = str ,
660
+ kind = define .CompletionItemKind .Text ,
661
+ }
655
662
end
656
663
end
657
664
end
0 commit comments