Skip to content

Commit 70a6aa7

Browse files
committed
Merge branch 'master' into move-tools-to-ocaml
2 parents b60b56d + fde49b6 commit 70a6aa7

27 files changed

+740
-65
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ jobs:
4949
key: ${{matrix.os}}-rescript-vscode-v4
5050

5151
- name: Use OCaml
52-
uses: ocaml/setup-ocaml@v2
52+
uses: ocaml/setup-ocaml@v2.1.7
5353
with:
5454
ocaml-compiler: 4.14.x
5555

CHANGELOG.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,24 @@
1212
1313
## master
1414

15+
#### :bug: Bug Fix
16+
17+
- Treat `result` type as a proper built in type. https://github.com/rescript-lang/rescript-vscode/pull/860
18+
19+
#### :nail_care: Polish
20+
21+
- Change end position of cursor when completing `Some(<fieldName>)` in patterns. https://github.com/rescript-lang/rescript-vscode/pull/857
22+
23+
#### :bug: Bug Fix
24+
25+
- Add support for detecting dead fields inside inline records. https://github.com/rescript-lang/rescript-vscode/pull/858
26+
27+
## 1.28.0
28+
29+
#### :bug: Bug Fix
30+
31+
- Fix issue introduced in recent PR for module completion. https://github.com/rescript-lang/rescript-vscode/pull/856
32+
1533
## 1.26.0
1634

1735
#### :bug: Bug Fix

analysis/bin/main.ml

Lines changed: 36 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -87,48 +87,71 @@ Options:
8787
|}
8888

8989
let main () =
90-
match Array.to_list Sys.argv with
90+
let args = Array.to_list Sys.argv in
91+
let debugLevel, args =
92+
match args with
93+
| _ :: "debug-dump" :: logLevel :: rest ->
94+
( (match logLevel with
95+
| "verbose" -> Debug.Verbose
96+
| "regular" -> Regular
97+
| _ -> Off),
98+
"dummy" :: rest )
99+
| args -> (Off, args)
100+
in
101+
Debug.debugLevel := debugLevel;
102+
let debug = debugLevel <> Debug.Off in
103+
let printHeaderInfo path line col =
104+
if debug then
105+
Printf.printf "Debug level: %s\n%s:%s-%s\n\n"
106+
(match debugLevel with
107+
| Debug.Verbose -> "verbose"
108+
| Regular -> "regular"
109+
| Off -> "off")
110+
path line col
111+
in
112+
match args with
91113
| [_; "completion"; path; line; col; currentFile; supportsSnippets] ->
114+
printHeaderInfo path line col;
92115
(Cfg.supportsSnippets :=
93116
match supportsSnippets with
94117
| "true" -> true
95118
| _ -> false);
96-
Commands.completion ~debug:false ~path
119+
Commands.completion ~debug ~path
97120
~pos:(int_of_string line, int_of_string col)
98121
~currentFile
99122
| [_; "definition"; path; line; col] ->
100123
Commands.definition ~path
101124
~pos:(int_of_string line, int_of_string col)
102-
~debug:false
125+
~debug
103126
| [_; "typeDefinition"; path; line; col] ->
104127
Commands.typeDefinition ~path
105128
~pos:(int_of_string line, int_of_string col)
106-
~debug:false
129+
~debug
107130
| [_; "documentSymbol"; path] -> DocumentSymbol.command ~path
108131
| [_; "hover"; path; line; col; currentFile; supportsMarkdownLinks] ->
109132
Commands.hover ~path
110133
~pos:(int_of_string line, int_of_string col)
111-
~currentFile ~debug:false
134+
~currentFile ~debug
112135
~supportsMarkdownLinks:
113136
(match supportsMarkdownLinks with
114137
| "true" -> true
115138
| _ -> false)
116139
| [_; "signatureHelp"; path; line; col; currentFile] ->
117140
Commands.signatureHelp ~path
118141
~pos:(int_of_string line, int_of_string col)
119-
~currentFile ~debug:false
142+
~currentFile ~debug
120143
| [_; "inlayHint"; path; line_start; line_end; maxLength] ->
121144
Commands.inlayhint ~path
122145
~pos:(int_of_string line_start, int_of_string line_end)
123-
~maxLength ~debug:false
124-
| [_; "codeLens"; path] -> Commands.codeLens ~path ~debug:false
125-
| [_; "extractDocs"; path] -> DocExtraction.extractDocs ~path ~debug:false
146+
~maxLength ~debug
147+
| [_; "codeLens"; path] -> Commands.codeLens ~path ~debug
148+
| [_; "extractDocs"; path] -> DocExtraction.extractDocs ~path ~debug
126149
| [_; "codeAction"; path; startLine; startCol; endLine; endCol; currentFile]
127150
->
128151
Commands.codeAction ~path
129152
~startPos:(int_of_string startLine, int_of_string startCol)
130153
~endPos:(int_of_string endLine, int_of_string endCol)
131-
~currentFile ~debug:false
154+
~currentFile ~debug
132155
| [_; "codemod"; path; line; col; typ; hint] ->
133156
let typ =
134157
match typ with
@@ -138,7 +161,7 @@ let main () =
138161
let res =
139162
Codemod.transform ~path
140163
~pos:(int_of_string line, int_of_string col)
141-
~debug:false ~typ ~hint
164+
~debug ~typ ~hint
142165
|> Json.escape
143166
in
144167
Printf.printf "\"%s\"" res
@@ -153,11 +176,11 @@ let main () =
153176
| [_; "references"; path; line; col] ->
154177
Commands.references ~path
155178
~pos:(int_of_string line, int_of_string col)
156-
~debug:false
179+
~debug
157180
| [_; "rename"; path; line; col; newName] ->
158181
Commands.rename ~path
159182
~pos:(int_of_string line, int_of_string col)
160-
~newName ~debug:false
183+
~newName ~debug
161184
| [_; "semanticTokens"; currentFile] ->
162185
SemanticTokens.semanticTokens ~currentFile
163186
| [_; "createInterface"; path; cmiFile] ->

analysis/reanalyze/examples/deadcode/expected/deadcode.txt

Lines changed: 75 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,9 @@
8787
addValueDeclaration +version DeadMl.ml:29:8 path:+DeadMl.Bs_version
8888
addValueDeclaration +header DeadMl.ml:30:8 path:+DeadMl.Bs_version
8989
addValueDeclaration +package_name DeadMl.ml:31:8 path:+DeadMl.Bs_version
90+
addRecordLabelDeclaration Lfunction.arity DeadMl.ml:35:21 path:+DeadMl.l
91+
addRecordLabelDeclaration Lfunction.params DeadMl.ml:36:21 path:+DeadMl.l
92+
addRecordLabelDeclaration Lfunction.body DeadMl.ml:37:21 path:+DeadMl.l
9093
addVariantCaseDeclaration Lfunction DeadMl.ml:35:2 path:+DeadMl.l
9194
addRecordLabelDeclaration module_name DeadMl.ml:41:2 path:+DeadMl.module_info
9295
addRecordLabelDeclaration case DeadMl.ml:42:2 path:+DeadMl.module_info
@@ -172,6 +175,7 @@
172175
addValueDeclaration +globallyLive3 DeadTest.res:154:6 path:+DeadTest.GloobLive
173176
addValueDeclaration +funWithInnerVars DeadTest.res:169:4 path:+DeadTest
174177
addValueDeclaration +deadIncorrect DeadTest.res:178:4 path:+DeadTest
178+
addValueDeclaration +ira DeadTest.res:184:4 path:+DeadTest
175179
addValueReference DeadTest.res:1:15 --> ImmutableArray.resi:9:0
176180
addValueReference DeadTest.res:8:7 --> DeadTest.res:7:4
177181
addValueReference DeadTest.res:11:7 --> DeadTest.res:10:4
@@ -249,6 +253,26 @@
249253
addRecordLabelDeclaration a DeadTest.res:175:11 path:+DeadTest.rc
250254
addValueDeclaration +_ DeadTest.res:180:0 path:+DeadTest
251255
addValueReference DeadTest.res:180:8 --> DeadTest.res:178:4
256+
addRecordLabelDeclaration IR.a DeadTest.res:182:24 path:+DeadTest.inlineRecord
257+
addRecordLabelDeclaration IR.b DeadTest.res:182:32 path:+DeadTest.inlineRecord
258+
addRecordLabelDeclaration IR.c DeadTest.res:182:40 path:+DeadTest.inlineRecord
259+
addRecordLabelDeclaration IR.d DeadTest.res:182:51 path:+DeadTest.inlineRecord
260+
addRecordLabelDeclaration IR.e DeadTest.res:182:65 path:+DeadTest.inlineRecord
261+
addVariantCaseDeclaration IR DeadTest.res:182:20 path:+DeadTest.inlineRecord
262+
addValueDeclaration +_ DeadTest.res:185:0 path:+DeadTest
263+
addTypeReference DeadTest.res:187:20 --> DeadTest.res:182:20
264+
addValueReference DeadTest.res:187:27 --> DeadTest.res:184:4
265+
addTypeReference DeadTest.res:187:35 --> DeadTest.res:182:32
266+
addValueReference DeadTest.res:187:35 --> DeadTest.res:187:7
267+
addValueReference DeadTest.res:187:40 --> DeadTest.res:187:8
268+
addTypeReference DeadTest.res:187:7 --> DeadTest.res:182:40
269+
addValueReference DeadTest.res:186:9 --> DeadTest.res:185:8
270+
addRecordLabelDeclaration IR2.a DeadTest.res:191:26 path:+DeadTest.inlineRecord2
271+
addRecordLabelDeclaration IR2.b DeadTest.res:191:34 path:+DeadTest.inlineRecord2
272+
addVariantCaseDeclaration IR2 DeadTest.res:191:21 path:+DeadTest.inlineRecord2
273+
addRecordLabelDeclaration IR3.a DeadTest.res:193:34 path:+DeadTest.inlineRecord3
274+
addRecordLabelDeclaration IR3.b DeadTest.res:193:42 path:+DeadTest.inlineRecord3
275+
addVariantCaseDeclaration IR3 DeadTest.res:193:21 path:+DeadTest.inlineRecord3
252276
addValueReference DeadTest.res:28:2 --> DeadTest.res:31:6
253277
addValueReference DeadTest.res:36:2 --> DeadTest.res:39:6
254278
addValueReference DeadTest.res:60:2 --> DeadTest.res:64:6
@@ -1665,6 +1689,7 @@
16651689
addVariantCaseDeclaration A Unboxed.res:5:10 path:+Unboxed.v2
16661690
addValueReference Unboxed.res:8:4 --> Unboxed.res:8:14
16671691
addRecordLabelDeclaration x Unboxed.res:11:11 path:+Unboxed.r1
1692+
addRecordLabelDeclaration B.g Unboxed.res:14:13 path:+Unboxed.r2
16681693
addVariantCaseDeclaration B Unboxed.res:14:10 path:+Unboxed.r2
16691694
addValueReference Unboxed.res:17:4 --> Unboxed.res:17:14
16701695
Scanning Uncurried.cmt Source:Uncurried.res
@@ -1984,6 +2009,9 @@ File References
19842009
Dead Value +DeadMl.+map_split_opt: 0 references () [0]
19852010
Dead RecordLabel +DeadMl.module_info.case: 0 references () [0]
19862011
Dead RecordLabel +DeadMl.module_info.module_name: 0 references () [0]
2012+
Dead RecordLabel +DeadMl.l.Lfunction.body: 0 references () [0]
2013+
Dead RecordLabel +DeadMl.l.Lfunction.params: 0 references () [0]
2014+
Dead RecordLabel +DeadMl.l.Lfunction.arity: 0 references () [0]
19872015
Dead VariantCase +DeadMl.l.Lfunction: 0 references () [0]
19882016
Dead Value +DeadMl.Bs_version.+package_name: 0 references () [1]
19892017
Dead Value +DeadMl.Bs_version.+package_name: 0 references () [0]
@@ -2004,6 +2032,20 @@ File References
20042032
Live VariantCase DeadRT.moduleAccessPath.Root: 1 references (DeadTest.res:106:16) [1]
20052033
Live VariantCase +DeadRT.moduleAccessPath.Root: 1 references (DeadRT.resi:2:2) [0]
20062034
Live VariantCase DeadRT.moduleAccessPath.Kaboom: 1 references (DeadRT.res:3:2) [0]
2035+
Dead RecordLabel +DeadTest.inlineRecord3.IR3.b: 0 references () [0]
2036+
Dead RecordLabel +DeadTest.inlineRecord3.IR3.a: 0 references () [0]
2037+
Dead VariantCase +DeadTest.inlineRecord3.IR3: 0 references () [0]
2038+
Dead RecordLabel +DeadTest.inlineRecord2.IR2.b: 0 references () [0]
2039+
Dead RecordLabel +DeadTest.inlineRecord2.IR2.a: 0 references () [0]
2040+
Dead VariantCase +DeadTest.inlineRecord2.IR2: 0 references () [0]
2041+
Dead Value +DeadTest.+_: 0 references () [0]
2042+
Live Value +DeadTest.+ira: 1 references (DeadTest.res:187:27) [0]
2043+
Live RecordLabel +DeadTest.inlineRecord.IR.e: 0 references () [0]
2044+
Dead RecordLabel +DeadTest.inlineRecord.IR.d: 0 references () [0]
2045+
Live RecordLabel +DeadTest.inlineRecord.IR.c: 1 references (DeadTest.res:187:7) [0]
2046+
Live RecordLabel +DeadTest.inlineRecord.IR.b: 1 references (DeadTest.res:187:35) [0]
2047+
Dead RecordLabel +DeadTest.inlineRecord.IR.a: 0 references () [0]
2048+
Live VariantCase +DeadTest.inlineRecord.IR: 1 references (DeadTest.res:187:20) [0]
20072049
Dead Value +DeadTest.+_: 0 references () [0]
20082050
Live Value +DeadTest.+deadIncorrect: 1 references (DeadTest.res:180:8) [0]
20092051
Dead RecordLabel +DeadTest.rc.a: 0 references () [0]
@@ -2350,6 +2392,7 @@ File References
23502392
Live Value +Types.+map: 0 references () [0]
23512393
Live Value +Types.+someIntList: 0 references () [0]
23522394
Live Value +Unboxed.+r2Test: 0 references () [0]
2395+
Dead RecordLabel +Unboxed.r2.B.g: 0 references () [0]
23532396
Dead VariantCase +Unboxed.r2.B: 0 references () [0]
23542397
Dead RecordLabel +Unboxed.r1.x: 0 references () [0]
23552398
Live Value +Unboxed.+testV1: 0 references () [0]
@@ -2838,6 +2881,24 @@ File References
28382881
<-- line 35
28392882
} [@dead "l.Lfunction"]
28402883

2884+
Warning Dead Type
2885+
DeadMl.ml:35:22-34
2886+
l.Lfunction.arity is a record label never used to read a value
2887+
<-- line 35
2888+
| Lfunction of { arity : int ; [@dead "l.Lfunction.arity"]
2889+
2890+
Warning Dead Type
2891+
DeadMl.ml:36:22-40
2892+
l.Lfunction.params is a record label never used to read a value
2893+
<-- line 36
2894+
params : int list ; [@dead "l.Lfunction.params"]
2895+
2896+
Warning Dead Type
2897+
DeadMl.ml:37:22-34
2898+
l.Lfunction.body is a record label never used to read a value
2899+
<-- line 37
2900+
body : string [@dead "l.Lfunction.body"]
2901+
28412902
Warning Dead Type
28422903
DeadMl.ml:41:3-22
28432904
module_info.module_name is a record label never used to read a value
@@ -3064,6 +3125,12 @@ File References
30643125
<-- line 175
30653126
type rc = {@dead("rc.a") a: int}
30663127

3128+
Warning Dead Type
3129+
DeadTest.res:182:25-30
3130+
inlineRecord.IR.a is a record label never used to read a value
3131+
<-- line 182
3132+
type inlineRecord = IR({@dead("inlineRecord.IR.a") a: int, b: int, c: string, @dead d: int, @live e: int})
3133+
30673134
Warning Dead Module
30683135
DeadTestBlacklist.res:0:1
30693136
DeadTestBlacklist is a dead module as all its items are dead.
@@ -4448,7 +4515,13 @@ File References
44484515
Unboxed.res:14:11-24
44494516
r2.B is a variant case which is never constructed
44504517
<-- line 14
4451-
type r2 = | @dead("r2.B") B({g: string})
4518+
type r2 = | @dead("r2.B") B({@dead("r2.B.g") g: string})
4519+
4520+
Warning Dead Type
4521+
Unboxed.res:14:14-22
4522+
r2.B.g is a record label never used to read a value
4523+
<-- line 14
4524+
type r2 = | @dead("r2.B") B({@dead("r2.B.g") g: string})
44524525

44534526
Warning Dead Type
44544527
Variants.res:95:14-39
@@ -4528,4 +4601,4 @@ File References
45284601
<-- line 96
45294602
type variant1Object = | @dead("variant1Object.R") R(payload)
45304603

4531-
Analysis reported 334 issues (Incorrect Dead Annotation:1, Warning Dead Exception:2, Warning Dead Module:25, Warning Dead Type:89, Warning Dead Value:199, Warning Dead Value With Side Effects:2, Warning Redundant Optional Argument:5, Warning Unused Argument:11)
4604+
Analysis reported 339 issues (Incorrect Dead Annotation:1, Warning Dead Exception:2, Warning Dead Module:25, Warning Dead Type:94, Warning Dead Value:199, Warning Dead Value With Side Effects:2, Warning Redundant Optional Argument:5, Warning Unused Argument:11)

analysis/reanalyze/examples/deadcode/src/DeadTest.bs.js

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

analysis/reanalyze/examples/deadcode/src/DeadTest.res

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,3 +178,16 @@ type rc = {a: int}
178178
let deadIncorrect = 34
179179

180180
let _ = deadIncorrect
181+
182+
type inlineRecord = IR({a: int, b: int, c: string, @dead d: int, @live e: int})
183+
184+
let ira = 10
185+
let _ = ir =>
186+
switch ir {
187+
| IR({c} as r) => IR({a: ira, b: r.b, c, d: 0, e: 0})
188+
}
189+
190+
@dead
191+
type inlineRecord2 = IR2({a: int, b: int})
192+
193+
type inlineRecord3 = | @dead IR3({a: int, b: int})

analysis/reanalyze/src/DeadCommon.ml

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -266,8 +266,22 @@ module ProcessDeadAnnotations = struct
266266
| Ttype_variant constructorDeclarations ->
267267
constructorDeclarations
268268
|> List.iter
269-
(fun ({cd_attributes; cd_loc} : Typedtree.constructor_declaration)
269+
(fun
270+
({cd_attributes; cd_loc; cd_args} :
271+
Typedtree.constructor_declaration)
270272
->
273+
let _process_inline_records =
274+
match cd_args with
275+
| Cstr_record flds ->
276+
List.iter
277+
(fun ({ld_attributes; ld_loc} :
278+
Typedtree.label_declaration) ->
279+
toplevelAttrs @ cd_attributes @ ld_attributes
280+
|> processAttributes ~doGenType:false ~name:""
281+
~pos:ld_loc.loc_start)
282+
flds
283+
| Cstr_tuple _ -> ()
284+
in
271285
toplevelAttrs @ cd_attributes
272286
|> processAttributes ~doGenType:false ~name:""
273287
~pos:cd_loc.loc_start)

analysis/reanalyze/src/DeadType.ml

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,18 @@ let addDeclaration ~(typeId : Ident.t) ~(typeKind : Types.type_kind) =
102102
l
103103
| Type_variant decls ->
104104
List.iteri
105-
(fun i {Types.cd_id; cd_loc} ->
105+
(fun i {Types.cd_id; cd_loc; cd_args} ->
106+
let _handle_inline_records =
107+
match cd_args with
108+
| Cstr_record lbls ->
109+
List.iter
110+
(fun {Types.ld_id; ld_loc} ->
111+
Ident.name cd_id ^ "." ^ Ident.name ld_id
112+
|> Name.create
113+
|> processTypeLabel ~declKind:RecordLabel ~loc:ld_loc)
114+
lbls
115+
| Cstr_tuple _ -> ()
116+
in
106117
let posAdjustment =
107118
(* In Res the variant loc can include the | and spaces after it *)
108119
if WriteDeadAnnotations.posLanguage cd_loc.loc_start = Res then

0 commit comments

Comments
 (0)