Skip to content

Commit b2aee40

Browse files
committed
leverage new unsaved code completion features to provide hover on (some) unsaved code
1 parent 9833a38 commit b2aee40

File tree

6 files changed

+60
-18
lines changed

6 files changed

+60
-18
lines changed

analysis/src/Commands.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ let completion ~debug ~path ~pos ~currentFile =
44
Completions.getCompletions ~debug ~path ~pos ~currentFile ~forHover:false
55
with
66
| None -> []
7-
| Some (completions, _) -> completions
7+
| Some (completions, _, _) -> completions
88
in
99
print_endline
1010
(completions

analysis/src/Completions.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,4 @@ let getCompletions ~debug ~path ~pos ~currentFile ~forHover =
1919
|> CompletionBackEnd.processCompletable ~debug ~full ~pos ~scope ~env
2020
~forHover
2121
in
22-
Some (completables, full)))
22+
Some (completables, full, scope)))

analysis/src/Hover.ml

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -125,31 +125,44 @@ let getHoverViaCompletions ~debug ~path ~pos ~currentFile ~forHover
125125
~supportsMarkdownLinks =
126126
match Completions.getCompletions ~debug ~path ~pos ~currentFile ~forHover with
127127
| None -> None
128-
| Some (completions, {file; package}) -> (
128+
| Some (completions, ({file; package} as full), scope) -> (
129+
let rawOpens = Scope.getRawOpens scope in
130+
let allFiles =
131+
FileSet.union package.projectFiles package.dependenciesFiles
132+
in
129133
match completions with
130134
| {kind = Label typString; docstring} :: _ ->
131135
let parts =
132136
(if typString = "" then [] else [Markdown.codeBlock typString])
133137
@ docstring
134138
in
135139
Some (Protocol.stringifyHover (String.concat "\n\n" parts))
136-
| {kind = Field _; docstring} :: _ -> (
137-
match CompletionBackEnd.completionsGetTypeEnv completions with
140+
| {kind = Field _; env; docstring} :: _ -> (
141+
let opens = CompletionBackEnd.getOpens ~debug ~rawOpens ~package ~env in
142+
match
143+
CompletionBackEnd.completionsGetTypeEnv2 ~debug ~full ~rawOpens ~opens
144+
~allFiles ~pos ~scope completions
145+
with
138146
| Some (typ, _env) ->
139147
let typeString =
140148
hoverWithExpandedTypes ~file ~package ~supportsMarkdownLinks typ
141149
in
142150
let parts = typeString :: docstring in
143151
Some (Protocol.stringifyHover (String.concat "\n\n" parts))
144152
| None -> None)
145-
| _ -> (
146-
match CompletionBackEnd.completionsGetTypeEnv completions with
153+
| {env} :: _ -> (
154+
let opens = CompletionBackEnd.getOpens ~debug ~rawOpens ~package ~env in
155+
match
156+
CompletionBackEnd.completionsGetTypeEnv2 ~debug ~full ~rawOpens ~opens
157+
~allFiles ~pos ~scope completions
158+
with
147159
| Some (typ, _env) ->
148160
let typeString =
149161
hoverWithExpandedTypes ~file ~package ~supportsMarkdownLinks typ
150162
in
151163
Some (Protocol.stringifyHover typeString)
152-
| None -> None))
164+
| None -> None)
165+
| _ -> None)
153166

154167
let newHover ~full:{file; package} ~supportsMarkdownLinks locItem =
155168
match locItem.locType with

analysis/tests/src/Hover.res

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ let arity0a = (. ()) => {
129129
f
130130
}
131131

132-
let arity0b = (. (), . ()) => 3
132+
let arity0b = (. ()) => (. ()) => 3
133133
// ^hov
134134

135135
let arity0c = (. (), ()) => 3
@@ -211,7 +211,6 @@ let usr: useR = {
211211
// let f = usr
212212
// ^hov
213213

214-
215214
module NotShadowed = {
216215
/** Stuff */
217216
let xx_ = 10
@@ -253,3 +252,10 @@ type variant = | /** Cool variant! */ CoolVariant | /** Other cool variant */ Ot
253252

254253
let coolVariant = CoolVariant
255254
// ^hov
255+
256+
// Hover on unsaved
257+
// let fff = "hello"; fff
258+
// ^hov
259+
260+
// switch x { | {someField} => someField }
261+
// ^hov

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1593,6 +1593,7 @@ Raw opens: 2 Shadow.B.place holder ... Shadow.A.place holder
15931593
Resolved opens 2 Completion.res Completion.res
15941594
ContextPath Value[FAO, forAutoObject]
15951595
Path FAO.forAutoObject
1596+
Raw opens: 2 Shadow.B.place holder ... Shadow.A.place holder
15961597
{"contents": {"kind": "markdown", "value": "```rescript\n{\"age\": int, \"forAutoLabel\": FAR.forAutoRecord}\n```"}}
15971598

15981599
Hover src/Completion.res 352:17

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

Lines changed: 30 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -191,25 +191,47 @@ ContextPath Value[usr]
191191
Path usr
192192
{"contents": {"kind": "markdown", "value": "```rescript\nuseR\n```\n\n---\n\n```\n \n```\n```rescript\ntype useR = {x: int, y: list<option<r<float>>>}\n```\nGo to: [Type definition](command:rescript-vscode.go_to_location?%5B%22Hover.res%22%2C200%2C0%5D)\n\n\n---\n\n```\n \n```\n```rescript\ntype r<'a> = {i: 'a, f: float}\n```\nGo to: [Type definition](command:rescript-vscode.go_to_location?%5B%22Hover.res%22%2C101%2C0%5D)\n"}}
193193

194-
Hover src/Hover.res 230:20
194+
Hover src/Hover.res 229:20
195195
{"contents": {"kind": "markdown", "value": "```rescript\nint\n```\n\n More Stuff "}}
196196

197-
Hover src/Hover.res 233:17
197+
Hover src/Hover.res 232:17
198198
{"contents": {"kind": "markdown", "value": "```rescript\nint\n```\n\n More Stuff "}}
199199

200-
Hover src/Hover.res 245:6
200+
Hover src/Hover.res 244:6
201201
Nothing at that position. Now trying to use completion.
202-
posCursor:[245:6] posNoWhite:[245:5] Found expr:[245:3->245:14]
203-
Pexp_field [245:3->245:4] someField:[245:5->245:14]
202+
posCursor:[244:6] posNoWhite:[244:5] Found expr:[244:3->244:14]
203+
Pexp_field [244:3->244:4] someField:[244:5->244:14]
204204
Completable: Cpath Value[x].someField
205205
ContextPath Value[x].someField
206206
ContextPath Value[x]
207207
Path x
208208
{"contents": {"kind": "markdown", "value": "```rescript\nbool\n```\n\n Mighty fine field here. "}}
209209

210-
Hover src/Hover.res 248:19
210+
Hover src/Hover.res 247:19
211211
{"contents": {"kind": "markdown", "value": "```rescript\nbool\n```\n\n Mighty fine field here. "}}
212212

213-
Hover src/Hover.res 253:20
214-
{"contents": {"kind": "markdown", "value": "```rescript\nCoolVariant\n```\n\n Cool variant! \n\n```rescript\nvariant\n```\n\n---\n\n```\n \n```\n```rescript\ntype variant = CoolVariant | OtherCoolVariant\n```\nGo to: [Type definition](command:rescript-vscode.go_to_location?%5B%22Hover.res%22%2C251%2C0%5D)\n"}}
213+
Hover src/Hover.res 252:20
214+
{"contents": {"kind": "markdown", "value": "```rescript\nCoolVariant\n```\n\n Cool variant! \n\n```rescript\nvariant\n```\n\n---\n\n```\n \n```\n```rescript\ntype variant = CoolVariant | OtherCoolVariant\n```\nGo to: [Type definition](command:rescript-vscode.go_to_location?%5B%22Hover.res%22%2C250%2C0%5D)\n"}}
215+
216+
Hover src/Hover.res 256:23
217+
Nothing at that position. Now trying to use completion.
218+
posCursor:[256:23] posNoWhite:[256:22] Found expr:[256:22->256:25]
219+
Pexp_ident fff:[256:22->256:25]
220+
Completable: Cpath Value[fff]
221+
ContextPath Value[fff]
222+
Path fff
223+
ContextPath string
224+
{"contents": {"kind": "markdown", "value": "```rescript\nstring\n```"}}
225+
226+
Hover src/Hover.res 259:33
227+
Nothing at that position. Now trying to use completion.
228+
posCursor:[259:33] posNoWhite:[259:32] Found expr:[259:31->259:40]
229+
Pexp_ident someField:[259:31->259:40]
230+
Completable: Cpath Value[someField]
231+
ContextPath Value[someField]
232+
Path someField
233+
ContextPath CPatternPath(Value[x])->recordField(someField)
234+
ContextPath Value[x]
235+
Path x
236+
{"contents": {"kind": "markdown", "value": "```rescript\nbool\n```"}}
215237

0 commit comments

Comments
 (0)