Skip to content

Commit 55be3c4

Browse files
committed
fix tests
1 parent 6f450ee commit 55be3c4

3 files changed

Lines changed: 30 additions & 11 deletions

File tree

de.peeeq.wurstscript/src/main/java/de/peeeq/wurstio/languageserver/JassDocService.java

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,10 +157,16 @@ public static void setTestLookup(@Nullable Function<LookupKey, @Nullable String>
157157
}
158158

159159
public @Nullable String documentationFor(String symbolName, SymbolKind symbolKind, String sourceFile) {
160+
Function<LookupKey, @Nullable String> override = testLookup;
161+
LookupKey key = new LookupKey(symbolName, symbolKind, sourceFile);
162+
if (override != null) {
163+
Optional<String> computed = Optional.ofNullable(trimToNull(override.apply(key)));
164+
Optional<String> prev = lookupCache.putIfAbsent(key, computed);
165+
return (prev != null ? prev : computed).orElse(null);
166+
}
160167
if (!isJassBuiltinSource(sourceFile)) {
161168
return null;
162169
}
163-
LookupKey key = new LookupKey(symbolName, symbolKind, sourceFile);
164170
Optional<String> cached = lookupCache.computeIfAbsent(key, this::lookupDocumentation);
165171
return cached.orElse(null);
166172
}
@@ -170,10 +176,16 @@ public static void setTestLookup(@Nullable Function<LookupKey, @Nullable String>
170176
* if DB is not ready, triggers async init and returns null immediately.
171177
*/
172178
public @Nullable String documentationForQuick(String symbolName, SymbolKind symbolKind, String sourceFile) {
179+
LookupKey key = new LookupKey(symbolName, symbolKind, sourceFile);
180+
Function<LookupKey, @Nullable String> override = testLookup;
181+
if (override != null) {
182+
Optional<String> computed = Optional.ofNullable(trimToNull(override.apply(key)));
183+
Optional<String> prev = lookupCache.putIfAbsent(key, computed);
184+
return (prev != null ? prev : computed).orElse(null);
185+
}
173186
if (!isJassBuiltinSource(sourceFile)) {
174187
return null;
175188
}
176-
LookupKey key = new LookupKey(symbolName, symbolKind, sourceFile);
177189
Optional<String> cached = lookupCache.get(key);
178190
if (cached != null) {
179191
return cached.orElse(null);

de.peeeq.wurstscript/src/main/java/de/peeeq/wurstio/languageserver/requests/GetCompletions.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -217,20 +217,20 @@ private void enrichTopDocumentation(List<CompletionItem> completions) {
217217
}
218218
String comment = null;
219219
boolean jassDoc = false;
220-
if (target instanceof NameDef) {
221-
NameDef n = (NameDef) target;
222-
comment = n.attrComment();
223-
if (comment == null || comment.isEmpty()) {
224-
comment = JassDocService.getInstance().documentationForVariableQuick(n);
225-
jassDoc = comment != null && !comment.isEmpty();
226-
}
227-
} else if (target instanceof FunctionDefinition) {
220+
if (target instanceof FunctionDefinition) {
228221
FunctionDefinition f = (FunctionDefinition) target;
229222
comment = f.attrComment();
230223
if (comment == null || comment.isEmpty()) {
231224
comment = JassDocService.getInstance().documentationForFunctionQuick(f);
232225
jassDoc = comment != null && !comment.isEmpty();
233226
}
227+
} else if (target instanceof NameDef) {
228+
NameDef n = (NameDef) target;
229+
comment = n.attrComment();
230+
if (comment == null || comment.isEmpty()) {
231+
comment = JassDocService.getInstance().documentationForVariableQuick(n);
232+
jassDoc = comment != null && !comment.isEmpty();
233+
}
234234
}
235235
if (comment == null || comment.isEmpty()) {
236236
continue;

de.peeeq.wurstscript/src/test/java/tests/wurstscript/tests/LspNativeFeaturesTests.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -473,7 +473,14 @@ public void completionUsesJassDocFallbackForBuiltinFunction() throws IOException
473473
assertNotNull(completions);
474474
String doc = completions.getItems().stream()
475475
.filter(i -> "DisplayTextToPlayer".equals(i.getLabel()))
476-
.map(i -> i.getDocumentation() != null ? i.getDocumentation().getLeft() : null)
476+
.map(i -> {
477+
if (i.getDocumentation() == null) {
478+
return null;
479+
}
480+
return i.getDocumentation().isLeft()
481+
? i.getDocumentation().getLeft()
482+
: i.getDocumentation().getRight().getValue();
483+
})
477484
.filter(Objects::nonNull)
478485
.findFirst()
479486
.orElse("");

0 commit comments

Comments
 (0)