11using EmmyLua . CodeAnalysis . Compilation . Search ;
2- using EmmyLua . CodeAnalysis . Type ;
2+ using EmmyLua . CodeAnalysis . Compilation . Symbol ;
3+ using EmmyLua . CodeAnalysis . Syntax . Node ;
34using EmmyLua . LanguageServer . Framework . Protocol . Message . DocumentSymbol ;
45using EmmyLua . LanguageServer . Server ;
56using EmmyLua . LanguageServer . Util ;
@@ -16,44 +17,35 @@ public class WorkspaceSymbolBuilder
1617 {
1718 var luaProject = context . LuaProject ;
1819 var searchContext = new SearchContext ( luaProject . Compilation , new SearchContextFeatures ( ) ) ;
19- var globals = context . LuaProject . Compilation . TypeManager . GetAllGlobalInfos ( ) ;
20- foreach ( var global in globals )
20+ var namedElements = context . LuaProject . Compilation . Db . QueryNamedElements ( searchContext ) ;
21+ foreach ( var pair in namedElements )
2122 {
22- if ( global . Name . StartsWith ( query , StringComparison . OrdinalIgnoreCase ) )
23+ var name = pair . Item1 ;
24+ if ( name . StartsWith ( query , StringComparison . OrdinalIgnoreCase ) )
2325 {
2426 cancellationToken . ThrowIfCancellationRequested ( ) ;
25- var globalSymbol = global . MainLuaSymbol ;
26- if ( globalSymbol is not null )
27+ var elementIds = pair . Item2 ;
28+ foreach ( var elementId in elementIds )
2729 {
28- var location = globalSymbol . GetLocation ( searchContext ) ? . ToLspLocation ( ) ;
29- result . Add ( new Framework . Protocol . Message . WorkspaceSymbol . WorkspaceSymbol ( )
30+ var document = luaProject . GetDocument ( elementId . DocumentId ) ;
31+ if ( document is not null )
3032 {
31- Name = global . Name ,
32- Kind = ToSymbolKind ( globalSymbol . Type ) ,
33- Location = location
34- } ) ;
33+ var ptr = new LuaElementPtr < LuaSyntaxElement > ( elementId ) ;
34+ if ( ptr . ToNode ( document ) is { } node )
35+ {
36+ var location = node . Location . ToLspLocation ( ) ;
37+ var declaration = searchContext . FindDeclaration ( node ) ;
38+ result . Add ( new Framework . Protocol . Message . WorkspaceSymbol . WorkspaceSymbol ( )
39+ {
40+ Name = name ,
41+ Kind = ToSymbolKind ( declaration ) ,
42+ Location = location
43+ } ) ;
44+ }
45+ }
3546 }
3647 }
3748 }
38-
39- // var members = context.LuaProject.Compilation.TypeManager.GetAllTypeMembers();
40- // foreach (var member in members)
41- // {
42- // if (member.Name.StartsWith(query, StringComparison.OrdinalIgnoreCase))
43- // {
44- // cancellationToken.ThrowIfCancellationRequested();
45- // var document = luaProject.GetDocument(member.DocumentId);
46- // if (document is not null && member.Info.Ptr.ToNode(document) is { } node)
47- // {
48- // result.Add(new Framework.Protocol.Message.WorkspaceSymbol.WorkspaceSymbol()
49- // {
50- // Name = member.Name,
51- // Kind = ToSymbolKind(member.Type),
52- // Location = node.Range.ToLspLocation(document)
53- // });
54- // }
55- // }
56- // }
5749
5850 return result ;
5951 }
@@ -63,12 +55,13 @@ public class WorkspaceSymbolBuilder
6355 }
6456 }
6557
66- private static SymbolKind ToSymbolKind ( LuaType ? type )
58+ private static SymbolKind ToSymbolKind ( LuaSymbol ? luaSymbol )
6759 {
68- return type switch
60+ return luaSymbol ? . Info switch
6961 {
70- LuaNamedType => SymbolKind . Variable ,
71- LuaMethodType => SymbolKind . Method ,
62+ MethodInfo => SymbolKind . Method ,
63+ ParamInfo => SymbolKind . TypeParameter ,
64+ NamedTypeInfo => SymbolKind . Class ,
7265 _ => SymbolKind . Variable
7366 } ;
7467 }
0 commit comments