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

Commit a22b38a

Browse files
committedApr 9, 2021
Autocomplete fix: don't let -> override . autocomplete
Fixes #99
1 parent 3942bee commit a22b38a

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed
 

‎Changes.md

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
- Fix issue in jump-to-definition on Windows. (See https://github.com/rescript-lang/rescript-vscode/issues/98) where the wrong URI was generated.
33
- Don't show file path on hover.
44
- Add autocomplete for props in JSX components.
5+
- Autocomplete: fix issue where `->` autocomplete was overruling `.`. See https://github.com/rescript-lang/rescript-editor-support/issues/99.
56

67
## Release 1.0.6 of rescript-vscode
78
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).

‎src/PartialParser.ml

+15-1
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,18 @@ type completable =
116116
| Cjsx of string list * string (* E.g. (["M", "Comp"], "id") for <M.Comp ... id *)
117117
| Cpipe of string (* E.g. "x->foo" *)
118118

119+
120+
let isLowercaseIdent id =
121+
let rec loop i =
122+
if i < 0 then true
123+
else
124+
match id.[i] with
125+
| ('a' .. 'z' | '_') when i = 0 -> true
126+
| ('a' .. 'z' | 'A' .. 'Z' | '0' .. '9' | '_') when i > 0 -> loop (i - 1)
127+
| _ -> false
128+
in
129+
loop (String.length id - 1)
130+
119131
let findCompletable text offset =
120132
let mkPath s =
121133
let len = String.length s in
@@ -142,7 +154,9 @@ let findCompletable text offset =
142154
| true -> Some (mkPath (String.sub text (i + 1) (offset - (i + 1))))
143155
| false -> (
144156
match text.[i] with
145-
| '>' when i > 0 && text.[i - 1] = '-' -> loop (i - 2)
157+
| '>' when i > 0 && text.[i - 1] = '-' ->
158+
let rest = String.sub text (i + 1) (offset - (i + 1)) in
159+
if isLowercaseIdent rest then loop (i - 2) else Some (mkPath rest)
146160
| '~' ->
147161
let labelPrefix = String.sub text (i + 1) (offset - (i + 1)) in
148162
let funPath = findCallFromArgument text (i - 1) in

0 commit comments

Comments
 (0)