Skip to content

Commit 815ccff

Browse files
committed
Read from current buffer for position
1 parent 2bc69d2 commit 815ccff

4 files changed

Lines changed: 17 additions & 7 deletions

File tree

analysis/bin/main.ml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff 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+
~maxLength ~currentFile:(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-
~maxLength ~debug
171+
~maxLength ~currentFile:None ~debug
168172
| [_; "codeLens"; path] -> Commands.codeLens ~path ~debug
169173
| [_; "codeAction"; path; startLine; startCol; endLine; endCol; currentFile]
170174
->

analysis/src/Commands.ml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff 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 ~maxLength ~debug with
46+
match Hint.inlay ~path ~pos ~maxLength ~currentFile ~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) ~maxLength:"25"
494-
~debug:false
494+
~currentFile:None ~debug:false
495495
| "cle" ->
496496
print_endline ("Code Lens " ^ path);
497497
codeLens ~path ~debug:false

analysis/src/Hint.ml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff 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

server/src/server.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff 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

0 commit comments

Comments
 (0)