-
Notifications
You must be signed in to change notification settings - Fork 57
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
Conversation
@@ -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 |
There was a problem hiding this comment.
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.
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added this.
(* 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; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is new.
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is new.
… intent to fill in the next argument)
2ea95d1
to
897443a
Compare
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