Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Store included values in separate table
  • Loading branch information
nojaf committed May 29, 2025
commit 1518f6d35781db24f36894e0d461d00b4050b009
42 changes: 21 additions & 21 deletions analysis/src/CompletionBackEnd.ml
Original file line number Diff line number Diff line change
Expand Up @@ -454,28 +454,26 @@ let processLocalModule name loc ~prefix ~exact ~env
let processLocalInclude includePath _loc ~prefix ~exact ~(env : QueryEnv.t)
~(localTables : LocalTables.t) =
(* process only values for now *)
localTables.valueTable
|> Hashtbl.iter (fun (name, _) (declared : Types.type_expr Declared.t) ->
localTables.includedValueTable
|> Hashtbl.iter
(fun (name, _) (declared : (string * Types.type_expr) Declared.t) ->
(* We check all the values if their origin is the same as the include path. *)
match declared.modulePath with
| ModulePath.IncludedModule (source, _) ->
let source_module_path = Path.name source in
if String.ends_with ~suffix:includePath source_module_path then
(* If this is the case we perform a similar check for the prefix *)
if Utils.checkName name ~prefix ~exact then
if not (Hashtbl.mem localTables.namesUsed name) then (
Hashtbl.add localTables.namesUsed name ();
localTables.resultRev <-
{
(Completion.create declared.name.txt ~env
~kind:(Value declared.item))
with
deprecated = declared.deprecated;
docstring = declared.docstring;
synthetic = true;
}
:: localTables.resultRev)
| _ -> ())
let source_module_path = fst declared.item in
if String.ends_with ~suffix:includePath source_module_path then
(* If this is the case we perform a similar check for the prefix *)
if Utils.checkName name ~prefix ~exact then
if not (Hashtbl.mem localTables.namesUsed name) then (
Hashtbl.add localTables.namesUsed name ();
localTables.resultRev <-
{
(Completion.create declared.name.txt ~env
~kind:(Value (snd declared.item)))
with
deprecated = declared.deprecated;
docstring = declared.docstring;
synthetic = true;
}
:: localTables.resultRev))

let getItemsFromOpens ~opens ~localTables ~prefix ~exact ~completionContext =
opens
Expand All @@ -491,6 +489,7 @@ let getItemsFromOpens ~opens ~localTables ~prefix ~exact ~completionContext =
let findLocalCompletionsForValuesAndConstructors ~(localTables : LocalTables.t)
~env ~prefix ~exact ~opens ~scope =
localTables |> LocalTables.populateValues ~env;
localTables |> LocalTables.populateIncludedValues ~env;
localTables |> LocalTables.populateConstructors ~env;
localTables |> LocalTables.populateModules ~env;

Expand Down Expand Up @@ -527,6 +526,7 @@ let findLocalCompletionsForValuesAndConstructors ~(localTables : LocalTables.t)
let findLocalCompletionsForValues ~(localTables : LocalTables.t) ~env ~prefix
~exact ~opens ~scope =
localTables |> LocalTables.populateValues ~env;
localTables |> LocalTables.populateIncludedValues ~env;
localTables |> LocalTables.populateModules ~env;
scope
|> Scope.iterValuesBeforeFirstOpen
Expand Down
30 changes: 15 additions & 15 deletions analysis/src/LocalTables.ml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ type t = {
modulesTable: Module.t table;
typesTable: Type.t table;
valueTable: Types.type_expr table;
includedValueTable: (string * Types.type_expr) table;
}

let create () =
Expand All @@ -20,28 +21,27 @@ let create () =
modulesTable = Hashtbl.create 1;
typesTable = Hashtbl.create 1;
valueTable = Hashtbl.create 1;
includedValueTable = Hashtbl.create 1;
}

let populateValues ~env localTables =
env.QueryEnv.file.stamps
|> Stamps.iterValues (fun _ declared ->
Hashtbl.replace localTables.valueTable
(declared.name.txt, declared.name.loc |> Loc.start)
declared)

let populateIncludedValues ~env localTables =
env.QueryEnv.file.stamps
|> Stamps.iterValues (fun _ declared ->
match declared.modulePath with
| ModulePath.ExportedModule _ -> (
match
Hashtbl.find_opt localTables.valueTable
(declared.name.txt, declared.name.loc |> Loc.start)
with
| Some {modulePath = ModulePath.IncludedModule _} ->
(* Don't override an included module declared item with an Exported one *)
()
| _ ->
Hashtbl.replace localTables.valueTable
(declared.name.txt, declared.name.loc |> Loc.start)
declared)
| _ ->
Hashtbl.replace localTables.valueTable
| ModulePath.IncludedModule (source, _) ->
let path = Path.name source in
let declared = {declared with item = (path, declared.item)} in
Hashtbl.replace localTables.includedValueTable
(declared.name.txt, declared.name.loc |> Loc.start)
declared)
declared
| _ -> ())

let populateConstructors ~env localTables =
env.QueryEnv.file.stamps
Expand Down