Skip to content

Commit c52647f

Browse files
committed
Don't complete inside comments.
1 parent aca03b1 commit c52647f

File tree

5 files changed

+18
-1
lines changed

5 files changed

+18
-1
lines changed

analysis/src/Completion.ml

+1
Original file line numberDiff line numberDiff line change
@@ -494,6 +494,7 @@ let completionWithParser ~debug ~path ~posCursor ~currentFile ~text =
494494
if expr.pexp_loc |> Loc.hasPos ~pos:posNoWhite then (
495495
setFound ();
496496
match expr.pexp_desc with
497+
| Pexp_constant _ -> setResult Cnone
497498
| Pexp_ident id ->
498499
if debug then
499500
Printf.printf "Pexp_ident %s:%s\n"

analysis/src/NewCompletions.ml

+1
Original file line numberDiff line numberDiff line change
@@ -1160,6 +1160,7 @@ let processCompletable ~package ~scope ~env ~pos (completable : Completable.t) =
11601160
|> completionsGetTypeEnv
11611161
in
11621162
match completable with
1163+
| Cnone -> []
11631164
| Cpath contextPath ->
11641165
contextPath
11651166
|> getCompletionsForContextPath ~package ~opens ~rawOpens ~allFiles ~pos

analysis/src/SharedTypes.ml

+2
Original file line numberDiff line numberDiff line change
@@ -412,6 +412,7 @@ module Completable = struct
412412
| Cdecorator of string (** e.g. @module *)
413413
| Clabel of string list * string * string list
414414
(** e.g. (["M", "foo"], "label", ["l1", "l2"]) for M.foo(...~l1...~l2...~label...) *)
415+
| Cnone (** e.g. don't complete inside strings *)
415416
| Cpath of contextPath
416417
| Cjsx of string list * string * string list
417418
(** E.g. (["M", "Comp"], "id", ["id1", "id2"]) for <M.Comp id1=... id2=... ... id *)
@@ -439,6 +440,7 @@ module Completable = struct
439440
| Cdecorator s -> "Cdecorator(" ^ str s ^ ")"
440441
| Clabel (sl1, s, sl2) ->
441442
"Clabel(" ^ (sl1 |> list) ^ ", " ^ str s ^ ", " ^ (sl2 |> list) ^ ")"
443+
| Cnone -> "Cnone"
442444
| Cjsx (sl1, s, sl2) ->
443445
"Cjsx(" ^ (sl1 |> list) ^ ", " ^ str s ^ ", " ^ (sl2 |> list) ^ ")"
444446
end

analysis/tests/src/Completion.res

+4-1
Original file line numberDiff line numberDiff line change
@@ -235,4 +235,7 @@ module FAO = {
235235

236236
let name = "abc"
237237
// let template = `My name is ${na}`
238-
// ^com
238+
// ^com
239+
240+
let notHere = " "
241+
// ^com

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

+10
Original file line numberDiff line numberDiff line change
@@ -832,6 +832,11 @@ DocumentSymbol tests/src/Completion.res
832832
"name": "name",
833833
"kind": 15,
834834
"location": {"uri": "Completion.res", "range": {"start": {"line": 235, "character": 0}, "end": {"line": 235, "character": 16}}}
835+
},
836+
{
837+
"name": "notHere",
838+
"kind": 15,
839+
"location": {"uri": "Completion.res", "range": {"start": {"line": 239, "character": 0}, "end": {"line": 239, "character": 22}}}
835840
}
836841
]
837842

@@ -1306,3 +1311,8 @@ Completable: Cpath Value[na]
13061311
"documentation": null
13071312
}]
13081313

1314+
Complete tests/src/Completion.res 239:17
1315+
posCursor:[239:17] posNoWhite:[239:14] Found expr:[239:14->239:22]
1316+
Completable: Cnone
1317+
[]
1318+

0 commit comments

Comments
 (0)