Skip to content

Add determinism to processing of files. #264

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 5, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions analysis/src/NewCompletions.ml
Original file line number Diff line number Diff line change
Expand Up @@ -773,7 +773,7 @@ let getItems ~full ~package ~rawOpens ~allFiles ~pos ~parts =
in
(* TODO complete the namespaced name too *)
let localModuleNames =
allFiles
allFiles |> FileSet.elements
|> Utils.filterMap (fun name ->
if Utils.startsWith name suffix && not (String.contains name '-')
then Some {(emptyDeclared name) with item = FileModule name}
Expand Down Expand Up @@ -1148,7 +1148,9 @@ let computeCompletions ~uri ~textOpt ~pos =
| Some full ->
let rawOpens = PartialParser.findOpens text offset in
let package = full.package in
let allFiles = package.projectFiles @ package.dependenciesFiles in
let allFiles =
FileSet.union package.projectFiles package.dependenciesFiles
in
let findItems ~exact parts =
let items =
getItems ~full ~package ~rawOpens ~allFiles ~pos ~parts
Expand Down
8 changes: 6 additions & 2 deletions analysis/src/Packages.ml
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,12 @@ let newBsPackage rootPath =
Log.log ("Opens from bsconfig: " ^ (opens |> String.concat " "));
{
SharedTypes.rootPath;
projectFiles = projectFilesAndPaths |> List.map fst;
dependenciesFiles = dependenciesFilesAndPaths |> List.map fst;
projectFiles =
projectFilesAndPaths |> List.map fst
|> SharedTypes.FileSet.of_list;
dependenciesFiles =
dependenciesFilesAndPaths |> List.map fst
|> SharedTypes.FileSet.of_list;
pathsForModule;
opens;
namespace;
Expand Down
12 changes: 6 additions & 6 deletions analysis/src/ProcessCmt.ml
Original file line number Diff line number Diff line change
Expand Up @@ -734,12 +734,12 @@ struct
else []))

let addFileReference moduleName loc =
Hashtbl.replace extra.fileReferences moduleName
(loc
::
(if Hashtbl.mem extra.fileReferences moduleName then
Hashtbl.find extra.fileReferences moduleName
else []))
let newLocs =
match Hashtbl.find_opt extra.fileReferences moduleName with
| Some oldLocs -> LocationSet.add loc oldLocs
| None -> LocationSet.singleton loc
in
Hashtbl.replace extra.fileReferences moduleName newLocs

let env = QueryEnv.fromFile Collector.file

Expand Down
6 changes: 3 additions & 3 deletions analysis/src/References.ml
Original file line number Diff line number Diff line change
Expand Up @@ -426,7 +426,7 @@ let forLocalStamp ~full:{file; extra; package} stamp tip =
maybeLog ("Now checking path " ^ pathToString path);
let thisModuleName = file.moduleName in
let externals =
package.projectFiles
package.projectFiles |> FileSet.elements
|> List.filter (fun name -> name <> file.moduleName)
|> Utils.filterMap (fun name ->
match ProcessCmt.fileForModule ~package name with
Expand Down Expand Up @@ -460,7 +460,7 @@ let allReferencesForLocItem ~full:({file; package} as full) locItem =
match locItem.locType with
| TopLevelModule moduleName ->
let otherModulesReferences =
package.projectFiles
package.projectFiles |> FileSet.elements
|> Utils.filterMap (fun name ->
match ProcessCmt.fileForModule ~package name with
| None -> None
Expand All @@ -469,7 +469,7 @@ let allReferencesForLocItem ~full:({file; package} as full) locItem =
match Hashtbl.find_opt full.extra.fileReferences moduleName with
| None -> []
| Some locs ->
locs
locs |> LocationSet.elements
|> List.map (fun loc ->
(Uri2.fromPath loc.Location.loc_start.pos_fname, [loc])))
|> List.flatten
Expand Down
14 changes: 11 additions & 3 deletions analysis/src/SharedTypes.ml
Original file line number Diff line number Diff line change
Expand Up @@ -200,10 +200,16 @@ type openTracker = {
mutable used : (path * tip * Location.t) list;
}

module LocationSet = Set.Make (struct
include Location

let compare loc1 loc2 = compare loc2 loc1 (* polymorphic compare should be OK *)
end)

type extra = {
internalReferences : (int, Location.t list) Hashtbl.t;
externalReferences : (string, (path * tip * Location.t) list) Hashtbl.t;
fileReferences : (string, Location.t list) Hashtbl.t;
fileReferences : (string, LocationSet.t) Hashtbl.t;
mutable locItems : locItem list;
(* This is the "open location", like the location...
or maybe the >> location of the open ident maybe *)
Expand All @@ -213,10 +219,12 @@ type extra = {

type file = string

module FileSet = Set.Make (String)

type package = {
rootPath : filePath;
projectFiles : file list;
dependenciesFiles : file list;
projectFiles : FileSet.t;
dependenciesFiles : FileSet.t;
pathsForModule : (file, paths) Hashtbl.t;
namespace : string option;
opens : string list;
Expand Down