• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

wurstscript / WurstScript / 228

29 Nov 2023 05:00PM UTC coverage: 62.48% (-0.09%) from 62.574%
228

push

circleci

web-flow
Show dialog for choosing game path, cleanup (#1083)

* show dialog for choosing game path

* cleanup code

* remove logs and refactor

* remove confusing mpq error, make some mpq loads readonly

17295 of 27681 relevant lines covered (62.48%)

0.62 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
de.peeeq.wurstscript/src/main/java/de/peeeq/wurstio/languageserver/requests/SymbolInformationRequest.java
1
package de.peeeq.wurstio.languageserver.requests;
2

3
import de.peeeq.wurstio.languageserver.Convert;
4
import de.peeeq.wurstio.languageserver.ModelManager;
5
import de.peeeq.wurstscript.ast.*;
6
import org.eclipse.lsp4j.SymbolInformation;
7
import org.eclipse.lsp4j.SymbolKind;
8
import org.eclipse.lsp4j.WorkspaceSymbol;
9
import org.eclipse.lsp4j.WorkspaceSymbolParams;
10
import org.eclipse.lsp4j.jsonrpc.messages.Either;
11

12
import java.util.ArrayList;
13
import java.util.Collections;
14
import java.util.List;
15
import java.util.stream.Collectors;
16

17
/**
18
 *
19
 */
20
public class SymbolInformationRequest extends UserRequest<Either<List<? extends SymbolInformation>, List<? extends WorkspaceSymbol>>> {
21

22
    private final String query;
23

24
    public SymbolInformationRequest(WorkspaceSymbolParams params) {
×
25
        query = params.getQuery().toLowerCase();
×
26
    }
×
27

28
    @Override
29
    public Either<List<? extends SymbolInformation>, List<? extends WorkspaceSymbol>> execute(ModelManager modelManager) {
30
        return Either.forLeft(symbolsFromModel(modelManager.getModel()));
×
31
    }
32

33
    private List<SymbolInformation> symbolsFromModel(WurstModel model) {
34
        return model.stream()
×
35
                .flatMap(cu -> symbolsFromCu(cu).stream())
×
36
                .filter(si -> (si.getContainerName() + "." + si.getName()).toLowerCase().contains(query))
×
37
                .collect(Collectors.toList());
×
38
    }
39

40
    private List<SymbolInformation> symbolsFromCu(CompilationUnit cu) {
41
        if (cu == null) {
×
42
            return Collections.emptyList();
×
43
        }
44
        List<SymbolInformation> result = new ArrayList<>();
×
45
        for (WPackage p : cu.getPackages()) {
×
46
            addSymbolsForPackage(result, p);
×
47
        }
×
48
        return result;
×
49
    }
50

51
    private void addSymbolsForPackage(List<SymbolInformation> result, WPackage p) {
52
        result.add(new SymbolInformation(p.getName(), SymbolKind.Package, Convert.errorLocation(p), ""));
×
53
        for (WEntity e : p.getElements()) {
×
54
            addSymbolsForEntity(result, p.getName(), e);
×
55
        }
×
56
    }
×
57

58
    private void addSymbolsForEntity(List<SymbolInformation> result, String containerName, WEntity e) {
59
        e.match(new WEntity.MatcherVoid() {
×
60
            private void add(String name, SymbolKind kind) {
61
                result.add(new SymbolInformation(name, kind, Convert.errorLocation(e), containerName));
×
62
            }
×
63

64
            @Override
65
            public void case_ExtensionFuncDef(ExtensionFuncDef extensionFuncDef) {
66
                add(extensionFuncDef.getName(), SymbolKind.Function);
×
67
            }
×
68

69
            @Override
70
            public void case_ClassDef(ClassDef classDef) {
71
                String name = classDef.getName();
×
72
                add(name, SymbolKind.Class);
×
73
                for (ClassDef c : classDef.getInnerClasses()) {
×
74
                    addSymbolsForEntity(result, containerName + "." + name, c);
×
75
                }
×
76
                for (FuncDef f : classDef.getMethods()) {
×
77
                    addSymbolsForEntity(result, containerName + "." + name, f);
×
78
                }
×
79
                for (GlobalVarDef v : classDef.getVars()) {
×
80
                    addSymbolsForEntity(result, containerName + "." + name, v);
×
81
                }
×
82
            }
×
83

84
            @Override
85
            public void case_InterfaceDef(InterfaceDef interfaceDef) {
86
                String name = interfaceDef.getName();
×
87
                add(name, SymbolKind.Interface);
×
88
                for (FuncDef f : interfaceDef.getMethods()) {
×
89
                    addSymbolsForEntity(result, containerName + "." + name, f);
×
90
                }
×
91
                for (GlobalVarDef v : interfaceDef.getVars()) {
×
92
                    addSymbolsForEntity(result, containerName + "." + name, v);
×
93
                }
×
94
            }
×
95

96
            @Override
97
            public void case_ModuleInstanciation(ModuleInstanciation moduleInstanciation) {
98

99
            }
×
100

101
            @Override
102
            public void case_NativeType(NativeType nativeType) {
103
                add(nativeType.getName(), SymbolKind.Class);
×
104
            }
×
105

106
            @Override
107
            public void case_InitBlock(InitBlock initBlock) {
108
                add("init", SymbolKind.Function);
×
109
            }
×
110

111
            @Override
112
            public void case_TupleDef(TupleDef tupleDef) {
113
                add(tupleDef.getName(), SymbolKind.Class);
×
114
            }
×
115

116
            @Override
117
            public void case_FuncDef(FuncDef funcDef) {
118
                SymbolKind kind = funcDef.attrIsDynamicClassMember() ? SymbolKind.Method : SymbolKind.Function;
×
119
                add(funcDef.getName(), kind);
×
120
            }
×
121

122
            @Override
123
            public void case_NativeFunc(NativeFunc nativeFunc) {
124
                add(nativeFunc.getName(), SymbolKind.Function);
×
125
            }
×
126

127
            @Override
128
            public void case_GlobalVarDef(GlobalVarDef g) {
129
                SymbolKind kind = g.attrIsDynamicClassMember() ? SymbolKind.Field : SymbolKind.Variable;
×
130
                add(g.getName(), kind);
×
131
            }
×
132

133
            @Override
134
            public void case_EnumDef(EnumDef enumDef) {
135
                add(enumDef.getName(), SymbolKind.Class);
×
136
            }
×
137

138
            @Override
139
            public void case_TypeParamDef(TypeParamDef typeParamDef) {
140
                add(typeParamDef.getName(), SymbolKind.Class);
×
141
            }
×
142

143
            @Override
144
            public void case_ModuleDef(ModuleDef moduleDef) {
145
                String name = moduleDef.getName();
×
146
                add(name, SymbolKind.Class);
×
147
                for (ClassDef c : moduleDef.getInnerClasses()) {
×
148
                    addSymbolsForEntity(result, containerName + "." + name, c);
×
149
                }
×
150
                for (FuncDef f : moduleDef.getMethods()) {
×
151
                    addSymbolsForEntity(result, containerName + "." + name, f);
×
152
                }
×
153
                for (GlobalVarDef v : moduleDef.getVars()) {
×
154
                    addSymbolsForEntity(result, containerName + "." + name, v);
×
155
                }
×
156
            }
×
157

158

159
        });
160
    }
×
161
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc