Skip to content

Commit 734a2a4

Browse files
committed
propagate deprecated attribute for record fields
1 parent ded3acf commit 734a2a4

File tree

5 files changed

+53
-5
lines changed

5 files changed

+53
-5
lines changed

Diff for: analysis/src/CompletionBackEnd.ml

+5-3
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ let completionForExportedFields ~(env : QueryEnv.t) ~prefix ~exact ~namesUsed =
130130
let () = Hashtbl.add namesUsed name () in
131131
Some
132132
(Completion.create name ~env ~docstring:f.docstring
133+
?deprecated:f.deprecated
133134
~kind:
134135
(Completion.Field
135136
(f, t.item.decl |> Shared.declToString t.name.txt)))
@@ -740,7 +741,7 @@ let rec getCompletionsForContextPath ~full ~opens ~rawOpens ~allFiles ~pos ~env
740741
if Utils.checkName field.fname.txt ~prefix:fieldName ~exact then
741742
Some
742743
(Completion.create field.fname.txt ~env
743-
~docstring:field.docstring
744+
~docstring:field.docstring ?deprecated:field.deprecated
744745
~kind:
745746
(Completion.Field
746747
( field,
@@ -1151,6 +1152,7 @@ let rec completeTypedValue ~full ~prefix ~completionContext ~mode
11511152
match (field.optional, mode) with
11521153
| true, Pattern Destructuring ->
11531154
Completion.create ("?" ^ field.fname.txt)
1155+
?deprecated:field.deprecated
11541156
~docstring:
11551157
[
11561158
field.fname.txt
@@ -1161,7 +1163,7 @@ let rec completeTypedValue ~full ~prefix ~completionContext ~mode
11611163
(Field (field, TypeUtils.extractedTypeToString extractedType))
11621164
~env
11631165
| _ ->
1164-
Completion.create field.fname.txt
1166+
Completion.create field.fname.txt ?deprecated:field.deprecated
11651167
~kind:
11661168
(Field (field, TypeUtils.extractedTypeToString extractedType))
11671169
~env)
@@ -1189,7 +1191,7 @@ let rec completeTypedValue ~full ~prefix ~completionContext ~mode
11891191
List.mem field.fname.txt seenFields = false)
11901192
|> List.map (fun (field : field) ->
11911193
Completion.create field.fname.txt ~kind:(Label "Inline record")
1192-
~env)
1194+
?deprecated:field.deprecated ~env)
11931195
|> filterItems ~prefix
11941196
| None ->
11951197
if prefix = "" then

Diff for: analysis/src/ProcessCmt.ml

+8
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ let mapRecordField {Types.ld_id; ld_type; ld_attributes} =
2727
(match ProcessAttributes.findDocAttribute ld_attributes with
2828
| None -> []
2929
| Some docstring -> [docstring]);
30+
deprecated = ProcessAttributes.findDeprecatedAttribute ld_attributes;
3031
}
3132

3233
let rec forTypeSignatureItem ~(env : SharedTypes.Env.t) ~(exported : Exported.t)
@@ -231,6 +232,10 @@ let forTypeDeclaration ~env ~(exported : Exported.t)
231232
with
232233
| None -> []
233234
| Some docstring -> [docstring]);
235+
deprecated =
236+
ProcessAttributes
237+
.findDeprecatedAttribute
238+
f.ld_attributes;
234239
})));
235240
res =
236241
(match cd_res with
@@ -268,6 +273,9 @@ let forTypeDeclaration ~env ~(exported : Exported.t)
268273
Res_parsetree_viewer.hasOptionalAttribute
269274
ld_attributes;
270275
docstring = attrsToDocstring ld_attributes;
276+
deprecated =
277+
ProcessAttributes.findDeprecatedAttribute
278+
ld_attributes;
271279
})));
272280
}
273281
~name ~stamp ~env typ_attributes

Diff for: analysis/src/SharedTypes.ml

+1
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ type field = {
3232
typ: Types.type_expr;
3333
optional: bool;
3434
docstring: string list;
35+
deprecated: string option;
3536
}
3637

3738
type constructorArgs =

Diff for: analysis/tests/src/Completion.res

+17
Original file line numberDiff line numberDiff line change
@@ -425,3 +425,20 @@ let ok = Ok(true)
425425

426426
// ok->g
427427
// ^com
428+
429+
type someRecordWithDeprecatedField = {
430+
name: string,
431+
@deprecated
432+
someInt: int,
433+
@deprecated("Use 'someInt'.")
434+
someFloat: float,
435+
}
436+
437+
let rWithDepr: someRecordWithDeprecatedField = {
438+
name: "hej",
439+
someInt: 12,
440+
someFloat: 12.,
441+
}
442+
443+
// rWithDepr.so
444+
// ^com

Diff for: analysis/tests/src/expected/Completion.res.txt

+22-2
Original file line numberDiff line numberDiff line change
@@ -1625,8 +1625,8 @@ Resolved opens 2 Completion.res Completion.res
16251625
}]
16261626

16271627
Complete src/Completion.res 405:22
1628-
posCursor:[405:22] posNoWhite:[405:21] Found expr:[405:11->428:0]
1629-
Pexp_apply ...__ghost__[0:-1->0:-1] (...[405:11->423:17], ...[428:0->428:0])
1628+
posCursor:[405:22] posNoWhite:[405:21] Found expr:[405:11->445:0]
1629+
Pexp_apply ...__ghost__[0:-1->0:-1] (...[405:11->423:17], ...[428:0->445:0])
16301630
posCursor:[405:22] posNoWhite:[405:21] Found expr:[405:11->423:17]
16311631
Pexp_apply ...__ghost__[0:-1->0:-1] (...[405:11->405:19], ...[405:21->423:17])
16321632
posCursor:[405:22] posNoWhite:[405:21] Found expr:[405:21->423:17]
@@ -1759,3 +1759,23 @@ Resolved opens 2 Completion.res Completion.res
17591759
"documentation": {"kind": "markdown", "value": "\n `getWithDefault(res, defaultValue)`: If `res` is `Ok(n)`, returns `n`,\n otherwise `default`\n\n ```res example\n Belt.Result.getWithDefault(Ok(42), 0) == 42\n\n Belt.Result.getWithDefault(Error(\"Invalid Data\"), 0) == 0\n ```\n"}
17601760
}]
17611761

1762+
Complete src/Completion.res 442:15
1763+
posCursor:[442:15] posNoWhite:[442:14] Found expr:[442:3->442:15]
1764+
Pexp_field [442:3->442:12] so:[442:13->442:15]
1765+
Completable: Cpath Value[rWithDepr].so
1766+
Raw opens: 2 Shadow.B.place holder ... Shadow.A.place holder
1767+
Resolved opens 2 Completion.res Completion.res
1768+
[{
1769+
"label": "someInt",
1770+
"kind": 5,
1771+
"tags": [1],
1772+
"detail": "someInt: int\n\ntype someRecordWithDeprecatedField = {\n name: string,\n someInt: int,\n someFloat: float,\n}",
1773+
"documentation": {"kind": "markdown", "value": "Deprecated: \n\n"}
1774+
}, {
1775+
"label": "someFloat",
1776+
"kind": 5,
1777+
"tags": [1],
1778+
"detail": "someFloat: float\n\ntype someRecordWithDeprecatedField = {\n name: string,\n someInt: int,\n someFloat: float,\n}",
1779+
"documentation": {"kind": "markdown", "value": "Deprecated: Use 'someInt'.\n\n"}
1780+
}]
1781+

0 commit comments

Comments
 (0)