Skip to content

Commit defb77c

Browse files
committed
properly qualify completion items
1 parent 5835ab7 commit defb77c

File tree

2 files changed

+45
-27
lines changed

2 files changed

+45
-27
lines changed

analysis/src/CompletionBackEnd.ml

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1292,7 +1292,7 @@ let rec getCompletionsForContextPath ~package ~opens ~rawOpens ~allFiles ~pos
12921292
~env ~exact:true ~scope
12931293
|> completionsGetTypeEnv
12941294
with
1295-
| Some (typ, env, completionItemModulePath) -> (
1295+
| Some (typ, _envFromCompletion, completionItemModulePath) -> (
12961296
let {
12971297
arrayModulePath;
12981298
optionModulePath;
@@ -1386,6 +1386,24 @@ let rec getCompletionsForContextPath ~package ~opens ~rawOpens ~allFiles ~pos
13861386
(* Restore original env for the completion after x->foo()... *);
13871387
})
13881388
| [] ->
1389+
(* Module paths coming directly from a completion item is prefixed with
1390+
file module name it was found in. We pluck that off here if the env
1391+
we're in is the same as the completion item was found in. This ensures
1392+
that a correct qualified path can be produced. *)
1393+
let modulePath =
1394+
match completionItemModulePath with
1395+
| topModule :: rest when topModule = env.file.moduleName -> rest
1396+
| modulePath -> modulePath
1397+
in
1398+
let modulePathMinusOpens =
1399+
modulePath
1400+
|> removeRawOpens package.opens
1401+
|> removeRawOpens rawOpens |> String.concat "."
1402+
in
1403+
let completionName name =
1404+
if modulePathMinusOpens = "" then name
1405+
else modulePathMinusOpens ^ "." ^ name
1406+
in
13891407
let completions =
13901408
completionItemModulePath @ [funNamePrefix]
13911409
|> getCompletionsForPath ~completionContext:Value ~exact:false
@@ -1395,7 +1413,7 @@ let rec getCompletionsForContextPath ~package ~opens ~rawOpens ~allFiles ~pos
13951413
|> List.map (fun (completion : Completion.t) ->
13961414
{
13971415
completion with
1398-
name = completion.name;
1416+
name = completionName completion.name;
13991417
env
14001418
(* Restore original env for the completion after x->foo()... *);
14011419
}))

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

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -48,25 +48,25 @@ Complete src/CompletionPipeChain.res 33:38
4848
posCursor:[33:38] posNoWhite:[33:37] Found expr:[33:11->0:-1]
4949
Completable: Cpath Value[Integer, increment](Nolabel, Nolabel)->
5050
[{
51-
"label": "toInt",
51+
"label": "Integer.toInt",
5252
"kind": 12,
5353
"tags": [],
5454
"detail": "t => int",
5555
"documentation": null
5656
}, {
57-
"label": "increment",
57+
"label": "Integer.increment",
5858
"kind": 12,
5959
"tags": [],
6060
"detail": "(t, int) => t",
6161
"documentation": null
6262
}, {
63-
"label": "decrement",
63+
"label": "Integer.decrement",
6464
"kind": 12,
6565
"tags": [],
6666
"detail": "(t, int => int) => t",
6767
"documentation": null
6868
}, {
69-
"label": "make",
69+
"label": "Integer.make",
7070
"kind": 12,
7171
"tags": [],
7272
"detail": "int => t",
@@ -77,25 +77,25 @@ Complete src/CompletionPipeChain.res 36:38
7777
posCursor:[36:38] posNoWhite:[36:37] Found expr:[36:11->0:-1]
7878
Completable: Cpath Value[Integer, increment](Nolabel, Nolabel)->
7979
[{
80-
"label": "toInt",
80+
"label": "Integer.toInt",
8181
"kind": 12,
8282
"tags": [],
8383
"detail": "t => int",
8484
"documentation": null
8585
}, {
86-
"label": "increment",
86+
"label": "Integer.increment",
8787
"kind": 12,
8888
"tags": [],
8989
"detail": "(t, int) => t",
9090
"documentation": null
9191
}, {
92-
"label": "decrement",
92+
"label": "Integer.decrement",
9393
"kind": 12,
9494
"tags": [],
9595
"detail": "(t, int => int) => t",
9696
"documentation": null
9797
}, {
98-
"label": "make",
98+
"label": "Integer.make",
9999
"kind": 12,
100100
"tags": [],
101101
"detail": "int => t",
@@ -106,25 +106,25 @@ Complete src/CompletionPipeChain.res 39:47
106106
posCursor:[39:47] posNoWhite:[39:46] Found expr:[39:11->0:-1]
107107
Completable: Cpath Value[Integer, decrement](Nolabel, Nolabel)->
108108
[{
109-
"label": "toInt",
109+
"label": "Integer.toInt",
110110
"kind": 12,
111111
"tags": [],
112112
"detail": "t => int",
113113
"documentation": null
114114
}, {
115-
"label": "increment",
115+
"label": "Integer.increment",
116116
"kind": 12,
117117
"tags": [],
118118
"detail": "(t, int) => t",
119119
"documentation": null
120120
}, {
121-
"label": "decrement",
121+
"label": "Integer.decrement",
122122
"kind": 12,
123123
"tags": [],
124124
"detail": "(t, int => int) => t",
125125
"documentation": null
126126
}, {
127-
"label": "make",
127+
"label": "Integer.make",
128128
"kind": 12,
129129
"tags": [],
130130
"detail": "int => t",
@@ -135,25 +135,25 @@ Complete src/CompletionPipeChain.res 42:69
135135
posCursor:[42:69] posNoWhite:[42:68] Found expr:[42:11->0:-1]
136136
Completable: Cpath Value[Integer, decrement](Nolabel, Nolabel)->
137137
[{
138-
"label": "toInt",
138+
"label": "Integer.toInt",
139139
"kind": 12,
140140
"tags": [],
141141
"detail": "t => int",
142142
"documentation": null
143143
}, {
144-
"label": "increment",
144+
"label": "Integer.increment",
145145
"kind": 12,
146146
"tags": [],
147147
"detail": "(t, int) => t",
148148
"documentation": null
149149
}, {
150-
"label": "decrement",
150+
"label": "Integer.decrement",
151151
"kind": 12,
152152
"tags": [],
153153
"detail": "(t, int => int) => t",
154154
"documentation": null
155155
}, {
156-
"label": "make",
156+
"label": "Integer.make",
157157
"kind": 12,
158158
"tags": [],
159159
"detail": "int => t",
@@ -164,13 +164,13 @@ Complete src/CompletionPipeChain.res 45:62
164164
posCursor:[45:62] posNoWhite:[45:61] Found expr:[45:11->0:-1]
165165
Completable: Cpath Value[SuperFloat, fromInteger](Nolabel)->
166166
[{
167-
"label": "fromInteger",
167+
"label": "SuperFloat.fromInteger",
168168
"kind": 12,
169169
"tags": [],
170170
"detail": "Integer.t => t",
171171
"documentation": null
172172
}, {
173-
"label": "toInteger",
173+
"label": "SuperFloat.toInteger",
174174
"kind": 12,
175175
"tags": [],
176176
"detail": "t => Integer.t",
@@ -181,7 +181,7 @@ Complete src/CompletionPipeChain.res 48:63
181181
posCursor:[48:63] posNoWhite:[48:62] Found expr:[48:11->48:63]
182182
Completable: Cpath Value[SuperFloat, fromInteger](Nolabel)->t
183183
[{
184-
"label": "toInteger",
184+
"label": "SuperFloat.toInteger",
185185
"kind": 12,
186186
"tags": [],
187187
"detail": "t => Integer.t",
@@ -192,19 +192,19 @@ Complete src/CompletionPipeChain.res 51:82
192192
posCursor:[51:82] posNoWhite:[51:81] Found expr:[51:11->0:-1]
193193
Completable: Cpath Value[CompletionSupport, Test, make](Nolabel)->
194194
[{
195-
"label": "add",
195+
"label": "CompletionSupport.Test.add",
196196
"kind": 12,
197197
"tags": [],
198198
"detail": "t => int",
199199
"documentation": null
200200
}, {
201-
"label": "addSelf",
201+
"label": "CompletionSupport.Test.addSelf",
202202
"kind": 12,
203203
"tags": [],
204204
"detail": "t => t",
205205
"documentation": null
206206
}, {
207-
"label": "make",
207+
"label": "CompletionSupport.Test.make",
208208
"kind": 12,
209209
"tags": [],
210210
"detail": "int => t",
@@ -215,19 +215,19 @@ Complete src/CompletionPipeChain.res 54:78
215215
posCursor:[54:78] posNoWhite:[54:77] Found expr:[54:11->0:-1]
216216
Completable: Cpath Value[CompletionSupport, Test, addSelf](Nolabel, Nolabel)->
217217
[{
218-
"label": "add",
218+
"label": "CompletionSupport.Test.add",
219219
"kind": 12,
220220
"tags": [],
221221
"detail": "t => int",
222222
"documentation": null
223223
}, {
224-
"label": "addSelf",
224+
"label": "CompletionSupport.Test.addSelf",
225225
"kind": 12,
226226
"tags": [],
227227
"detail": "t => t",
228228
"documentation": null
229229
}, {
230-
"label": "make",
230+
"label": "CompletionSupport.Test.make",
231231
"kind": 12,
232232
"tags": [],
233233
"detail": "int => t",

0 commit comments

Comments
 (0)