Skip to content
This repository was archived by the owner on Apr 24, 2021. It is now read-only.

Commit 5afdd84

Browse files
committed
Add support for autocomplete for decorators such as @module and @val.
Fixes rescript-lang/rescript-vscode#26
1 parent d731ecc commit 5afdd84

File tree

5 files changed

+56
-4
lines changed

5 files changed

+56
-4
lines changed

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,6 @@ npm-debug.log
44
*.install
55
_build
66
editor-extensions/vscode/*.zip
7+
examples/*/node_modules
8+
examples/*/lib
9+
editor-extensions/vscode/node_modules

Changes.md

+7-1
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,18 @@
11
## master
2+
- Add support for autocomplete for `foo->`: the type of `foo` is used to determine the module to take completions from.
3+
- Add support for autocomplete for decorators such as `@module` and `@val`.
4+
5+
## Release 1.0.5 of rescript-vscode
6+
This [commit](https://github.com/rescript-lang/rescript-editor-support/commit/6bdd10f6af259edc5f9cbe5b9df06836de3ab865) is vendored in [rescript-vscode 1.0.5](https://github.com/rescript-lang/rescript-vscode/releases/tag/1.0.5).
7+
28
- Add support for doc strings when hovering on modules.
39
- Add support for printing uncurried function types in hover.
410
- Fix autocomplete issue where `open Foo` would be picked up inside line comments (see https://github.com/rescript-lang/rescript-editor-support/issues/15).
511
- Don't print parens as in `A()` for 0-ary variants.
612
- Fix infinite loop in autocomplete that can cause `rescript-editor-support.exe` processes to use up 100% cpu.
713
- Fix jump to type definition for types defined in an inner module.
814

9-
## Release 1.0.3 of rescript-vscode
15+
## Release 1.0.3 of rescript-vscode
1016
This [commit](https://github.com/rescript-lang/rescript-editor-support/commit/214d220d8573f9f0c8d54e623c163e01617bf124) is vendored in [rescript-vscode 1.0.3](https://github.com/rescript-lang/rescript-vscode/releases/tag/1.0.3).
1117

1218
- Fix type shown when hovering on record fields (see https://github.com/rescript-lang/rescript-vscode/issues/52), and doc comments for records.

src/rescript-editor-support/NewCompletions.re

+42
Original file line numberDiff line numberDiff line change
@@ -778,6 +778,48 @@ let computeCompletions = (~full, ~maybeText, ~package, ~pos, ~state) => {
778778
| None => []
779779
};
780780

781+
| Some((_, _, Some(Cdecorator(prefix)))) =>
782+
let mkDecorator = name =>
783+
mkItem(
784+
~name,
785+
~kind=4,
786+
~detail="",
787+
~docstring=None,
788+
~uri=full.file.uri,
789+
~pos_lnum=fst(pos),
790+
);
791+
[
792+
"as",
793+
"deriving",
794+
"genType",
795+
"genType.as",
796+
"genType.import",
797+
"genType.opaque",
798+
"get",
799+
"get_index",
800+
"inline",
801+
"int",
802+
"meth",
803+
"module",
804+
"new",
805+
"obj",
806+
"react.component",
807+
"return",
808+
"scope",
809+
"send",
810+
"set",
811+
"set_index",
812+
"string",
813+
"this",
814+
"unboxed",
815+
"uncurry",
816+
"unwrap",
817+
"val",
818+
"variadic",
819+
]
820+
|> List.filter(decorator => Utils.startsWith(decorator, prefix))
821+
|> List.map(mkDecorator);
822+
781823
| Some((_, _, Some(Clabel(_)))) =>
782824
// not supported yet
783825
[]

src/rescript-editor-support/PartialParser.re

+2
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ let rec startOfLident = (text, i) =>
6565
};
6666

6767
type completable =
68+
| Cdecorator(string)
6869
| Clabel(string)
6970
| Cpath(list(string))
7071
| Cpipe(string);
@@ -92,6 +93,7 @@ let findCompletable = (text, offset) => {
9293
switch (text.[i]) {
9394
| '>' when i > 0 && text.[i - 1] == '-' => loop(i - 2)
9495
| '~' => Some(Clabel(String.sub(text, i + 1, offset - (i + 1))))
96+
| '@' => Some(Cdecorator(String.sub(text, i + 1, offset - (i + 1))))
9597
| 'a'..'z'
9698
| 'A'..'Z'
9799
| '0'..'9'

src/rescript-editor-support/RescriptEditorSupport.re

+2-3
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ let capabilities =
77
("hoverProvider", J.t),
88
(
99
"completionProvider",
10-
J.o([("triggerCharacters", J.l([J.s("."), J.s(">")]))]),
10+
J.o([("triggerCharacters", J.l([J.s("."), J.s(">"), J.s("@")]))]),
1111
),
1212
("definitionProvider", J.t),
1313
("typeDefinitionProvider", J.t),
@@ -19,8 +19,7 @@ let capabilities =
1919
]);
2020

2121
let getInitialState = params => {
22-
let rootUri =
23-
Json.get("rootUri", params) |?> Json.string |?> Uri2.parse;
22+
let rootUri = Json.get("rootUri", params) |?> Json.string |?> Uri2.parse;
2423
let%try rootUri = rootUri |> RResult.orError("Not a uri");
2524
let rootPath = Uri2.toPath(rootUri);
2625

0 commit comments

Comments
 (0)