Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat: add completion toplevel decorators #799

Merged
merged 6 commits into from
Aug 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#### :rocket: New Feature

- Add support for syntax highlighting in `%raw` and `%ffi` extension points. https://github.com/rescript-lang/rescript-vscode/pull/774
- Add completion to top level decorators. https://github.com/rescript-lang/rescript-vscode/pull/799

#### :bug: Bug Fix

Expand Down
11 changes: 10 additions & 1 deletion analysis/src/CompletionBackEnd.ml
Original file line number Diff line number Diff line change
Expand Up @@ -1475,7 +1475,16 @@ let rec processCompletable ~debug ~full ~scope ~env ~pos ~forHover completable =
let mkDecorator (name, docstring) =
{(Completion.create name ~kind:(Label "") ~env) with docstring}
in
CompletionDecorators.decorators
let isTopLevel = String.starts_with ~prefix:"@" prefix in
let prefix =
if isTopLevel then String.sub prefix 1 (String.length prefix - 1)
else prefix
in
let decorators =
if isTopLevel then CompletionDecorators.toplevel
else CompletionDecorators.local
in
decorators
|> List.filter (fun (decorator, _) -> Utils.startsWith decorator prefix)
|> List.map (fun (decorator, doc) ->
let parts = String.split_on_char '.' prefix in
Expand Down
25 changes: 24 additions & 1 deletion analysis/src/CompletionDecorators.ml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
let decorators =
let local =
[
( "as",
[
Expand Down Expand Up @@ -221,3 +221,26 @@ Note: The `@react.component` decorator requires the react-jsx config to be set i
[Read more and see examples in the documentation](https://rescript-lang.org/syntax-lookup#variadic-decorator).|};
] );
]

let toplevel =
[
( "deprecated",
[
{|The `@@deprecated` decorator is used to add a deprecation note to the file-level of a module. The compiler and editor tooling will yield a warning whenever a deprecated file module is being used.

[Read more and see examples in the documentation](https://rescript-lang.org/syntax-lookup#module-deprecated-decorator).|};
] );
( "directive",
[
{|The `@@directive` decorator will output that string verbatim at the very top of the generated JavaScript file, before any imports.

[Read more and see examples in the documentation](https://rescript-lang.org/syntax-lookup#directive-decorator).|};
] );
( "warning",
[
{|The `@@warning` decorator is used to modify the enabled compiler warnings for the current module. See here for all available warning numbers.

[Read more and see examples in the documentation](https://rescript-lang.org/syntax-lookup#module-warning-decorator).
|};
] );
]