aboutsummaryrefslogtreecommitdiffstats
path: root/subprojects/frontend/src/xtext/ContentAssistService.ts
diff options
context:
space:
mode:
authorLibravatar Kristóf Marussy <kristof@marussy.com>2022-11-28 00:20:44 +0100
committerLibravatar Kristóf Marussy <kristof@marussy.com>2022-12-09 00:07:39 +0100
commit0173a4e5deb5dbe71c91a68c02ef88e3de778068 (patch)
tree8498ac382150f59ba626b85827c11dca3c33f880 /subprojects/frontend/src/xtext/ContentAssistService.ts
parentfeat(frontend): scroll beyond last line in editor (diff)
downloadrefinery-0173a4e5deb5dbe71c91a68c02ef88e3de778068.tar.gz
refinery-0173a4e5deb5dbe71c91a68c02ef88e3de778068.tar.zst
refinery-0173a4e5deb5dbe71c91a68c02ef88e3de778068.zip
fix(frontend): content assist error recovery
Diffstat (limited to 'subprojects/frontend/src/xtext/ContentAssistService.ts')
-rw-r--r--subprojects/frontend/src/xtext/ContentAssistService.ts32
1 files changed, 26 insertions, 6 deletions
diff --git a/subprojects/frontend/src/xtext/ContentAssistService.ts b/subprojects/frontend/src/xtext/ContentAssistService.ts
index fa894e4d..78f61c06 100644
--- a/subprojects/frontend/src/xtext/ContentAssistService.ts
+++ b/subprojects/frontend/src/xtext/ContentAssistService.ts
@@ -33,16 +33,36 @@ interface IFoundToken {
33 33
34function findToken({ pos, state }: CompletionContext): IFoundToken | undefined { 34function findToken({ pos, state }: CompletionContext): IFoundToken | undefined {
35 const token = syntaxTree(state).resolveInner(pos, -1); 35 const token = syntaxTree(state).resolveInner(pos, -1);
36 if (token.firstChild !== null) { 36 const { from } = token;
37 // We only autocomplete terminal nodes. If the current node is nonterminal, 37 if (from > pos) {
38 // returning `undefined` makes us autocomplete with the empty prefix instead. 38 // We haven't found the token we want to complete.
39 // Complete with an empty prefix from `pos` instead.
40 // The other `return undefined;` lines also handle this condition.
41 return undefined;
42 }
43 // We look at the text at the beginning of the token.
44 // For QualifiedName tokens right before a comment, this may be a comment token.
45 const endIndex = token.firstChild?.from ?? token.to;
46 if (pos > endIndex) {
47 return undefined;
48 }
49 const text = state.sliceDoc(from, endIndex).trimEnd();
50 // Due to parser error recovery, we may get spurious whitespace
51 // at the end of the token.
52 const to = from + text.length;
53 if (to > endIndex) {
54 return undefined;
55 }
56 if (from > pos || endIndex < pos) {
57 // We haven't found the token we want to complete.
58 // Complete with an empty prefix from `pos` instead.
39 return undefined; 59 return undefined;
40 } 60 }
41 return { 61 return {
42 from: token.from, 62 from,
43 to: token.to, 63 to,
44 implicitCompletion: token.type.prop(implicitCompletion) || false, 64 implicitCompletion: token.type.prop(implicitCompletion) || false,
45 text: state.sliceDoc(token.from, token.to), 65 text,
46 }; 66 };
47} 67}
48 68