From 8ca6cf3f7a7d3fefc455f6a85d757b2181cb7f6a Mon Sep 17 00:00:00 2001 From: Shulhi Sapli <913103+shulhi@users.noreply.github.com> Date: Sun, 15 Feb 2026 22:08:00 +0800 Subject: [PATCH 1/3] Fix inlay hints reading from disk instead of editor buffer --- analysis/bin/main.ml | 6 +++++- analysis/src/Commands.ml | 6 +++--- analysis/src/Hint.ml | 5 +++-- 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/analysis/bin/main.ml b/analysis/bin/main.ml index e5075f102ed..6969585b83e 100644 --- a/analysis/bin/main.ml +++ b/analysis/bin/main.ml @@ -166,10 +166,14 @@ let main () = (match allowForConstructorPayloads with | "true" -> true | _ -> false) + | [_; "inlayHint"; path; line_start; line_end; maxLength; currentFile] -> + Commands.inlayhint ~path + ~pos:(int_of_string line_start, int_of_string line_end) + ~maxLength ~currentFile:(Some currentFile) ~debug | [_; "inlayHint"; path; line_start; line_end; maxLength] -> Commands.inlayhint ~path ~pos:(int_of_string line_start, int_of_string line_end) - ~maxLength ~debug + ~maxLength ~currentFile:None ~debug | [_; "codeLens"; path] -> Commands.codeLens ~path ~debug | [_; "codeAction"; path; startLine; startCol; endLine; endCol; currentFile] -> diff --git a/analysis/src/Commands.ml b/analysis/src/Commands.ml index 40799348ec5..97fe46c14af 100644 --- a/analysis/src/Commands.ml +++ b/analysis/src/Commands.ml @@ -41,9 +41,9 @@ let completionResolve ~path ~modulePath = in print_endline docstring -let inlayhint ~path ~pos ~maxLength ~debug = +let inlayhint ~path ~pos ~maxLength ~currentFile ~debug = let result = - match Hint.inlay ~path ~pos ~maxLength ~debug with + match Hint.inlay ~path ~pos ~maxLength ~currentFile ~debug with | Some hints -> hints |> Protocol.array | None -> Protocol.null in @@ -516,7 +516,7 @@ let test ~path = ("Inlay Hint " ^ path ^ " " ^ string_of_int line_start ^ ":" ^ string_of_int line_end); inlayhint ~path ~pos:(line_start, line_end) ~maxLength:"25" - ~debug:false + ~currentFile:None ~debug:false | "cle" -> print_endline ("Code Lens " ^ path); codeLens ~path ~debug:false diff --git a/analysis/src/Hint.ml b/analysis/src/Hint.ml index 71b1b7cfe3a..0b3efd0c42c 100644 --- a/analysis/src/Hint.ml +++ b/analysis/src/Hint.ml @@ -31,7 +31,7 @@ let locItemToTypeHint ~full:{file; package} locItem = | `Field -> fromType t)) | _ -> None -let inlay ~path ~pos ~maxLength ~debug = +let inlay ~path ~pos ~maxLength ~currentFile ~debug = let maxlen = try Some (int_of_string maxLength) with Failure _ -> None in let hints = ref [] in let start_line, end_line = pos in @@ -71,11 +71,12 @@ let inlay ~path ~pos ~maxLength ~debug = Ast_iterator.default_iterator.value_binding iterator vb in let iterator = {Ast_iterator.default_iterator with value_binding} in + let sourceFile = match currentFile with Some f -> f | None -> path in (if Files.classifySourceFile path = Res then let parser = Res_driver.parsing_engine.parse_implementation ~for_printer:false in - let {Res_driver.parsetree = structure} = parser ~filename:path in + let {Res_driver.parsetree = structure} = parser ~filename:sourceFile in iterator.structure iterator structure |> ignore); match Cmt.loadFullCmtFromPath ~path with | None -> None From f96d112feb0fd665ef38e1ef90e22f6301a48e81 Mon Sep 17 00:00:00 2001 From: Shulhi Sapli <913103+shulhi@users.noreply.github.com> Date: Sun, 22 Feb 2026 11:12:56 +0800 Subject: [PATCH 2/3] Run ocamlformat --- analysis/src/Hint.ml | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/analysis/src/Hint.ml b/analysis/src/Hint.ml index 0b3efd0c42c..83a42cb4783 100644 --- a/analysis/src/Hint.ml +++ b/analysis/src/Hint.ml @@ -71,7 +71,11 @@ let inlay ~path ~pos ~maxLength ~currentFile ~debug = Ast_iterator.default_iterator.value_binding iterator vb in let iterator = {Ast_iterator.default_iterator with value_binding} in - let sourceFile = match currentFile with Some f -> f | None -> path in + let sourceFile = + match currentFile with + | Some f -> f + | None -> path + in (if Files.classifySourceFile path = Res then let parser = Res_driver.parsing_engine.parse_implementation ~for_printer:false From de69c76e5ffb5dc6056bdb0c1ceb82056521b581 Mon Sep 17 00:00:00 2001 From: Shulhi Sapli <913103+shulhi@users.noreply.github.com> Date: Fri, 27 Feb 2026 19:58:51 +0800 Subject: [PATCH 3/3] Add comment --- analysis/src/Hint.ml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/analysis/src/Hint.ml b/analysis/src/Hint.ml index 83a42cb4783..6825b8229be 100644 --- a/analysis/src/Hint.ml +++ b/analysis/src/Hint.ml @@ -31,6 +31,12 @@ let locItemToTypeHint ~full:{file; package} locItem = | `Field -> fromType t)) | _ -> None +(* [currentFile] is the file to parse for the AST. The LSP writes the + editor's current (possibly unsaved) buffer to a temporary file and passes + that path here, so hint positions stay in sync with what the user sees even + before the file is saved. When [None], [path] itself is parsed instead. + [path] is always the original on-disk path and is used for loading the + compiled `.cmt` artefact. *) let inlay ~path ~pos ~maxLength ~currentFile ~debug = let maxlen = try Some (int_of_string maxLength) with Failure _ -> None in let hints = ref [] in