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

Fix signature help in uncurried mode #809

Merged
merged 2 commits into from
Aug 17, 2023
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
- Don't emit object keys in uppercase as namespace. https://github.com/rescript-lang/rescript-vscode/pull/798
- Fix accidental output of extra `|` when producing exhaustive switch code for polyvariants. https://github.com/rescript-lang/rescript-vscode/pull/805
- Fix JS syntax highlighting in single-line FFI extension points. https://github.com/rescript-lang/rescript-vscode/pull/807
- Fix signature help in uncurried mode. https://github.com/rescript-lang/rescript-vscode/pull/809

## 1.18.0

Expand Down
23 changes: 18 additions & 5 deletions analysis/src/SignatureHelp.ml
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,23 @@ let findFunctionType ~currentFile ~debug ~path ~pos =
let extractParameters ~signature ~typeStrForParser ~labelPrefixLen =
match signature with
| [
{
Parsetree.psig_desc =
Psig_value {pval_type = {ptyp_desc = Ptyp_arrow _} as expr};
};
( {
Parsetree.psig_desc =
Psig_value {pval_type = {ptyp_desc = Ptyp_arrow _} as expr};
}
| {
psig_desc =
Psig_value
{
pval_type =
{
ptyp_desc =
Ptyp_constr
( {txt = Lident "function$"},
[({ptyp_desc = Ptyp_arrow _} as expr); _] );
};
};
} );
] ->
let rec extractParams expr params =
match expr with
Expand Down Expand Up @@ -262,7 +275,7 @@ let signatureHelp ~path ~pos ~currentFile ~debug =
| {
pexp_desc =
Pexp_apply
( {pexp_desc = Pexp_ident {txt = Lident "|."}},
( {pexp_desc = Pexp_ident {txt = Lident ("|." | "|.u")}},
[
_;
( _,
Expand Down
78 changes: 78 additions & 0 deletions analysis/tests/src/SignatureHelpUncurried.res
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
@@uncurried

type someVariant = One | Two | Three

/** Does stuff. */
let someFunc = (one: int, ~two: option<string>=?, ~three: unit => unit, ~four: someVariant, ()) => {
ignore(one)
ignore(two)
ignore(three())
ignore(four)
}

let otherFunc = (first: string, second: int, third: float) => {
ignore(first)
ignore(second)
ignore(third)
}

// let _ = someFunc(
// ^she

// let _ = someFunc(1
// ^she

// let _ = someFunc(123, ~two
// ^she

// let _ = someFunc(123, ~two="123"
// ^she

// let _ = someFunc(123, ~two="123", ~four
// ^she

// let _ = someFunc(123, ~two="123", ~four=O
// ^she

// let _ = otherFunc(
// ^she

// let _ = otherFunc("123"
// ^she

// let _ = otherFunc("123", 123, 123.0)
// ^she

// let _ = Completion.Lib.foo(~age
// ^she

let iAmSoSpecial = (iJustHaveOneArg: string) => {
ignore(iJustHaveOneArg)
}

// let _ = iAmSoSpecial(
// ^she

// let _ = "hello"->otherFunc(1
// ^she

let fn = (age: int, name: string, year: int) => {
ignore(age)
ignore(name)
ignore(year)
}

// let _ = fn(22, )
// ^she

// let _ = fn(22, , 2023)
// ^she

// let _ = fn(12, "hello", )
// ^she

// let _ = fn({ iAmSoSpecial() })
// ^she

// let _ = fn({ iAmSoSpecial({ someFunc() }) })
// ^she
Loading