• 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/GetUsages.java
1
package de.peeeq.wurstio.languageserver.requests;
2

3
import de.peeeq.wurstio.languageserver.BufferManager;
4
import de.peeeq.wurstio.languageserver.Convert;
5
import de.peeeq.wurstio.languageserver.ModelManager;
6
import de.peeeq.wurstio.languageserver.WFile;
7
import de.peeeq.wurstscript.ast.CompilationUnit;
8
import de.peeeq.wurstscript.ast.Element;
9
import de.peeeq.wurstscript.ast.ExprVarArrayAccess;
10
import de.peeeq.wurstscript.ast.NameDef;
11
import de.peeeq.wurstscript.utils.Utils;
12
import org.eclipse.lsp4j.*;
13

14
import java.util.*;
15

16
public class GetUsages extends UserRequest<List<GetUsages.UsagesData>> {
17

18
    private final WFile wFile;
19
    private final String buffer;
20
    private final int line;
21
    private final int column;
22
    private final boolean global;
23

24

25

26
    public GetUsages(TextDocumentPositionParams position, BufferManager bufferManager, boolean global) {
×
27
        this.wFile = WFile.create(position.getTextDocument().getUri());
×
28
        this.buffer = bufferManager.getBuffer(position.getTextDocument());
×
29
        this.line = position.getPosition().getLine() + 1;
×
30
        this.column = position.getPosition().getCharacter() + 1;
×
31
        this.global = global;
×
32
    }
×
33

34

35
    @Override
36
    public List<UsagesData> execute(ModelManager modelManager) {
37
        CompilationUnit cu = modelManager.replaceCompilationUnitContent(wFile, buffer, false);
×
38
        if (cu == null) {
×
39
            return Collections.emptyList();
×
40
        }
41
        Optional<Element> astElem = Utils.getAstElementAtPos(cu, line, column, false);
×
42
        Optional<NameDef> nameDef = astElem.flatMap(elem -> Optional.ofNullable(elem.tryGetNameDef()));
×
43
        List<UsagesData> usages = new ArrayList<>();
×
44
        if (nameDef.isPresent()) {
×
45

46
            if (global || nameDef.get().getSource().getFile().equals(wFile.toString())) {
×
47
                // add declaration
48
                usages.add(
×
49
                    new UsagesData(Convert.posToLocation(nameDef.get().attrErrorPos()), DocumentHighlightKind.Write));
×
50
            }
51
            Deque<Element> todo = new ArrayDeque<>();
×
52
            if (global) {
×
53
                todo.push(modelManager.getModel());
×
54
            } else {
55
                todo.push(cu);
×
56
            }
57
            while (!todo.isEmpty()) {
×
58
                Element e = todo.pop();
×
59
                // visit children:
60
                for (int i = 0; i < e.size(); i++) {
×
61
                    todo.push(e.get(i));
×
62
                }
63
                NameDef e_def = e.tryGetNameDef();
×
64
                if (e_def == nameDef.get()) {
×
65
                    if (e instanceof ExprVarArrayAccess) {
×
66
                        e = ((ExprVarArrayAccess) e).getVarNameId();
×
67
                    }
68
                    Location location = Convert.posToLocation(e.attrErrorPos());
×
69
                    UsagesData usagesData = new UsagesData(location, DocumentHighlightKind.Read);
×
70
                    usages.add(usagesData);
×
71
                }
72
            }
×
73
        }
74

75
        return usages;
×
76
    }
77

78
    public static class UsagesData {
79
        private final Location location;
80
        private DocumentHighlightKind kind;
81

82

83
        public UsagesData(Location location, DocumentHighlightKind kind) {
×
84
            this.location = location;
×
85
            this.kind = kind;
×
86
        }
×
87

88
        public String getFilename() {
89
            return location.getUri();
×
90
        }
91

92
        public void setFilename(String filename) {
93
            location.setUri(filename);
×
94
        }
×
95

96
        public Range getRange() {
97
            return location.getRange();
×
98
        }
99

100
        public void setRange(Range range) {
101
            location.setRange(range);
×
102
        }
×
103

104
        public DocumentHighlightKind getKind() {
105
            return kind;
×
106
        }
107

108
        public void setKind(DocumentHighlightKind kind) {
109
            this.kind = kind;
×
110
        }
×
111

112
        public Location getLocation() {
113
            return location;
×
114
        }
115

116
        public DocumentHighlight toDocumentHighlight() {
117
            return new DocumentHighlight(location.getRange(), kind);
×
118
        }
119

120
    }
121
}
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