aboutsummaryrefslogtreecommitdiffstats
path: root/language-web
diff options
context:
space:
mode:
authorLibravatar Kristóf Marussy <kristof@marussy.com>2021-11-05 19:17:30 +0100
committerLibravatar Kristóf Marussy <kristof@marussy.com>2021-11-05 19:17:30 +0100
commit10df138d6084000659626aaf50afb16e6b674b25 (patch)
tree6769f681ff339e0796e2ca43525df3e58b6fc6db /language-web
parentfix(lang): make default and scope non-contextual (diff)
downloadrefinery-10df138d6084000659626aaf50afb16e6b674b25.tar.gz
refinery-10df138d6084000659626aaf50afb16e6b674b25.tar.zst
refinery-10df138d6084000659626aaf50afb16e6b674b25.zip
chore(web): implicit completion info in grammar
Move information about which tokens should support implicit completions into the Lezer grammar.
Diffstat (limited to 'language-web')
-rw-r--r--language-web/package.json1
-rw-r--r--language-web/src/main/js/language/problem.grammar10
-rw-r--r--language-web/src/main/js/language/props.ts7
-rw-r--r--language-web/src/main/js/xtext/ContentAssistService.ts15
-rw-r--r--language-web/yarn.lock2
5 files changed, 20 insertions, 15 deletions
diff --git a/language-web/package.json b/language-web/package.json
index cb860c5f..3362a47a 100644
--- a/language-web/package.json
+++ b/language-web/package.json
@@ -85,6 +85,7 @@
85 "escape-string-regexp": "^5.0.0", 85 "escape-string-regexp": "^5.0.0",
86 "@fontsource/jetbrains-mono": "^4.5.0", 86 "@fontsource/jetbrains-mono": "^4.5.0",
87 "@fontsource/roboto": "^4.5.1", 87 "@fontsource/roboto": "^4.5.1",
88 "@lezer/common": "^0.15.7",
88 "@lezer/lr": "^0.15.4", 89 "@lezer/lr": "^0.15.4",
89 "loglevel": "^1.7.1", 90 "loglevel": "^1.7.1",
90 "loglevel-plugin-prefix": "^0.8.4", 91 "loglevel-plugin-prefix": "^0.8.4",
diff --git a/language-web/src/main/js/language/problem.grammar b/language-web/src/main/js/language/problem.grammar
index 86cc7722..8e39243f 100644
--- a/language-web/src/main/js/language/problem.grammar
+++ b/language-web/src/main/js/language/problem.grammar
@@ -1,3 +1,7 @@
1@detectDelim
2
3@external prop implicitCompletion from '../../../../src/main/js/language/props.ts'
4
1@top Problem { statement* } 5@top Problem { statement* }
2 6
3statement { 7statement {
@@ -89,11 +93,11 @@ VariableName { QualifiedName }
89 93
90NodeName { QualifiedName } 94NodeName { QualifiedName }
91 95
92QualifiedName { identifier ("::" identifier)* } 96QualifiedName[implicitCompletion=true] { identifier ("::" identifier)* }
93 97
94kw<term> { @specialize[@name={term}]<identifier, term> } 98kw<term> { @specialize[@name={term},implicitCompletion=true]<identifier, term> }
95 99
96ckw<term> { @extend[@name={term}]<identifier, term> } 100ckw<term> { @extend[@name={term},implicitCompletion=true]<identifier, term> }
97 101
98ParameterList<content> { "(" sep<",", content> ")" } 102ParameterList<content> { "(" sep<",", content> ")" }
99 103
diff --git a/language-web/src/main/js/language/props.ts b/language-web/src/main/js/language/props.ts
new file mode 100644
index 00000000..8e488bf5
--- /dev/null
+++ b/language-web/src/main/js/language/props.ts
@@ -0,0 +1,7 @@
1import { NodeProp } from '@lezer/common';
2
3export const implicitCompletion = new NodeProp({
4 deserialize(s: string) {
5 return s === 'true';
6 },
7});
diff --git a/language-web/src/main/js/xtext/ContentAssistService.ts b/language-web/src/main/js/xtext/ContentAssistService.ts
index 65381b21..aa9a80b0 100644
--- a/language-web/src/main/js/xtext/ContentAssistService.ts
+++ b/language-web/src/main/js/xtext/ContentAssistService.ts
@@ -7,18 +7,11 @@ import { syntaxTree } from '@codemirror/language';
7import type { Transaction } from '@codemirror/state'; 7import type { Transaction } from '@codemirror/state';
8import escapeStringRegexp from 'escape-string-regexp'; 8import escapeStringRegexp from 'escape-string-regexp';
9 9
10import { implicitCompletion } from '../language/props';
10import type { UpdateService } from './UpdateService'; 11import type { UpdateService } from './UpdateService';
11import { getLogger } from '../utils/logger'; 12import { getLogger } from '../utils/logger';
12import type { IContentAssistEntry } from './xtextServiceResults'; 13import type { IContentAssistEntry } from './xtextServiceResults';
13 14
14const IMPLICIT_COMPLETION_TOKENS = [
15 'QualifiedName',
16 'true',
17 'false',
18 'unknown',
19 'error',
20];
21
22const PROPOSALS_LIMIT = 1000; 15const PROPOSALS_LIMIT = 1000;
23 16
24const IDENTIFIER_REGEXP_STR = '[a-zA-Z0-9_]*'; 17const IDENTIFIER_REGEXP_STR = '[a-zA-Z0-9_]*';
@@ -32,7 +25,7 @@ interface IFoundToken {
32 25
33 to: number; 26 to: number;
34 27
35 name: string; 28 implicitCompletion: boolean;
36 29
37 text: string; 30 text: string;
38} 31}
@@ -50,14 +43,14 @@ function findToken({ pos, state }: CompletionContext): IFoundToken | null {
50 return { 43 return {
51 from: token.from, 44 from: token.from,
52 to: token.to, 45 to: token.to,
53 name: token.name, 46 implicitCompletion: token.type.prop(implicitCompletion) || false,
54 text: state.sliceDoc(token.from, token.to), 47 text: state.sliceDoc(token.from, token.to),
55 }; 48 };
56} 49}
57 50
58function shouldCompleteImplicitly(token: IFoundToken | null, context: CompletionContext): boolean { 51function shouldCompleteImplicitly(token: IFoundToken | null, context: CompletionContext): boolean {
59 return token !== null 52 return token !== null
60 && IMPLICIT_COMPLETION_TOKENS.includes(token.name) 53 && token.implicitCompletion
61 && context.pos - token.from >= 2; 54 && context.pos - token.from >= 2;
62} 55}
63 56
diff --git a/language-web/yarn.lock b/language-web/yarn.lock
index e05f4fa6..06b30508 100644
--- a/language-web/yarn.lock
+++ b/language-web/yarn.lock
@@ -1476,7 +1476,7 @@
1476 resolved "https://registry.yarnpkg.com/@humanwhocodes/object-schema/-/object-schema-1.2.0.tgz#87de7af9c231826fdd68ac7258f77c429e0e5fcf" 1476 resolved "https://registry.yarnpkg.com/@humanwhocodes/object-schema/-/object-schema-1.2.0.tgz#87de7af9c231826fdd68ac7258f77c429e0e5fcf"
1477 integrity sha512-wdppn25U8z/2yiaT6YGquE6X8sSv7hNMWSXYSSU1jGv/yd6XqjXgTDJ8KP4NgjTXfJ3GbRjeeb8RTV7a/VpM+w== 1477 integrity sha512-wdppn25U8z/2yiaT6YGquE6X8sSv7hNMWSXYSSU1jGv/yd6XqjXgTDJ8KP4NgjTXfJ3GbRjeeb8RTV7a/VpM+w==
1478 1478
1479"@lezer/common@^0.15.0", "@lezer/common@^0.15.5": 1479"@lezer/common@^0.15.0", "@lezer/common@^0.15.5", "@lezer/common@^0.15.7":
1480 version "0.15.7" 1480 version "0.15.7"
1481 resolved "https://registry.yarnpkg.com/@lezer/common/-/common-0.15.7.tgz#8b445dae9777f689783132cf490770ece3c03d7b" 1481 resolved "https://registry.yarnpkg.com/@lezer/common/-/common-0.15.7.tgz#8b445dae9777f689783132cf490770ece3c03d7b"
1482 integrity sha512-Rw8TDJnBzZnkyzIXs1Tmmd241FrBLJBj8gkdy3y0joGFb8Z4I/joKEsR+gv1pb13o1TMsZxm3fmP+d/wPt2CTQ== 1482 integrity sha512-Rw8TDJnBzZnkyzIXs1Tmmd241FrBLJBj8gkdy3y0joGFb8Z4I/joKEsR+gv1pb13o1TMsZxm3fmP+d/wPt2CTQ==