Skip to content
This repository has been archived by the owner on Apr 24, 2021. It is now read-only.

Commit

Permalink
Autocomplete fix: don't let -> override . autocomplete
Browse files Browse the repository at this point in the history
Fixes #99
  • Loading branch information
cristianoc committed Apr 9, 2021
1 parent b4c2e85 commit 02740ca
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
1 change: 1 addition & 0 deletions Changes.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
- Fix issue in jump-to-definition on Windows. (See https://github.com/rescript-lang/rescript-vscode/issues/98) where the wrong URI was generated.
- Don't show file path on hover.
- Add autocomplete for props in JSX components.
- Autocomplete: fix issue where `->` autocomplete was overruling `.`. See https://github.com/rescript-lang/rescript-editor-support/issues/99.

## Release 1.0.6 of rescript-vscode
This [commit](https://github.com/rescript-lang/rescript-editor-support/commit/03ee0d97b250474028d4fb08eac81ddb21ccb082) is vendored in [rescript-vscode 1.0.6](https://github.com/rescript-lang/rescript-vscode/releases/tag/1.0.6).
Expand Down
16 changes: 15 additions & 1 deletion src/PartialParser.ml
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,18 @@ type completable =
| Cjsx of string list * string (* E.g. (["M", "Comp"], "id") for <M.Comp ... id *)
| Cpipe of string (* E.g. "x->foo" *)


let isLowercaseIdent id =
let rec loop i =
if i < 0 then true
else
match id.[i] with
| ('a' .. 'z' | '_') when i = 0 -> true
| ('a' .. 'z' | 'A' .. 'Z' | '0' .. '9' | '_') when i > 0 -> loop (i - 1)
| _ -> false
in
loop (String.length id - 1)

let findCompletable text offset =
let mkPath s =
let len = String.length s in
Expand All @@ -142,7 +154,9 @@ let findCompletable text offset =
| true -> Some (mkPath (String.sub text (i + 1) (offset - (i + 1))))
| false -> (
match text.[i] with
| '>' when i > 0 && text.[i - 1] = '-' -> loop (i - 2)
| '>' when i > 0 && text.[i - 1] = '-' ->
let rest = String.sub text (i + 1) (offset - (i + 1)) in
if isLowercaseIdent rest then loop (i - 2) else Some (mkPath rest)
| '~' ->
let labelPrefix = String.sub text (i + 1) (offset - (i + 1)) in
let funPath = findCallFromArgument text (i - 1) in
Expand Down

0 comments on commit 02740ca

Please sign in to comment.