diff --git a/CHANGELOG.md b/CHANGELOG.md index 40ca6a0b3..f272aaacc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/analysis/src/CompletionBackEnd.ml b/analysis/src/CompletionBackEnd.ml index 47b3ccd5d..2cf5d183f 100644 --- a/analysis/src/CompletionBackEnd.ml +++ b/analysis/src/CompletionBackEnd.ml @@ -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 diff --git a/analysis/src/CompletionDecorators.ml b/analysis/src/CompletionDecorators.ml index 952434647..f8beb7910 100644 --- a/analysis/src/CompletionDecorators.ml +++ b/analysis/src/CompletionDecorators.ml @@ -1,4 +1,4 @@ -let decorators = +let local = [ ( "as", [ @@ -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). + |}; + ] ); + ]