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

Improve signature help precision #675

Merged
merged 3 commits into from
Jan 5, 2023
Merged

Conversation

zth
Copy link
Collaborator

@zth zth commented Jan 4, 2023

Better precision in signature help. You now don't have to start typing in an argument for it to highlight. We now look at commas to decide which argument you're currently intending to fill in.

Closes #672

@zth zth requested a review from cristianoc January 4, 2023 19:47
@@ -152,159 +152,206 @@ let docsForLabel typeExpr ~file ~package ~supportsMarkdownLinks =
typeString :: typeDefinitions |> String.concat "\n"

let signatureHelp ~path ~pos ~currentFile ~debug =
let posBeforeCursor = Pos.posBeforeCursor pos in
Copy link
Collaborator Author

@zth zth Jan 4, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Absolutely terrible display of the diff in GitHub. I've added two optional unwrappings which messes with the indentation, which messes up the diff. Haven't really changed that much.

I added comments highlighting the things I've actually changed/added.

Comment on lines +155 to +167
let textOpt = Files.readFile currentFile in
match textOpt with
| None | Some "" -> None
| Some text -> (
match Pos.positionToOffset text pos with
| None -> None
| Some offset -> (
let posBeforeCursor = Pos.posBeforeCursor pos in
let offsetNoWhite = Utils.skipWhite text (offset - 1) in
let firstCharBeforeCursorNoWhite =
if offsetNoWhite < String.length text && offsetNoWhite >= 0 then
Some text.[offsetNoWhite]
else None
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added this.

Comment on lines +192 to +198
(* If this unlabelled arg doesn't have the cursor, record
it as the last seen unlabelled arg before the
cursor.*)
if posBeforeCursor >= (arg.exp.pexp_loc |> Loc.start)
then
lastUnlabelledArgBeforeCursor :=
currentUnlabelledArgCount;
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is new.

Comment on lines +222 to +237
match argAtCursor_ with
| None ->
Some
(Unlabelled
(!lastUnlabelledArgBeforeCursor
+
if firstCharBeforeCursorNoWhite = Some ',' then 1
(* If we found no argument with the cursor, we might still be
able to complete for an unlabelled argument, if the char
before the cursor is ',', like: `someFn(123, <com>)`
complete for argument 2, or: `someFn(123, <com>, true)`
complete for argument 2 as well. Adding 1 here accounts
for the comma telling us that the users intent is to fill
in the next argument. *)
else 0))
| v -> v
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is new.

@zth zth force-pushed the improve-signature-help-precision branch from 2ea95d1 to 897443a Compare January 4, 2023 20:06
@zth zth merged commit 9416cc9 into master Jan 5, 2023
@zth zth deleted the improve-signature-help-precision branch January 5, 2023 09:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Improve precision in signature help
2 participants