From 57375c46bddb4d02089e609b366b569a4dc1e87f Mon Sep 17 00:00:00 2001 From: Pedro Castro Date: Sat, 5 Aug 2023 20:11:11 -0300 Subject: [PATCH 1/6] add completion to toplevel decorators --- analysis/src/CompletionBackEnd.ml | 22 +++++++- analysis/src/CompletionDecorators.ml | 79 +++++++++++++++++----------- 2 files changed, 68 insertions(+), 33 deletions(-) diff --git a/analysis/src/CompletionBackEnd.ml b/analysis/src/CompletionBackEnd.ml index 47b3ccd5d..fdb3aa3fa 100644 --- a/analysis/src/CompletionBackEnd.ml +++ b/analysis/src/CompletionBackEnd.ml @@ -1475,9 +1475,29 @@ let rec processCompletable ~debug ~full ~scope ~env ~pos ~forHover completable = let mkDecorator (name, docstring) = {(Completion.create name ~kind:(Label "") ~env) with docstring} in + let isTopLevel = String.starts_with ~prefix:"@" prefix in + let prefix = + if isTopLevel then String.sub prefix 1 (String.length prefix - 1) + else prefix + in CompletionDecorators.decorators - |> List.filter (fun (decorator, _) -> Utils.startsWith decorator prefix) + |> List.filter (fun (decorator, _) -> + match isTopLevel with + | true -> ( + match decorator with + | CompletionDecorators.TopLevel s | TopLevelOrLocal s -> + Utils.startsWith s prefix + | _ -> false) + | false -> ( + match decorator with + | CompletionDecorators.Local s -> Utils.startsWith s prefix + | _ -> false)) |> List.map (fun (decorator, doc) -> + let decorator = + match decorator with + | CompletionDecorators.Local s | TopLevel s | TopLevelOrLocal s -> + s + in let parts = String.split_on_char '.' prefix in let len = String.length prefix in let dec2 = diff --git a/analysis/src/CompletionDecorators.ml b/analysis/src/CompletionDecorators.ml index 952434647..e57825efb 100644 --- a/analysis/src/CompletionDecorators.ml +++ b/analysis/src/CompletionDecorators.ml @@ -1,6 +1,8 @@ +type kind = TopLevel of string | Local of string | TopLevelOrLocal of string + let decorators = [ - ( "as", + ( Local "as", [ {|The `@as` decorator is commonly used on record types to alias record field names to a different JavaScript attribute name. @@ -10,7 +12,7 @@ It is also possible to map a ReScript record to a JavaScript array by passing in [Read more and see examples in the documentation](https://rescript-lang.org/syntax-lookup#as-decorator).|}; ] ); - ( "dead", + ( Local "dead", [ {|The `@dead` decorator is for reanalyze, a static analysis tool for ReScript that can do dead code analysis. @@ -20,13 +22,13 @@ It is also possible to map a ReScript record to a JavaScript array by passing in > Hint: Did you know you can run an interactive code analysis in your project by running the command `> ReScript: Start Code Analyzer`? Try it!|}; ] ); - ( "deriving", + ( Local "deriving", [ {|When the `@deriving` decorator is applied to a record type, it expands the type into a factory function plus a set of getter/setter functions for its fields. [Read more and see examples in the documentation](https://rescript-lang.org/syntax-lookup#deriving-decorator).|}; ] ); - ( "deprecated", + ( TopLevelOrLocal "deprecated", [ {|The `@deprecated` decorator is used to add deprecation notes to types, values and submodules. The compiler and editor tooling will yield a warning whenever a deprecated entity is being used. @@ -34,7 +36,7 @@ Alternatively, use the `@@deprecated` decorator to add a deprecation warning to [Read more and see examples in the documentation](https://rescript-lang.org/syntax-lookup#expression-deprecated-decorator).|}; ] ); - ( "doesNotRaise", + ( Local "doesNotRaise", [ {|The `@doesNotRaise` decorator is for reanalyze, a static analysis tool for ReScript that can perform exception analysis. @@ -45,55 +47,55 @@ could potentially raise. [Read more and see examples in the documentation](https://github.com/rescript-association/reanalyze/blob/master/EXCEPTION.md). > Hint: Did you know you can run an interactive code analysis in your project by running the command `> ReScript: Start Code Analyzer`? Try it!|}; ] ); - ( "genType", + ( Local "genType", [ {|The @genType decorator may be used to export ReScript values and types to JavaScript, and import JavaScript values and types into ReScript. It allows seamless integration of compiled ReScript modules in existing TypeScript, Flow, or plain JavaScript codebases, without loosing type information across different type systems. [Read more and see examples in the documentation](https://rescript-lang.org/syntax-lookup#gentype-decorator).|}; ] ); - ( "genType.as", + ( Local "genType.as", [ {|The @genType decorator may be used to export ReScript values and types to JavaScript, and import JavaScript values and types into ReScript. It allows seamless integration of compiled ReScript modules in existing TypeScript, Flow, or plain JavaScript codebases, without loosing type information across different type systems. [Read more and see examples in the documentation](https://rescript-lang.org/docs/gentype/latest/usage).|}; ] ); - ( "genType.import", + ( Local "genType.import", [ {|The @genType decorator may be used to export ReScript values and types to JavaScript, and import JavaScript values and types into ReScript. It allows seamless integration of compiled ReScript modules in existing TypeScript, Flow, or plain JavaScript codebases, without loosing type information across different type systems. [Read more and see examples in the documentation](https://rescript-lang.org/docs/gentype/latest/usage).|}; ] ); - ( "genType.opaque", + ( Local "genType.opaque", [ {|The @genType decorator may be used to export ReScript values and types to JavaScript, and import JavaScript values and types into ReScript. It allows seamless integration of compiled ReScript modules in existing TypeScript, Flow, or plain JavaScript codebases, without loosing type information across different type systems. [Read more and see examples in the documentation](https://rescript-lang.org/docs/gentype/latest/usage).|}; ] ); - ( "get", + ( Local "get", [ {|The `@get` decorator is used to bind to a property of an object. [Read more and see examples in the documentation](https://rescript-lang.org/syntax-lookup#get-decorator).|}; ] ); - ( "get_index", + ( Local "get_index", [ {|The `@get_index` decorator is used to access a dynamic property on an object, or an index of an array. [Read more and see examples in the documentation](https://rescript-lang.org/syntax-lookup#get-index-decorator).|}; ] ); - ( "inline", + ( Local "inline", [ {|The `@inline` decorator tells the compiler to inline its value in every place the binding is being used, rather than use a variable. [Read more and see examples in the documentation](https://rescript-lang.org/syntax-lookup#inline-decorator).|}; ] ); - ( "int", + ( Local "int", [ {|The `@int` decorator can be used with polymorphic variants and the @as decorator on externals to modify the compiled JavaScript to use integers for the values instead of strings. [Read more and see examples in the documentation](https://rescript-lang.org/syntax-lookup#int-decorator).|}; ] ); - ( "live", + ( Local "live", [ {|The `@live` decorator is for reanalyze, a static analysis tool for ReScript that can do dead code analysis. @@ -103,32 +105,32 @@ could potentially raise. Hint: Did you know you can run an interactive code analysis in your project by running the command `> ReScript: Start Code Analyzer`? Try it!|}; ] ); - ( "meth", + ( Local "meth", [ {|The `@meth` decorator is used to call a function on a JavaScript object, and avoid issues with currying. [Read more and see examples in the documentation](https://rescript-lang.org/syntax-lookup#meth-decorator).|}; ] ); - ( "module", + ( Local "module", [ {|The `@module` decorator is used to bind to a JavaScript module. [Read more and see examples in the documentation](https://rescript-lang.org/syntax-lookup#module-decorator).|}; ] ); - ( "new", + ( Local "new", [ {| The `@new` decorator is used whenever you need to bind to a JavaScript class constructor that requires the new keword for instantiation.| [Read more and see examples in the documentation](https://rescript-lang.org/syntax-lookup#new-decorator).|}; ] ); - ( "obj", + ( Local "obj", [ {|The `@obj` decorator is used to create functions that return JavaScript objects with properties that match the function's parameter labels. [Read more and see examples in the documentation](https://rescript-lang.org/syntax-lookup#obj-decorator).|}; ] ); - ( "raises", + ( Local "raises", [ {|The `@raises` decorator is for reanalyze, a static analysis tool for ReScript that can perform exception analysis. @@ -138,7 +140,7 @@ Example `@raises(Exn)` or `@raises([E1, E2, E3])` for multiple exceptions. [Read more and see examples in the documentation](https://github.com/rescript-association/reanalyze/blob/master/EXCEPTION.md). > Hint: Did you know you can run an interactive code analysis in your project by running the command `> ReScript: Start Code Analyzer`? Try it!|}; ] ); - ( "react.component", + ( Local "react.component", [ {|The `@react.component` decorator is used to annotate functions that are RescriptReact components. @@ -148,76 +150,89 @@ 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#react-component-decorator).|}; ] ); - ( "return", + ( Local "return", [ {|The `@return` decorator is used to control how `null` and `undefined` values are converted to option types in ReScript. [Read more and see examples in the documentation](https://rescript-lang.org/syntax-lookup#return-decorator).|}; ] ); - ( "scope", + ( Local "scope", [ {|The `@scope` decorator is used with other decorators such as `@val` and `@module` to declare a parent scope for the binding. [Read more and see examples in the documentation](https://rescript-lang.org/syntax-lookup#scope-decorator).|}; ] ); - ( "send", + ( Local "send", [ {|The `@send` decorator is used to bind to a method on an object or array. [Read more and see examples in the documentation](https://rescript-lang.org/syntax-lookup#send-decorator).|}; ] ); - ( "set", + ( Local "set", [ {|The `@set` decorator is used to set a property of an object. [Read more and see examples in the documentation](https://rescript-lang.org/syntax-lookup#set-decorator).|}; ] ); - ( "set_index", + ( Local "set_index", [ {|The `@set_index` decorator is used to set a dynamic property on an object, or an index of an array. [Read more and see examples in the documentation](https://rescript-lang.org/syntax-lookup#set-index-decorator).|}; ] ); - ( "string", + ( Local "string", [ {|The `@string` decorator can be used with polymorphic variants and the `@as` decorator on externals to modify the string values used for the variants in the compiled JavaScript. [Read more and see examples in the documentation](https://rescript-lang.org/syntax-lookup#string-decorator).|}; ] ); - ( "this", + ( Local "this", [ {|The `@this` decorator may be used to bind to an external callback function that require access to a this context. [Read more and see examples in the documentation](https://rescript-lang.org/syntax-lookup#this-decorator).|}; ] ); - ( "unboxed", + ( Local "unboxed", [ {|The `@unboxed` decorator provides a way to unwrap variant constructors that have a single argument, or record objects that have a single field. [Read more and see examples in the documentation](https://rescript-lang.org/syntax-lookup#unboxed-decorator).|}; ] ); - ( "uncurry", + ( Local "uncurry", [ {|The `@uncurry` decorator can be used to mark any callback argument within an external function as an uncurried function without the need for any explicit uncurried function syntax (`(.) => { ... }`). [Read more and see examples in the documentation](https://rescript-lang.org/syntax-lookup#uncurry-decorator).|}; ] ); - ( "unwrap", + ( Local "unwrap", [ {|The `@unwrap` decorator may be used when binding to external functions that accept multiple types for an argument. [Read more and see examples in the documentation](https://rescript-lang.org/syntax-lookup#unwrap-decorator).|}; ] ); - ( "val", + ( Local "val", [ {|The `@val` decorator allows you to bind to JavaScript values that are on the global scope. [Read more and see examples in the documentation](https://rescript-lang.org/syntax-lookup#val-decorator).|}; ] ); - ( "variadic", + ( Local "variadic", [ {|The `@variadic` decorator is used to model JavaScript functions that take a variable number of arguments, where all arguments are of the same type. [Read more and see examples in the documentation](https://rescript-lang.org/syntax-lookup#variadic-decorator).|}; ] ); + ( TopLevel "directive", + [ + {|The `@@directive` 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).|}; + ] ); + ( TopLevel "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). + |}; + ] ); ] From 3d6d56a1177ae1721efeb2b48e94ca06850c507f Mon Sep 17 00:00:00 2001 From: Pedro Castro Date: Sat, 5 Aug 2023 20:13:44 -0300 Subject: [PATCH 2/6] update text --- analysis/src/CompletionDecorators.ml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/analysis/src/CompletionDecorators.ml b/analysis/src/CompletionDecorators.ml index e57825efb..4c9f3502b 100644 --- a/analysis/src/CompletionDecorators.ml +++ b/analysis/src/CompletionDecorators.ml @@ -224,13 +224,13 @@ Note: The `@react.component` decorator requires the react-jsx config to be set i ] ); ( TopLevel "directive", [ - {|The `@@directive` will output that string verbatim at the very top of the generated JavaScript file, before any imports. + {|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).|}; ] ); ( TopLevel "warning", [ - {|The @@warning decorator is used to modify the enabled compiler warnings for the current module. See here for all available warning numbers. + {|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). |}; From fb514b023db1aa0da2bad9abea27021e917950bd Mon Sep 17 00:00:00 2001 From: Pedro Castro Date: Sat, 5 Aug 2023 20:35:07 -0300 Subject: [PATCH 3/6] update CHANGELOG.md --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) 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 From 4a4a3520ec1bdbe53c6c5413031367736c91d605 Mon Sep 17 00:00:00 2001 From: Pedro Castro Date: Tue, 8 Aug 2023 21:14:00 -0300 Subject: [PATCH 4/6] refactor --- analysis/src/CompletionBackEnd.ml | 32 ++----- analysis/src/CompletionDecorators.ml | 84 ++++++++++--------- .../tests/src/expected/Completion.res.txt | 2 +- 3 files changed, 52 insertions(+), 66 deletions(-) diff --git a/analysis/src/CompletionBackEnd.ml b/analysis/src/CompletionBackEnd.ml index fdb3aa3fa..1225026bc 100644 --- a/analysis/src/CompletionBackEnd.ml +++ b/analysis/src/CompletionBackEnd.ml @@ -1480,32 +1480,12 @@ let rec processCompletable ~debug ~full ~scope ~env ~pos ~forHover completable = if isTopLevel then String.sub prefix 1 (String.length prefix - 1) else prefix in - CompletionDecorators.decorators - |> List.filter (fun (decorator, _) -> - match isTopLevel with - | true -> ( - match decorator with - | CompletionDecorators.TopLevel s | TopLevelOrLocal s -> - Utils.startsWith s prefix - | _ -> false) - | false -> ( - match decorator with - | CompletionDecorators.Local s -> Utils.startsWith s prefix - | _ -> false)) - |> List.map (fun (decorator, doc) -> - let decorator = - match decorator with - | CompletionDecorators.Local s | TopLevel s | TopLevelOrLocal s -> - s - in - let parts = String.split_on_char '.' prefix in - let len = String.length prefix in - let dec2 = - if List.length parts > 1 then - String.sub decorator len (String.length decorator - len) - else decorator - in - (dec2, doc)) + let decorators = + if isTopLevel then CompletionDecorators.toplevel + else CompletionDecorators.local + in + decorators + |> List.filter (fun (decorator, _) -> Utils.startsWith decorator prefix) |> List.map mkDecorator | CnamedArg (cp, prefix, identsSeen) -> let labels = diff --git a/analysis/src/CompletionDecorators.ml b/analysis/src/CompletionDecorators.ml index 4c9f3502b..21f93779d 100644 --- a/analysis/src/CompletionDecorators.ml +++ b/analysis/src/CompletionDecorators.ml @@ -1,8 +1,6 @@ -type kind = TopLevel of string | Local of string | TopLevelOrLocal of string - -let decorators = +let local = [ - ( Local "as", + ( "as", [ {|The `@as` decorator is commonly used on record types to alias record field names to a different JavaScript attribute name. @@ -12,7 +10,7 @@ It is also possible to map a ReScript record to a JavaScript array by passing in [Read more and see examples in the documentation](https://rescript-lang.org/syntax-lookup#as-decorator).|}; ] ); - ( Local "dead", + ( "dead", [ {|The `@dead` decorator is for reanalyze, a static analysis tool for ReScript that can do dead code analysis. @@ -22,21 +20,19 @@ It is also possible to map a ReScript record to a JavaScript array by passing in > Hint: Did you know you can run an interactive code analysis in your project by running the command `> ReScript: Start Code Analyzer`? Try it!|}; ] ); - ( Local "deriving", + ( "deriving", [ {|When the `@deriving` decorator is applied to a record type, it expands the type into a factory function plus a set of getter/setter functions for its fields. [Read more and see examples in the documentation](https://rescript-lang.org/syntax-lookup#deriving-decorator).|}; ] ); - ( TopLevelOrLocal "deprecated", + ( "deprecated", [ {|The `@deprecated` decorator is used to add deprecation notes to types, values and submodules. The compiler and editor tooling will yield a warning whenever a deprecated entity is being used. -Alternatively, use the `@@deprecated` decorator to add a deprecation warning to the file level. - [Read more and see examples in the documentation](https://rescript-lang.org/syntax-lookup#expression-deprecated-decorator).|}; ] ); - ( Local "doesNotRaise", + ( "doesNotRaise", [ {|The `@doesNotRaise` decorator is for reanalyze, a static analysis tool for ReScript that can perform exception analysis. @@ -47,55 +43,55 @@ could potentially raise. [Read more and see examples in the documentation](https://github.com/rescript-association/reanalyze/blob/master/EXCEPTION.md). > Hint: Did you know you can run an interactive code analysis in your project by running the command `> ReScript: Start Code Analyzer`? Try it!|}; ] ); - ( Local "genType", + ( "genType", [ {|The @genType decorator may be used to export ReScript values and types to JavaScript, and import JavaScript values and types into ReScript. It allows seamless integration of compiled ReScript modules in existing TypeScript, Flow, or plain JavaScript codebases, without loosing type information across different type systems. [Read more and see examples in the documentation](https://rescript-lang.org/syntax-lookup#gentype-decorator).|}; ] ); - ( Local "genType.as", + ( "genType.as", [ {|The @genType decorator may be used to export ReScript values and types to JavaScript, and import JavaScript values and types into ReScript. It allows seamless integration of compiled ReScript modules in existing TypeScript, Flow, or plain JavaScript codebases, without loosing type information across different type systems. [Read more and see examples in the documentation](https://rescript-lang.org/docs/gentype/latest/usage).|}; ] ); - ( Local "genType.import", + ( "genType.import", [ {|The @genType decorator may be used to export ReScript values and types to JavaScript, and import JavaScript values and types into ReScript. It allows seamless integration of compiled ReScript modules in existing TypeScript, Flow, or plain JavaScript codebases, without loosing type information across different type systems. [Read more and see examples in the documentation](https://rescript-lang.org/docs/gentype/latest/usage).|}; ] ); - ( Local "genType.opaque", + ( "genType.opaque", [ {|The @genType decorator may be used to export ReScript values and types to JavaScript, and import JavaScript values and types into ReScript. It allows seamless integration of compiled ReScript modules in existing TypeScript, Flow, or plain JavaScript codebases, without loosing type information across different type systems. [Read more and see examples in the documentation](https://rescript-lang.org/docs/gentype/latest/usage).|}; ] ); - ( Local "get", + ( "get", [ {|The `@get` decorator is used to bind to a property of an object. [Read more and see examples in the documentation](https://rescript-lang.org/syntax-lookup#get-decorator).|}; ] ); - ( Local "get_index", + ( "get_index", [ {|The `@get_index` decorator is used to access a dynamic property on an object, or an index of an array. [Read more and see examples in the documentation](https://rescript-lang.org/syntax-lookup#get-index-decorator).|}; ] ); - ( Local "inline", + ( "inline", [ {|The `@inline` decorator tells the compiler to inline its value in every place the binding is being used, rather than use a variable. [Read more and see examples in the documentation](https://rescript-lang.org/syntax-lookup#inline-decorator).|}; ] ); - ( Local "int", + ( "int", [ {|The `@int` decorator can be used with polymorphic variants and the @as decorator on externals to modify the compiled JavaScript to use integers for the values instead of strings. [Read more and see examples in the documentation](https://rescript-lang.org/syntax-lookup#int-decorator).|}; ] ); - ( Local "live", + ( "live", [ {|The `@live` decorator is for reanalyze, a static analysis tool for ReScript that can do dead code analysis. @@ -105,32 +101,32 @@ could potentially raise. Hint: Did you know you can run an interactive code analysis in your project by running the command `> ReScript: Start Code Analyzer`? Try it!|}; ] ); - ( Local "meth", + ( "meth", [ {|The `@meth` decorator is used to call a function on a JavaScript object, and avoid issues with currying. [Read more and see examples in the documentation](https://rescript-lang.org/syntax-lookup#meth-decorator).|}; ] ); - ( Local "module", + ( "module", [ {|The `@module` decorator is used to bind to a JavaScript module. [Read more and see examples in the documentation](https://rescript-lang.org/syntax-lookup#module-decorator).|}; ] ); - ( Local "new", + ( "new", [ {| The `@new` decorator is used whenever you need to bind to a JavaScript class constructor that requires the new keword for instantiation.| [Read more and see examples in the documentation](https://rescript-lang.org/syntax-lookup#new-decorator).|}; ] ); - ( Local "obj", + ( "obj", [ {|The `@obj` decorator is used to create functions that return JavaScript objects with properties that match the function's parameter labels. [Read more and see examples in the documentation](https://rescript-lang.org/syntax-lookup#obj-decorator).|}; ] ); - ( Local "raises", + ( "raises", [ {|The `@raises` decorator is for reanalyze, a static analysis tool for ReScript that can perform exception analysis. @@ -140,7 +136,7 @@ Example `@raises(Exn)` or `@raises([E1, E2, E3])` for multiple exceptions. [Read more and see examples in the documentation](https://github.com/rescript-association/reanalyze/blob/master/EXCEPTION.md). > Hint: Did you know you can run an interactive code analysis in your project by running the command `> ReScript: Start Code Analyzer`? Try it!|}; ] ); - ( Local "react.component", + ( "react.component", [ {|The `@react.component` decorator is used to annotate functions that are RescriptReact components. @@ -150,85 +146,95 @@ 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#react-component-decorator).|}; ] ); - ( Local "return", + ( "return", [ {|The `@return` decorator is used to control how `null` and `undefined` values are converted to option types in ReScript. [Read more and see examples in the documentation](https://rescript-lang.org/syntax-lookup#return-decorator).|}; ] ); - ( Local "scope", + ( "scope", [ {|The `@scope` decorator is used with other decorators such as `@val` and `@module` to declare a parent scope for the binding. [Read more and see examples in the documentation](https://rescript-lang.org/syntax-lookup#scope-decorator).|}; ] ); - ( Local "send", + ( "send", [ {|The `@send` decorator is used to bind to a method on an object or array. [Read more and see examples in the documentation](https://rescript-lang.org/syntax-lookup#send-decorator).|}; ] ); - ( Local "set", + ( "set", [ {|The `@set` decorator is used to set a property of an object. [Read more and see examples in the documentation](https://rescript-lang.org/syntax-lookup#set-decorator).|}; ] ); - ( Local "set_index", + ( "set_index", [ {|The `@set_index` decorator is used to set a dynamic property on an object, or an index of an array. [Read more and see examples in the documentation](https://rescript-lang.org/syntax-lookup#set-index-decorator).|}; ] ); - ( Local "string", + ( "string", [ {|The `@string` decorator can be used with polymorphic variants and the `@as` decorator on externals to modify the string values used for the variants in the compiled JavaScript. [Read more and see examples in the documentation](https://rescript-lang.org/syntax-lookup#string-decorator).|}; ] ); - ( Local "this", + ( "this", [ {|The `@this` decorator may be used to bind to an external callback function that require access to a this context. [Read more and see examples in the documentation](https://rescript-lang.org/syntax-lookup#this-decorator).|}; ] ); - ( Local "unboxed", + ( "unboxed", [ {|The `@unboxed` decorator provides a way to unwrap variant constructors that have a single argument, or record objects that have a single field. [Read more and see examples in the documentation](https://rescript-lang.org/syntax-lookup#unboxed-decorator).|}; ] ); - ( Local "uncurry", + ( "uncurry", [ {|The `@uncurry` decorator can be used to mark any callback argument within an external function as an uncurried function without the need for any explicit uncurried function syntax (`(.) => { ... }`). [Read more and see examples in the documentation](https://rescript-lang.org/syntax-lookup#uncurry-decorator).|}; ] ); - ( Local "unwrap", + ( "unwrap", [ {|The `@unwrap` decorator may be used when binding to external functions that accept multiple types for an argument. [Read more and see examples in the documentation](https://rescript-lang.org/syntax-lookup#unwrap-decorator).|}; ] ); - ( Local "val", + ( "val", [ {|The `@val` decorator allows you to bind to JavaScript values that are on the global scope. [Read more and see examples in the documentation](https://rescript-lang.org/syntax-lookup#val-decorator).|}; ] ); - ( Local "variadic", + ( "variadic", [ {|The `@variadic` decorator is used to model JavaScript functions that take a variable number of arguments, where all arguments are of the same type. [Read more and see examples in the documentation](https://rescript-lang.org/syntax-lookup#variadic-decorator).|}; ] ); - ( TopLevel "directive", + ] + +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).|}; ] ); - ( TopLevel "warning", + ( "warning", [ {|The `@@warning` decorator is used to modify the enabled compiler warnings for the current module. See here for all available warning numbers. diff --git a/analysis/tests/src/expected/Completion.res.txt b/analysis/tests/src/expected/Completion.res.txt index 560385753..b02ca2840 100644 --- a/analysis/tests/src/expected/Completion.res.txt +++ b/analysis/tests/src/expected/Completion.res.txt @@ -564,7 +564,7 @@ Completable: Cdecorator(react.) Package opens Pervasives.JsxModules.place holder Resolved opens 1 pervasives [{ - "label": "component", + "label": "react.component", "kind": 4, "tags": [], "detail": "", From bb29048eef2bb43a38445168b028bb80c49fc76d Mon Sep 17 00:00:00 2001 From: Pedro Castro Date: Wed, 9 Aug 2023 11:37:55 -0300 Subject: [PATCH 5/6] revert change --- analysis/src/CompletionBackEnd.ml | 9 +++++++++ analysis/tests/src/expected/Completion.res.txt | 2 +- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/analysis/src/CompletionBackEnd.ml b/analysis/src/CompletionBackEnd.ml index 1225026bc..2cf5d183f 100644 --- a/analysis/src/CompletionBackEnd.ml +++ b/analysis/src/CompletionBackEnd.ml @@ -1486,6 +1486,15 @@ let rec processCompletable ~debug ~full ~scope ~env ~pos ~forHover completable = in decorators |> List.filter (fun (decorator, _) -> Utils.startsWith decorator prefix) + |> List.map (fun (decorator, doc) -> + let parts = String.split_on_char '.' prefix in + let len = String.length prefix in + let dec2 = + if List.length parts > 1 then + String.sub decorator len (String.length decorator - len) + else decorator + in + (dec2, doc)) |> List.map mkDecorator | CnamedArg (cp, prefix, identsSeen) -> let labels = diff --git a/analysis/tests/src/expected/Completion.res.txt b/analysis/tests/src/expected/Completion.res.txt index b02ca2840..560385753 100644 --- a/analysis/tests/src/expected/Completion.res.txt +++ b/analysis/tests/src/expected/Completion.res.txt @@ -564,7 +564,7 @@ Completable: Cdecorator(react.) Package opens Pervasives.JsxModules.place holder Resolved opens 1 pervasives [{ - "label": "react.component", + "label": "component", "kind": 4, "tags": [], "detail": "", From e3e0463259bc85ee4ac86ebf71ec3fc581ebda33 Mon Sep 17 00:00:00 2001 From: Pedro Castro Date: Sat, 12 Aug 2023 18:31:39 -0300 Subject: [PATCH 6/6] add note for @@deprecated --- analysis/src/CompletionDecorators.ml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/analysis/src/CompletionDecorators.ml b/analysis/src/CompletionDecorators.ml index 21f93779d..f8beb7910 100644 --- a/analysis/src/CompletionDecorators.ml +++ b/analysis/src/CompletionDecorators.ml @@ -30,6 +30,8 @@ It is also possible to map a ReScript record to a JavaScript array by passing in [ {|The `@deprecated` decorator is used to add deprecation notes to types, values and submodules. The compiler and editor tooling will yield a warning whenever a deprecated entity is being used. +Alternatively, use the `@@deprecated` decorator to add a deprecation warning to the file level. + [Read more and see examples in the documentation](https://rescript-lang.org/syntax-lookup#expression-deprecated-decorator).|}; ] ); ( "doesNotRaise",