File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -161,10 +161,14 @@ let main () =
161161 (match allowForConstructorPayloads with
162162 | "true" -> true
163163 | _ -> false )
164+ | [_; " inlayHint" ; path; line_start; line_end; maxLength; currentFile] ->
165+ Commands. inlayhint ~path
166+ ~pos: (int_of_string line_start, int_of_string line_end)
167+ ~max Length ~current File:(Some currentFile) ~debug
164168 | [_; " inlayHint" ; path; line_start; line_end; maxLength] ->
165169 Commands. inlayhint ~path
166170 ~pos: (int_of_string line_start, int_of_string line_end)
167- ~max Length ~debug
171+ ~max Length ~current File: None ~ debug
168172 | [_; " codeLens" ; path] -> Commands. codeLens ~path ~debug
169173 | [_; " codeAction" ; path; startLine; startCol; endLine; endCol; currentFile]
170174 ->
Original file line number Diff line number Diff line change @@ -41,9 +41,9 @@ let completionResolve ~path ~modulePath =
4141 in
4242 print_endline docstring
4343
44- let inlayhint ~path ~pos ~maxLength ~debug =
44+ let inlayhint ~path ~pos ~maxLength ~currentFile ~ debug =
4545 let result =
46- match Hint. inlay ~path ~pos ~max Length ~debug with
46+ match Hint. inlay ~path ~pos ~max Length ~current File ~ debug with
4747 | Some hints -> hints |> Protocol. array
4848 | None -> Protocol. null
4949 in
@@ -491,7 +491,7 @@ let test ~path =
491491 (" Inlay Hint " ^ path ^ " " ^ string_of_int line_start ^ " :"
492492 ^ string_of_int line_end);
493493 inlayhint ~path ~pos: (line_start, line_end) ~max Length:" 25"
494- ~debug: false
494+ ~current File: None ~ debug:false
495495 | "cle" ->
496496 print_endline (" Code Lens " ^ path);
497497 codeLens ~path ~debug: false
Original file line number Diff line number Diff line change @@ -31,7 +31,7 @@ let locItemToTypeHint ~full:{file; package} locItem =
3131 | `Field -> fromType t))
3232 | _ -> None
3333
34- let inlay ~path ~pos ~maxLength ~debug =
34+ let inlay ~path ~pos ~maxLength ~currentFile ~ debug =
3535 let maxlen = try Some (int_of_string maxLength) with Failure _ -> None in
3636 let hints = ref [] in
3737 let start_line, end_line = pos in
@@ -70,11 +70,12 @@ let inlay ~path ~pos ~maxLength ~debug =
7070 Ast_iterator. default_iterator.value_binding iterator vb
7171 in
7272 let iterator = {Ast_iterator. default_iterator with value_binding} in
73+ let sourceFile = match currentFile with Some f -> f | None -> path in
7374 (if Files. classifySourceFile path = Res then
7475 let parser =
7576 Res_driver. parsing_engine.parse_implementation ~for_printer: false
7677 in
77- let {Res_driver. parsetree = structure} = parser ~filename: path in
78+ let {Res_driver. parsetree = structure} = parser ~filename: sourceFile in
7879 iterator.structure iterator structure |> ignore);
7980 match Cmt. loadFullCmtFromPath ~path with
8081 | None -> None
Original file line number Diff line number Diff line change @@ -646,7 +646,10 @@ async function inlayHint(msg: p.RequestMessage) {
646646 const filePath = utils . uriToNormalizedPath (
647647 params . textDocument . uri as utils . FileURI ,
648648 ) ;
649-
649+ let code = getOpenedFileContent ( params . textDocument . uri as utils . FileURI ) ;
650+ let extension = path . extname ( params . textDocument . uri ) ;
651+ let tmpname = utils . createFileInTempDir ( extension ) ;
652+ fs . writeFileSync ( tmpname , code , { encoding : "utf-8" } ) ;
650653 const response = await utils . runAnalysisCommand (
651654 filePath ,
652655 [
@@ -655,9 +658,11 @@ async function inlayHint(msg: p.RequestMessage) {
655658 params . range . start . line ,
656659 params . range . end . line ,
657660 config . extensionConfiguration . inlayHints ?. maxLength ,
661+ tmpname ,
658662 ] ,
659663 msg ,
660664 ) ;
665+ fs . unlink ( tmpname , ( ) => null ) ;
661666 return response ;
662667}
663668
You can’t perform that action at this time.
0 commit comments