Skip to content

Commit 76ca546

Browse files
committed
propagate deprecated for constructors
1 parent 734a2a4 commit 76ca546

File tree

5 files changed

+56
-9
lines changed

5 files changed

+56
-9
lines changed

Diff for: analysis/src/CompletionBackEnd.ml

+2-1
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ let completionsForExportedConstructors ~(env : QueryEnv.t) ~prefix ~exact
108108
let () = Hashtbl.add namesUsed name () in
109109
Some
110110
(Completion.create name ~env ~docstring:c.docstring
111+
?deprecated:c.deprecated
111112
~kind:
112113
(Completion.Constructor
113114
(c, t.item.decl |> Shared.declToString t.name.txt)))
@@ -1073,7 +1074,7 @@ let rec completeTypedValue ~full ~prefix ~completionContext ~mode
10731074
| InlineRecord _ -> 1
10741075
| Args args -> List.length args
10751076
in
1076-
Completion.createWithSnippet
1077+
Completion.createWithSnippet ?deprecated:constructor.deprecated
10771078
~name:
10781079
(constructor.cname.txt
10791080
^ printConstructorArgs numArgs ~asSnippet:false)

Diff for: analysis/src/ProcessCmt.ml

+6
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,9 @@ let rec forTypeSignatureItem ~(env : SharedTypes.Env.t) ~(exported : Exported.t)
100100
res = cd_res;
101101
typeDecl = (name, decl);
102102
docstring = attrsToDocstring cd_attributes;
103+
deprecated =
104+
ProcessAttributes.findDeprecatedAttribute
105+
cd_attributes;
103106
}
104107
in
105108
let declared =
@@ -201,6 +204,9 @@ let forTypeDeclaration ~env ~(exported : Exported.t)
201204
{
202205
Constructor.stamp;
203206
cname;
207+
deprecated =
208+
ProcessAttributes.findDeprecatedAttribute
209+
cd_attributes;
204210
args =
205211
(match cd_args with
206212
| Cstr_tuple args ->

Diff for: analysis/src/SharedTypes.ml

+4-3
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ module Constructor = struct
4747
res: Types.type_expr option;
4848
typeDecl: string * Types.type_declaration;
4949
docstring: string list;
50+
deprecated: string option;
5051
}
5152
end
5253

@@ -368,12 +369,12 @@ module Completion = struct
368369
detail;
369370
}
370371

371-
let createWithSnippet ~name ?insertText ~kind ~env ?sortText ?filterText
372-
?(docstring = []) () =
372+
let createWithSnippet ~name ?insertText ~kind ~env ?sortText ?deprecated
373+
?filterText ?(docstring = []) () =
373374
{
374375
name;
375376
env;
376-
deprecated = None;
377+
deprecated;
377378
docstring;
378379
kind;
379380
sortText;

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

+8
Original file line numberDiff line numberDiff line change
@@ -440,5 +440,13 @@ let rWithDepr: someRecordWithDeprecatedField = {
440440
someFloat: 12.,
441441
}
442442

443+
// Should show deprecated status
443444
// rWithDepr.so
444445
// ^com
446+
447+
type someVariantWithDeprecated =
448+
| @deprecated DoNotUseMe | UseMeInstead | @deprecated("Use 'UseMeInstead'") AndNotMe
449+
450+
// Should show deprecated status
451+
// let v: someVariantWithDeprecated =
452+
// ^com

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

+36-5
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->445:0]
1629-
Pexp_apply ...__ghost__[0:-1->0:-1] (...[405:11->423:17], ...[428:0->445:0])
1628+
posCursor:[405:22] posNoWhite:[405:21] Found expr:[405:11->453:0]
1629+
Pexp_apply ...__ghost__[0:-1->0:-1] (...[405:11->423:17], ...[428:0->453: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,9 +1759,9 @@ 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]
1762+
Complete src/Completion.res 443:15
1763+
posCursor:[443:15] posNoWhite:[443:14] Found expr:[443:3->443:15]
1764+
Pexp_field [443:3->443:12] so:[443:13->443:15]
17651765
Completable: Cpath Value[rWithDepr].so
17661766
Raw opens: 2 Shadow.B.place holder ... Shadow.A.place holder
17671767
Resolved opens 2 Completion.res Completion.res
@@ -1779,3 +1779,34 @@ Resolved opens 2 Completion.res Completion.res
17791779
"documentation": {"kind": "markdown", "value": "Deprecated: Use 'someInt'.\n\n"}
17801780
}]
17811781

1782+
Complete src/Completion.res 450:37
1783+
XXX Not found!
1784+
Completable: Cexpression Type[someVariantWithDeprecated]
1785+
Raw opens: 2 Shadow.B.place holder ... Shadow.A.place holder
1786+
Resolved opens 2 Completion.res Completion.res
1787+
[{
1788+
"label": "DoNotUseMe",
1789+
"kind": 4,
1790+
"tags": [1],
1791+
"detail": "DoNotUseMe\n\ntype someVariantWithDeprecated =\n | DoNotUseMe\n | UseMeInstead\n | AndNotMe",
1792+
"documentation": {"kind": "markdown", "value": "Deprecated: \n\n"},
1793+
"insertText": "DoNotUseMe",
1794+
"insertTextFormat": 2
1795+
}, {
1796+
"label": "UseMeInstead",
1797+
"kind": 4,
1798+
"tags": [],
1799+
"detail": "UseMeInstead\n\ntype someVariantWithDeprecated =\n | DoNotUseMe\n | UseMeInstead\n | AndNotMe",
1800+
"documentation": null,
1801+
"insertText": "UseMeInstead",
1802+
"insertTextFormat": 2
1803+
}, {
1804+
"label": "AndNotMe",
1805+
"kind": 4,
1806+
"tags": [1],
1807+
"detail": "AndNotMe\n\ntype someVariantWithDeprecated =\n | DoNotUseMe\n | UseMeInstead\n | AndNotMe",
1808+
"documentation": {"kind": "markdown", "value": "Deprecated: Use 'UseMeInstead'\n\n"},
1809+
"insertText": "AndNotMe",
1810+
"insertTextFormat": 2
1811+
}]
1812+

0 commit comments

Comments
 (0)