Skip to content

Commit 1518f6d

Browse files
committed
Store included values in separate table
1 parent 0359c7f commit 1518f6d

File tree

2 files changed

+36
-36
lines changed

2 files changed

+36
-36
lines changed

analysis/src/CompletionBackEnd.ml

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -454,28 +454,26 @@ let processLocalModule name loc ~prefix ~exact ~env
454454
let processLocalInclude includePath _loc ~prefix ~exact ~(env : QueryEnv.t)
455455
~(localTables : LocalTables.t) =
456456
(* process only values for now *)
457-
localTables.valueTable
458-
|> Hashtbl.iter (fun (name, _) (declared : Types.type_expr Declared.t) ->
457+
localTables.includedValueTable
458+
|> Hashtbl.iter
459+
(fun (name, _) (declared : (string * Types.type_expr) Declared.t) ->
459460
(* We check all the values if their origin is the same as the include path. *)
460-
match declared.modulePath with
461-
| ModulePath.IncludedModule (source, _) ->
462-
let source_module_path = Path.name source in
463-
if String.ends_with ~suffix:includePath source_module_path then
464-
(* If this is the case we perform a similar check for the prefix *)
465-
if Utils.checkName name ~prefix ~exact then
466-
if not (Hashtbl.mem localTables.namesUsed name) then (
467-
Hashtbl.add localTables.namesUsed name ();
468-
localTables.resultRev <-
469-
{
470-
(Completion.create declared.name.txt ~env
471-
~kind:(Value declared.item))
472-
with
473-
deprecated = declared.deprecated;
474-
docstring = declared.docstring;
475-
synthetic = true;
476-
}
477-
:: localTables.resultRev)
478-
| _ -> ())
461+
let source_module_path = fst declared.item in
462+
if String.ends_with ~suffix:includePath source_module_path then
463+
(* If this is the case we perform a similar check for the prefix *)
464+
if Utils.checkName name ~prefix ~exact then
465+
if not (Hashtbl.mem localTables.namesUsed name) then (
466+
Hashtbl.add localTables.namesUsed name ();
467+
localTables.resultRev <-
468+
{
469+
(Completion.create declared.name.txt ~env
470+
~kind:(Value (snd declared.item)))
471+
with
472+
deprecated = declared.deprecated;
473+
docstring = declared.docstring;
474+
synthetic = true;
475+
}
476+
:: localTables.resultRev))
479477

480478
let getItemsFromOpens ~opens ~localTables ~prefix ~exact ~completionContext =
481479
opens
@@ -491,6 +489,7 @@ let getItemsFromOpens ~opens ~localTables ~prefix ~exact ~completionContext =
491489
let findLocalCompletionsForValuesAndConstructors ~(localTables : LocalTables.t)
492490
~env ~prefix ~exact ~opens ~scope =
493491
localTables |> LocalTables.populateValues ~env;
492+
localTables |> LocalTables.populateIncludedValues ~env;
494493
localTables |> LocalTables.populateConstructors ~env;
495494
localTables |> LocalTables.populateModules ~env;
496495

@@ -527,6 +526,7 @@ let findLocalCompletionsForValuesAndConstructors ~(localTables : LocalTables.t)
527526
let findLocalCompletionsForValues ~(localTables : LocalTables.t) ~env ~prefix
528527
~exact ~opens ~scope =
529528
localTables |> LocalTables.populateValues ~env;
529+
localTables |> LocalTables.populateIncludedValues ~env;
530530
localTables |> LocalTables.populateModules ~env;
531531
scope
532532
|> Scope.iterValuesBeforeFirstOpen

analysis/src/LocalTables.ml

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ type t = {
1010
modulesTable: Module.t table;
1111
typesTable: Type.t table;
1212
valueTable: Types.type_expr table;
13+
includedValueTable: (string * Types.type_expr) table;
1314
}
1415

1516
let create () =
@@ -20,28 +21,27 @@ let create () =
2021
modulesTable = Hashtbl.create 1;
2122
typesTable = Hashtbl.create 1;
2223
valueTable = Hashtbl.create 1;
24+
includedValueTable = Hashtbl.create 1;
2325
}
2426

2527
let populateValues ~env localTables =
28+
env.QueryEnv.file.stamps
29+
|> Stamps.iterValues (fun _ declared ->
30+
Hashtbl.replace localTables.valueTable
31+
(declared.name.txt, declared.name.loc |> Loc.start)
32+
declared)
33+
34+
let populateIncludedValues ~env localTables =
2635
env.QueryEnv.file.stamps
2736
|> Stamps.iterValues (fun _ declared ->
2837
match declared.modulePath with
29-
| ModulePath.ExportedModule _ -> (
30-
match
31-
Hashtbl.find_opt localTables.valueTable
32-
(declared.name.txt, declared.name.loc |> Loc.start)
33-
with
34-
| Some {modulePath = ModulePath.IncludedModule _} ->
35-
(* Don't override an included module declared item with an Exported one *)
36-
()
37-
| _ ->
38-
Hashtbl.replace localTables.valueTable
39-
(declared.name.txt, declared.name.loc |> Loc.start)
40-
declared)
41-
| _ ->
42-
Hashtbl.replace localTables.valueTable
38+
| ModulePath.IncludedModule (source, _) ->
39+
let path = Path.name source in
40+
let declared = {declared with item = (path, declared.item)} in
41+
Hashtbl.replace localTables.includedValueTable
4342
(declared.name.txt, declared.name.loc |> Loc.start)
44-
declared)
43+
declared
44+
| _ -> ())
4545

4646
let populateConstructors ~env localTables =
4747
env.QueryEnv.file.stamps

0 commit comments

Comments
 (0)