Skip to content

Commit bb4adcd

Browse files
aspeddrozth
authored andcommitted
refactor
1 parent c1a5ff2 commit bb4adcd

File tree

3 files changed

+52
-66
lines changed

3 files changed

+52
-66
lines changed

analysis/src/CompletionBackEnd.ml

+6-26
Original file line numberDiff line numberDiff line change
@@ -1480,32 +1480,12 @@ let rec processCompletable ~debug ~full ~scope ~env ~pos ~forHover completable =
14801480
if isTopLevel then String.sub prefix 1 (String.length prefix - 1)
14811481
else prefix
14821482
in
1483-
CompletionDecorators.decorators
1484-
|> List.filter (fun (decorator, _) ->
1485-
match isTopLevel with
1486-
| true -> (
1487-
match decorator with
1488-
| CompletionDecorators.TopLevel s | TopLevelOrLocal s ->
1489-
Utils.startsWith s prefix
1490-
| _ -> false)
1491-
| false -> (
1492-
match decorator with
1493-
| CompletionDecorators.Local s -> Utils.startsWith s prefix
1494-
| _ -> false))
1495-
|> List.map (fun (decorator, doc) ->
1496-
let decorator =
1497-
match decorator with
1498-
| CompletionDecorators.Local s | TopLevel s | TopLevelOrLocal s ->
1499-
s
1500-
in
1501-
let parts = String.split_on_char '.' prefix in
1502-
let len = String.length prefix in
1503-
let dec2 =
1504-
if List.length parts > 1 then
1505-
String.sub decorator len (String.length decorator - len)
1506-
else decorator
1507-
in
1508-
(dec2, doc))
1483+
let decorators =
1484+
if isTopLevel then CompletionDecorators.toplevel
1485+
else CompletionDecorators.local
1486+
in
1487+
decorators
1488+
|> List.filter (fun (decorator, _) -> Utils.startsWith decorator prefix)
15091489
|> List.map mkDecorator
15101490
| CnamedArg (cp, prefix, identsSeen) ->
15111491
let labels =

analysis/src/CompletionDecorators.ml

+45-39
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
1-
type kind = TopLevel of string | Local of string | TopLevelOrLocal of string
2-
3-
let decorators =
1+
let local =
42
[
5-
( Local "as",
3+
( "as",
64
[
75
{|The `@as` decorator is commonly used on record types to alias record field names to a different JavaScript attribute name.
86

@@ -12,7 +10,7 @@ It is also possible to map a ReScript record to a JavaScript array by passing in
1210

1311
[Read more and see examples in the documentation](https://rescript-lang.org/syntax-lookup#as-decorator).|};
1412
] );
15-
( Local "dead",
13+
( "dead",
1614
[
1715
{|The `@dead` decorator is for reanalyze, a static analysis tool for ReScript that can do dead code analysis.
1816

@@ -22,21 +20,19 @@ It is also possible to map a ReScript record to a JavaScript array by passing in
2220

2321
> Hint: Did you know you can run an interactive code analysis in your project by running the command `> ReScript: Start Code Analyzer`? Try it!|};
2422
] );
25-
( Local "deriving",
23+
( "deriving",
2624
[
2725
{|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.
2826

2927
[Read more and see examples in the documentation](https://rescript-lang.org/syntax-lookup#deriving-decorator).|};
3028
] );
31-
( TopLevelOrLocal "deprecated",
29+
( "deprecated",
3230
[
3331
{|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.
3432

35-
Alternatively, use the `@@deprecated` decorator to add a deprecation warning to the file level.
36-
3733
[Read more and see examples in the documentation](https://rescript-lang.org/syntax-lookup#expression-deprecated-decorator).|};
3834
] );
39-
( Local "doesNotRaise",
35+
( "doesNotRaise",
4036
[
4137
{|The `@doesNotRaise` decorator is for reanalyze, a static analysis tool for ReScript that can perform exception analysis.
4238

@@ -47,55 +43,55 @@ could potentially raise.
4743
[Read more and see examples in the documentation](https://github.com/rescript-association/reanalyze/blob/master/EXCEPTION.md).
4844
> Hint: Did you know you can run an interactive code analysis in your project by running the command `> ReScript: Start Code Analyzer`? Try it!|};
4945
] );
50-
( Local "genType",
46+
( "genType",
5147
[
5248
{|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.
5349

5450
[Read more and see examples in the documentation](https://rescript-lang.org/syntax-lookup#gentype-decorator).|};
5551
] );
56-
( Local "genType.as",
52+
( "genType.as",
5753
[
5854
{|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.
5955

6056
[Read more and see examples in the documentation](https://rescript-lang.org/docs/gentype/latest/usage).|};
6157
] );
62-
( Local "genType.import",
58+
( "genType.import",
6359
[
6460
{|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.
6561

6662
[Read more and see examples in the documentation](https://rescript-lang.org/docs/gentype/latest/usage).|};
6763
] );
68-
( Local "genType.opaque",
64+
( "genType.opaque",
6965
[
7066
{|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.
7167

7268
[Read more and see examples in the documentation](https://rescript-lang.org/docs/gentype/latest/usage).|};
7369
] );
74-
( Local "get",
70+
( "get",
7571
[
7672
{|The `@get` decorator is used to bind to a property of an object.
7773

7874
[Read more and see examples in the documentation](https://rescript-lang.org/syntax-lookup#get-decorator).|};
7975
] );
80-
( Local "get_index",
76+
( "get_index",
8177
[
8278
{|The `@get_index` decorator is used to access a dynamic property on an object, or an index of an array.
8379

8480
[Read more and see examples in the documentation](https://rescript-lang.org/syntax-lookup#get-index-decorator).|};
8581
] );
86-
( Local "inline",
82+
( "inline",
8783
[
8884
{|The `@inline` decorator tells the compiler to inline its value in every place the binding is being used, rather than use a variable.
8985

9086
[Read more and see examples in the documentation](https://rescript-lang.org/syntax-lookup#inline-decorator).|};
9187
] );
92-
( Local "int",
88+
( "int",
9389
[
9490
{|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.
9591

9692
[Read more and see examples in the documentation](https://rescript-lang.org/syntax-lookup#int-decorator).|};
9793
] );
98-
( Local "live",
94+
( "live",
9995
[
10096
{|The `@live` decorator is for reanalyze, a static analysis tool for ReScript that can do dead code analysis.
10197

@@ -105,32 +101,32 @@ could potentially raise.
105101

106102
Hint: Did you know you can run an interactive code analysis in your project by running the command `> ReScript: Start Code Analyzer`? Try it!|};
107103
] );
108-
( Local "meth",
104+
( "meth",
109105
[
110106
{|The `@meth` decorator is used to call a function on a JavaScript object, and avoid issues with currying.
111107

112108
[Read more and see examples in the documentation](https://rescript-lang.org/syntax-lookup#meth-decorator).|};
113109
] );
114-
( Local "module",
110+
( "module",
115111
[
116112
{|The `@module` decorator is used to bind to a JavaScript module.
117113

118114
[Read more and see examples in the documentation](https://rescript-lang.org/syntax-lookup#module-decorator).|};
119115
] );
120-
( Local "new",
116+
( "new",
121117
[
122118
{|
123119
The `@new` decorator is used whenever you need to bind to a JavaScript class constructor that requires the new keword for instantiation.|
124120

125121
[Read more and see examples in the documentation](https://rescript-lang.org/syntax-lookup#new-decorator).|};
126122
] );
127-
( Local "obj",
123+
( "obj",
128124
[
129125
{|The `@obj` decorator is used to create functions that return JavaScript objects with properties that match the function's parameter labels.
130126

131127
[Read more and see examples in the documentation](https://rescript-lang.org/syntax-lookup#obj-decorator).|};
132128
] );
133-
( Local "raises",
129+
( "raises",
134130
[
135131
{|The `@raises` decorator is for reanalyze, a static analysis tool for ReScript that can perform exception analysis.
136132

@@ -140,7 +136,7 @@ Example `@raises(Exn)` or `@raises([E1, E2, E3])` for multiple exceptions.
140136
[Read more and see examples in the documentation](https://github.com/rescript-association/reanalyze/blob/master/EXCEPTION.md).
141137
> Hint: Did you know you can run an interactive code analysis in your project by running the command `> ReScript: Start Code Analyzer`? Try it!|};
142138
] );
143-
( Local "react.component",
139+
( "react.component",
144140
[
145141
{|The `@react.component` decorator is used to annotate functions that are RescriptReact components.
146142

@@ -150,85 +146,95 @@ Note: The `@react.component` decorator requires the react-jsx config to be set i
150146

151147
[Read more and see examples in the documentation](https://rescript-lang.org/syntax-lookup#react-component-decorator).|};
152148
] );
153-
( Local "return",
149+
( "return",
154150
[
155151
{|The `@return` decorator is used to control how `null` and `undefined` values are converted to option types in ReScript.
156152

157153
[Read more and see examples in the documentation](https://rescript-lang.org/syntax-lookup#return-decorator).|};
158154
] );
159-
( Local "scope",
155+
( "scope",
160156
[
161157
{|The `@scope` decorator is used with other decorators such as `@val` and `@module` to declare a parent scope for the binding.
162158

163159
[Read more and see examples in the documentation](https://rescript-lang.org/syntax-lookup#scope-decorator).|};
164160
] );
165-
( Local "send",
161+
( "send",
166162
[
167163
{|The `@send` decorator is used to bind to a method on an object or array.
168164

169165
[Read more and see examples in the documentation](https://rescript-lang.org/syntax-lookup#send-decorator).|};
170166
] );
171-
( Local "set",
167+
( "set",
172168
[
173169
{|The `@set` decorator is used to set a property of an object.
174170

175171
[Read more and see examples in the documentation](https://rescript-lang.org/syntax-lookup#set-decorator).|};
176172
] );
177-
( Local "set_index",
173+
( "set_index",
178174
[
179175
{|The `@set_index` decorator is used to set a dynamic property on an object, or an index of an array.
180176

181177
[Read more and see examples in the documentation](https://rescript-lang.org/syntax-lookup#set-index-decorator).|};
182178
] );
183-
( Local "string",
179+
( "string",
184180
[
185181
{|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.
186182

187183
[Read more and see examples in the documentation](https://rescript-lang.org/syntax-lookup#string-decorator).|};
188184
] );
189-
( Local "this",
185+
( "this",
190186
[
191187
{|The `@this` decorator may be used to bind to an external callback function that require access to a this context.
192188

193189
[Read more and see examples in the documentation](https://rescript-lang.org/syntax-lookup#this-decorator).|};
194190
] );
195-
( Local "unboxed",
191+
( "unboxed",
196192
[
197193
{|The `@unboxed` decorator provides a way to unwrap variant constructors that have a single argument, or record objects that have a single field.
198194

199195
[Read more and see examples in the documentation](https://rescript-lang.org/syntax-lookup#unboxed-decorator).|};
200196
] );
201-
( Local "uncurry",
197+
( "uncurry",
202198
[
203199
{|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 (`(.) => { ... }`).
204200

205201
[Read more and see examples in the documentation](https://rescript-lang.org/syntax-lookup#uncurry-decorator).|};
206202
] );
207-
( Local "unwrap",
203+
( "unwrap",
208204
[
209205
{|The `@unwrap` decorator may be used when binding to external functions that accept multiple types for an argument.
210206

211207
[Read more and see examples in the documentation](https://rescript-lang.org/syntax-lookup#unwrap-decorator).|};
212208
] );
213-
( Local "val",
209+
( "val",
214210
[
215211
{|The `@val` decorator allows you to bind to JavaScript values that are on the global scope.
216212

217213
[Read more and see examples in the documentation](https://rescript-lang.org/syntax-lookup#val-decorator).|};
218214
] );
219-
( Local "variadic",
215+
( "variadic",
220216
[
221217
{|The `@variadic` decorator is used to model JavaScript functions that take a variable number of arguments, where all arguments are of the same type.
222218

223219
[Read more and see examples in the documentation](https://rescript-lang.org/syntax-lookup#variadic-decorator).|};
224220
] );
225-
( TopLevel "directive",
221+
]
222+
223+
let toplevel =
224+
[
225+
( "deprecated",
226+
[
227+
{|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.
228+
229+
[Read more and see examples in the documentation](https://rescript-lang.org/syntax-lookup#module-deprecated-decorator).|};
230+
] );
231+
( "directive",
226232
[
227233
{|The `@@directive` decorator will output that string verbatim at the very top of the generated JavaScript file, before any imports.
228234

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

analysis/tests/src/expected/Completion.res.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -564,7 +564,7 @@ Completable: Cdecorator(react.)
564564
Package opens Pervasives.JsxModules.place holder
565565
Resolved opens 1 pervasives
566566
[{
567-
"label": "component",
567+
"label": "react.component",
568568
"kind": 4,
569569
"tags": [],
570570
"detail": "",

0 commit comments

Comments
 (0)