Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

More removal of _ in expr completion #890

Merged
merged 2 commits into from
Jan 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
26 changes: 17 additions & 9 deletions analysis/src/CompletionBackEnd.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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 *)
Expand Down
4 changes: 2 additions & 2 deletions analysis/tests/src/expected/CompletionExpressions.res.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
}]

Expand Down Expand Up @@ -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
}]

Expand Down
4 changes: 2 additions & 2 deletions analysis/tests/src/expected/CompletionJsxProps.res.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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
}]

12 changes: 6 additions & 6 deletions analysis/tests/src/expected/CompletionTypeAnnotation.res.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
}]

Expand Down Expand Up @@ -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
}]

Expand Down Expand Up @@ -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
}]

Expand All @@ -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
}]

Expand Down Expand Up @@ -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
}]

Expand Down Expand Up @@ -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
}]