Skip to content

Fix crash where the completion command receives a non-existing offset. #463

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

Merged
merged 1 commit into from
Jun 18, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 10 additions & 7 deletions analysis/src/CompletionFrontEnd.ml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ let offsetOfLine text line =
let positionToOffset text (line, character) =
match offsetOfLine text line with
| None -> None
| Some bol -> Some (bol + character)
| Some bol ->
if bol + character <= String.length text then Some (bol + character)
else None

type prop = {
name: string;
Expand Down Expand Up @@ -216,12 +218,7 @@ let rec exprToContextPath (e : Parsetree.expression) =
| Some contexPath -> Some (CPApply (contexPath, args |> List.map fst)))
| _ -> None

let completionWithParser ~debug ~path ~posCursor ~currentFile ~text =
let offset =
match positionToOffset text posCursor with
| Some offset -> offset
| None -> assert false
in
let completionWithParser1 ~currentFile ~debug ~offset ~path ~posCursor ~text =
let offsetNoWhite = skipWhite text (offset - 1) in
let posNoWhite =
let line, col = posCursor in
Expand Down Expand Up @@ -789,3 +786,9 @@ let completionWithParser ~debug ~path ~posCursor ~currentFile ~text =
if !found = false then if debug then Printf.printf "XXX Not found!\n";
!result)
else None

let completionWithParser ~debug ~path ~posCursor ~currentFile ~text =
match positionToOffset text posCursor with
| Some offset ->
completionWithParser1 ~currentFile ~debug ~offset ~path ~posCursor ~text
| None -> None