Skip to content

Commit 76959b6

Browse files
committed
Autocomplete: skip inline comments to decide if a labeled argument was already supplied.
Fixes #250
1 parent 59d099b commit 76959b6

File tree

3 files changed

+20
-6
lines changed

3 files changed

+20
-6
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
## master
22
- Find references to files as modules.
3+
- Autocomplete: skip inline comments to decide if a labeled argument was already supplied.
34

45
## 1.1.2
56

analysis/src/PartialParser.ml

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,18 @@ let rec findBackSkippingCommentsAndStrings text char pair i level =
2121
loop (findOpenComment text (i - 2)) level
2222
| _ -> loop (i - 1) level
2323

24+
let rec findLineComment text offset =
25+
if offset <= 0 || text.[offset] = '\n' then None
26+
else if offset > 0 && text.[offset] = '/' && text.[offset - 1] = '/' then
27+
Some (offset - 1)
28+
else findLineComment text (offset - 1)
29+
30+
(* Check if the position is inside a `//` comment *)
31+
let insideLineComment text offset = findLineComment text offset <> None
32+
33+
let skipLineComment text offset =
34+
match findLineComment text offset with None -> offset | Some n -> n - 1
35+
2436
let rec skipWhite text i =
2537
if i < 0 then 0
2638
else
@@ -38,6 +50,7 @@ let rec startOfLident text i =
3850
let findCallFromArgument text offset =
3951
let none = ([], []) in
4052
let rec loop identsSeen i =
53+
let i = skipLineComment text i in
4154
let i = skipWhite text i in
4255
if i > 0 then
4356
match text.[i] with
@@ -244,12 +257,6 @@ let findCompletable text offset =
244257
in
245258
if offset > String.length text || offset = 0 then None else loop (offset - 1)
246259

247-
(* Check if the position is inside a `//` comment *)
248-
let rec insideLineComment text offset =
249-
if offset <= 0 || text.[offset] = '\n' then false
250-
else if offset > 0 && text.[offset] = '/' && text.[offset - 1] = '/' then true
251-
else insideLineComment text (offset - 1)
252-
253260
let findOpens text offset =
254261
let opens = ref [] in
255262
let pathOfModuleOpen o =

analysis/tests/src/expected/Completion.res.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -585,6 +585,12 @@ Complete tests/src/Completion.res 64:2
585585

586586
Complete tests/src/Completion.res 67:2
587587
[{
588+
"label": "age",
589+
"kind": 4,
590+
"tags": [],
591+
"detail": "int",
592+
"documentation": null
593+
}, {
588594
"label": "name",
589595
"kind": 4,
590596
"tags": [],

0 commit comments

Comments
 (0)