Skip to content

Commit 5f762ab

Browse files
authored
feat(completion): add external() {} to completion (#111)
Fixes #85
1 parent ea2a97a commit 5f762ab

File tree

4 files changed

+59
-29
lines changed

4 files changed

+59
-29
lines changed

server/src/completion/providers/MessageMethodCompletionProvider.ts

+32-29
Original file line numberDiff line numberDiff line change
@@ -9,37 +9,40 @@ export class MessageMethodCompletionProvider implements CompletionProvider {
99
}
1010

1111
addCompletion(_ctx: CompletionContext, result: CompletionResult): void {
12-
result.add({
13-
label: "receive",
14-
labelDetails: {
15-
detail: "(msg: <type>) {}",
16-
},
17-
kind: CompletionItemKind.Keyword,
18-
insertText: "receive(msg: $1) {$0}",
19-
insertTextFormat: InsertTextFormat.Snippet,
20-
weight: CompletionWeight.KEYWORD,
21-
})
12+
const options = ["receive", "external"]
13+
options.forEach(name => {
14+
result.add({
15+
label: name,
16+
labelDetails: {
17+
detail: "(msg: <type>) {}",
18+
},
19+
kind: CompletionItemKind.Keyword,
20+
insertText: `${name}(msg: $1) {$0}`,
21+
insertTextFormat: InsertTextFormat.Snippet,
22+
weight: CompletionWeight.KEYWORD,
23+
})
2224

23-
result.add({
24-
label: "receive",
25-
labelDetails: {
26-
detail: `("<message>") {}`,
27-
},
28-
kind: CompletionItemKind.Keyword,
29-
insertText: 'receive("$1") {$0}',
30-
insertTextFormat: InsertTextFormat.Snippet,
31-
weight: CompletionWeight.KEYWORD,
32-
})
25+
result.add({
26+
label: name,
27+
labelDetails: {
28+
detail: `("<message>") {}`,
29+
},
30+
kind: CompletionItemKind.Keyword,
31+
insertText: `${name}("$1") {$0}`,
32+
insertTextFormat: InsertTextFormat.Snippet,
33+
weight: CompletionWeight.KEYWORD,
34+
})
3335

34-
result.add({
35-
label: "receive",
36-
labelDetails: {
37-
detail: `() {}`,
38-
},
39-
kind: CompletionItemKind.Keyword,
40-
insertText: "receive() {$0}",
41-
insertTextFormat: InsertTextFormat.Snippet,
42-
weight: CompletionWeight.KEYWORD,
36+
result.add({
37+
label: name,
38+
labelDetails: {
39+
detail: `() {}`,
40+
},
41+
kind: CompletionItemKind.Keyword,
42+
insertText: `${name}() {$0}`,
43+
insertTextFormat: InsertTextFormat.Snippet,
44+
weight: CompletionWeight.KEYWORD,
45+
})
4346
})
4447

4548
result.add({

server/src/e2e/suite/testcases/completion/constants.test

+6
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@ contract Foo {
4141
------------------------------------------------------------------------
4242
13 bounced(msg: <type>) {}
4343
13 const Foo: <type> = <value>
44+
13 external(msg: <type>) {}
45+
13 external("<message>") {}
46+
13 external() {}
4447
13 fun name() {}
4548
13 get fun name() {}
4649
13 init() {}
@@ -61,6 +64,9 @@ trait Foo {
6164
13 abstract fun name();
6265
13 bounced(msg: <type>) {}
6366
13 const Foo: <type> = <value>
67+
13 external(msg: <type>) {}
68+
13 external("<message>") {}
69+
13 external() {}
6470
13 fun name() {}
6571
13 get fun name() {}
6672
13 init() {}

server/src/e2e/suite/testcases/completion/contracts.test

+3
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ contract Foo {
77
------------------------------------------------------------------------
88
13 bounced(msg: <type>) {}
99
13 const Foo: <type> = <value>
10+
13 external(msg: <type>) {}
11+
13 external("<message>") {}
12+
13 external() {}
1013
13 fun name() {}
1114
13 get fun name() {}
1215
13 init() {}

server/src/e2e/suite/testcases/completion/traits.test

+18
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ trait Child with Parent {
1212
13 abstract fun name();
1313
13 bounced(msg: <type>) {}
1414
13 const Foo: <type> = <value>
15+
13 external(msg: <type>) {}
16+
13 external("<message>") {}
17+
13 external() {}
1518
13 fun name() {}
1619
13 get fun name() {}
1720
13 init() {}
@@ -39,6 +42,9 @@ trait Child with Parent {
3942
13 abstract fun name();
4043
13 bounced(msg: <type>) {}
4144
13 const Foo: <type> = <value>
45+
13 external(msg: <type>) {}
46+
13 external("<message>") {}
47+
13 external() {}
4248
13 fun name() {}
4349
13 get fun name() {}
4450
13 init() {}
@@ -65,6 +71,9 @@ trait Child with Parent {
6571
13 abstract fun name();
6672
13 bounced(msg: <type>) {}
6773
13 const Foo: <type> = <value>
74+
13 external(msg: <type>) {}
75+
13 external("<message>") {}
76+
13 external() {}
6877
13 fun name() {}
6978
13 get fun name() {}
7079
13 init() {}
@@ -91,6 +100,9 @@ trait Child with Parent {
91100
13 abstract fun name();
92101
13 bounced(msg: <type>) {}
93102
13 const Foo: <type> = <value>
103+
13 external(msg: <type>) {}
104+
13 external("<message>") {}
105+
13 external() {}
94106
13 fun name() {}
95107
13 get fun name() {}
96108
13 init() {}
@@ -122,6 +134,9 @@ trait Child with Parent {
122134
13 abstract fun name();
123135
13 bounced(msg: <type>) {}
124136
13 const Foo: <type> = <value>
137+
13 external(msg: <type>) {}
138+
13 external("<message>") {}
139+
13 external() {}
125140
13 fun name() {}
126141
13 get fun name() {}
127142
13 init() {}
@@ -150,6 +165,9 @@ trait Child with Parent {
150165
13 abstract fun name();
151166
13 bounced(msg: <type>) {}
152167
13 const Foo: <type> = <value>
168+
13 external(msg: <type>) {}
169+
13 external("<message>") {}
170+
13 external() {}
153171
13 fun name() {}
154172
13 get fun name() {}
155173
13 init() {}

0 commit comments

Comments
 (0)