From dadf0712858bfde03a1a3c1a4124f3b70b264577 Mon Sep 17 00:00:00 2001 From: Gabriel Nordeborn Date: Tue, 9 Jan 2024 12:18:59 +0100 Subject: [PATCH 1/2] more removal of _ in expr completion --- analysis/src/CompletionBackEnd.ml | 26 ++++++++++++------- .../expected/CompletionExpressions.res.txt | 4 +-- .../src/expected/CompletionJsxProps.res.txt | 4 +-- .../expected/CompletionTypeAnnotation.res.txt | 12 ++++----- 4 files changed, 27 insertions(+), 19 deletions(-) diff --git a/analysis/src/CompletionBackEnd.ml b/analysis/src/CompletionBackEnd.ml index 839aa50bf..9ffc51fcc 100644 --- a/analysis/src/CompletionBackEnd.ml +++ b/analysis/src/CompletionBackEnd.ml @@ -1168,24 +1168,32 @@ let filterItems items ~prefix = |> List.filter (fun (item : Completion.t) -> Utils.startsWith item.name prefix) -let printConstructorArgs argsLen ~asSnippet = +type completionMode = Pattern of Completable.patternMode | Expression + +let emptyCase ~mode num = + match mode with + | Expression -> "$" ^ string_of_int (num - 1) + | Pattern _ -> "${" ^ string_of_int num ^ ":_}" + +let printConstructorArgs ~mode ~asSnippet argsLen = let args = ref [] in for argNum = 1 to argsLen do args := - !args @ [(if asSnippet then Printf.sprintf "${%i:_}" argNum else "_")] + !args + @ [ + (match (asSnippet, argsLen) with + | true, l when l > 1 -> Printf.sprintf "${%i:_}" argNum + | true, l when l > 0 -> emptyCase ~mode argNum + | _ -> "_"); + ] done; if List.length !args > 0 then "(" ^ (!args |> String.concat ", ") ^ ")" else "" -type completionMode = Pattern of Completable.patternMode | Expression - let rec completeTypedValue ~rawOpens ~full ~prefix ~completionContext ~mode (t : SharedTypes.completionType) = - let emptyCase num = - match mode with - | Expression -> "$" ^ string_of_int (num - 1) - | Pattern _ -> "${" ^ string_of_int num ^ ":_}" - in + let emptyCase = emptyCase ~mode in + let printConstructorArgs = printConstructorArgs ~mode in match t with | TtypeT {env; path} -> (* Find all functions in the module that returns type t *) diff --git a/analysis/tests/src/expected/CompletionExpressions.res.txt b/analysis/tests/src/expected/CompletionExpressions.res.txt index c56f744e4..0b5a19564 100644 --- a/analysis/tests/src/expected/CompletionExpressions.res.txt +++ b/analysis/tests/src/expected/CompletionExpressions.res.txt @@ -1163,7 +1163,7 @@ Path fnTakingPolyVariant "tags": [], "detail": "#two(bool)\n\n[#one | #three(someRecord, bool) | #two(bool)]", "documentation": null, - "insertText": "#two(${1:_})", + "insertText": "#two($0)", "insertTextFormat": 2 }] @@ -1198,7 +1198,7 @@ Path fnTakingPolyVariant "tags": [], "detail": "#two(bool)\n\n[#one | #three(someRecord, bool) | #two(bool)]", "documentation": null, - "insertText": "two(${1:_})", + "insertText": "two($0)", "insertTextFormat": 2 }] diff --git a/analysis/tests/src/expected/CompletionJsxProps.res.txt b/analysis/tests/src/expected/CompletionJsxProps.res.txt index 43a91f799..b4612a73a 100644 --- a/analysis/tests/src/expected/CompletionJsxProps.res.txt +++ b/analysis/tests/src/expected/CompletionJsxProps.res.txt @@ -60,7 +60,7 @@ Path CompletionSupport.TestComponent.make "detail": "Three(int)\n\ntype testVariant = One | Two | Three(int)", "documentation": null, "sortText": "A Three(_)", - "insertText": "{Three(${1:_})}", + "insertText": "{Three($0)}", "insertTextFormat": 2 }, { "label": "TableclothMap", @@ -250,7 +250,7 @@ Path CompletionSupport.TestComponent.make "tags": [], "detail": "Three(int)\n\ntype testVariant = One | Two | Three(int)", "documentation": null, - "insertText": "Three(${1:_})", + "insertText": "Three($0)", "insertTextFormat": 2 }] diff --git a/analysis/tests/src/expected/CompletionTypeAnnotation.res.txt b/analysis/tests/src/expected/CompletionTypeAnnotation.res.txt index e8a009cf8..e2db577b7 100644 --- a/analysis/tests/src/expected/CompletionTypeAnnotation.res.txt +++ b/analysis/tests/src/expected/CompletionTypeAnnotation.res.txt @@ -58,7 +58,7 @@ Path someVariant "tags": [], "detail": "Two(bool)\n\ntype someVariant = One | Two(bool)", "documentation": null, - "insertText": "Two(${1:_})", + "insertText": "Two($0)", "insertTextFormat": 2 }] @@ -113,7 +113,7 @@ Path somePolyVariant "tags": [], "detail": "#two(bool)\n\n[#one | #two(bool)]", "documentation": null, - "insertText": "#two(${1:_})", + "insertText": "#two($0)", "insertTextFormat": 2 }] @@ -240,7 +240,7 @@ Path someVariant "tags": [], "detail": "Two(bool)\n\ntype someVariant = One | Two(bool)", "documentation": null, - "insertText": "Some(Two(${1:_}))", + "insertText": "Some(Two($0))", "insertTextFormat": 2 }] @@ -266,7 +266,7 @@ Path someVariant "tags": [], "detail": "Two(bool)\n\ntype someVariant = One | Two(bool)", "documentation": null, - "insertText": "Two(${1:_})", + "insertText": "Two($0)", "insertTextFormat": 2 }] @@ -311,7 +311,7 @@ Path someVariant "tags": [], "detail": "Two(bool)\n\ntype someVariant = One | Two(bool)", "documentation": null, - "insertText": "Two(${1:_})", + "insertText": "Two($0)", "insertTextFormat": 2 }] @@ -358,7 +358,7 @@ Path someVariant "tags": [], "detail": "Two(bool)\n\ntype someVariant = One | Two(bool)", "documentation": null, - "insertText": "Two(${1:_})", + "insertText": "Two($0)", "insertTextFormat": 2 }] From 082ef56052a2f1e313f45d40bf7cca130ce79100 Mon Sep 17 00:00:00 2001 From: Gabriel Nordeborn Date: Tue, 9 Jan 2024 12:20:49 +0100 Subject: [PATCH 2/2] changelog --- CHANGELOG.md | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7d31631c5..dbbe7e6c1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,10 @@ ## master +#### :nail_care: Polish + +- More cases of not emitting `_` when completing in expressions. https://github.com/rescript-lang/rescript-vscode/pull/890 + ## 1.34.0 #### :rocket: New Feature @@ -23,7 +27,7 @@ #### :nail_care: Polish - Better error recovery when analysis fails. https://github.com/rescript-lang/rescript-vscode/pull/880 -- Do not emit `_` when completing in patterns. https://github.com/rescript-lang/rescript-vscode/pull/885 +- Do not emit `_` when completing in expressions. https://github.com/rescript-lang/rescript-vscode/pull/885 - Include fields when completing a braced expr that's an ID, where it the path likely starts with a module. https://github.com/rescript-lang/rescript-vscode/pull/882 ## 1.32.0