Skip to content

Commit

Permalink
add back in the stdlibs
Browse files Browse the repository at this point in the history
  • Loading branch information
jaredly committed Apr 6, 2019
1 parent 7c9848a commit 8d236a8
Show file tree
Hide file tree
Showing 10 changed files with 37 additions and 38 deletions.
8 changes: 0 additions & 8 deletions bin/Diagnose.re

This file was deleted.

8 changes: 0 additions & 8 deletions bin/dune
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,3 @@
(flags :standard -w -9)
(preprocess (pps Belt_ppx Ppx_monads))
)

(executable
(public_name diagnose)
(modules Diagnose)
(libraries Lsp Analyze)
(flags :standard -w -9)
(preprocess (pps Belt_ppx Ppx_monads))
)
21 changes: 10 additions & 11 deletions core/References.re
Original file line number Diff line number Diff line change
Expand Up @@ -272,31 +272,30 @@ let forPos = (~file, ~extra, pos) => {
Some(refs)
};

let validateLoc = (loc: Location.t, backup: Location.t) => {
if (loc.loc_start.pos_cnum == -1) {
if (backup.loc_start.pos_cnum == -1) {
let validateLoc = (loc: Location.t, backup: Location.t) =>
if (loc.loc_start.pos_cnum == (-1)) {
if (backup.loc_start.pos_cnum == (-1)) {
{
Location.loc_ghost: true,
loc_start: {
pos_cnum: 0,
pos_lnum: 1,
pos_bol: 0,
pos_fname: ""
pos_fname: "",
},
loc_end: {
pos_cnum: 0,
pos_lnum: 1,
pos_bol: 0,
pos_fname: ""
pos_fname: "",
},
}
};
} else {
backup
}
backup;
};
} else {
loc
}
};
loc;
};

let resolveModuleDefinition = (~file, ~getModule, stamp) => {
let%opt md = Query.hashFind(file.stamps.modules, stamp);
Expand Down
6 changes: 6 additions & 0 deletions src/analyze/BuildSystem.re
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@ type t =
| Bsb(string)
| BsbNative(string, target);

let usesStdlib = v => switch v {
| V407 => true
| V406 => false
| V402 => false
};


let fromString = string => {
switch (Util.Utils.split_on_char(':', string)) {
Expand Down
12 changes: 7 additions & 5 deletions src/analyze/NewCompletions.re
Original file line number Diff line number Diff line change
Expand Up @@ -458,8 +458,9 @@ TODO filter out things that are defined after the current position
*/

let resolveRawOpens = (~env, ~getModule, ~rawOpens, ~package) => {
let packageOpens = ["Pervasives", ...package.TopTypes.opens];
let resolveRawOpens = (~useStdlib, ~env, ~getModule, ~rawOpens, ~package) => {
// TODO Stdlib instead of Pervasives
let packageOpens = [useStdlib ? "Stdlib" : "Pervasives", ...package.TopTypes.opens];
Log.log("Package opens " ++ String.concat(" ", packageOpens));

let opens =
Expand All @@ -482,6 +483,7 @@ let resolveRawOpens = (~env, ~getModule, ~rawOpens, ~package) => {
/** This function should live somewhere else */
let findDeclaredValue =
(
~useStdlib=false,
~full,
~package,
/* the text that we found e.g. open A.B.C, this is "A.B.C" */
Expand All @@ -492,7 +494,7 @@ let findDeclaredValue =
) => {
let env = Query.fileEnv(full.file);

let opens = resolveRawOpens(~env, ~getModule, ~rawOpens, ~package);
let opens = resolveRawOpens(~useStdlib, ~env, ~getModule, ~rawOpens, ~package);

let path = pathFromTokenParts(tokenParts);

Expand All @@ -504,7 +506,7 @@ let findDeclaredValue =


let get =
(~full, ~package, ~rawOpens, ~getModule, ~allModules, pos, tokenParts) => {
(~useStdlib=false, ~full, ~package, ~rawOpens, ~getModule, ~allModules, pos, tokenParts) => {
Log.log(
"Opens folkz > "
++ string_of_int(List.length(rawOpens))
Expand All @@ -516,7 +518,7 @@ let get =
let packageOpens = ["Pervasives", ...package.TopTypes.opens];
Log.log("Package opens " ++ String.concat(" ", packageOpens));

let opens = resolveRawOpens(~env, ~getModule, ~rawOpens, ~package);
let opens = resolveRawOpens(~useStdlib, ~env, ~getModule, ~rawOpens, ~package);
Log.log(
"Opens nows "
++ string_of_int(List.length(opens))
Expand Down
9 changes: 6 additions & 3 deletions src/analyze/Packages.re
Original file line number Diff line number Diff line change
Expand Up @@ -287,8 +287,13 @@ let newJbuilderPackage = (~overrideBuildSystem=?, ~reportDiagnostics, state, roo
let%try hiddenLocation = BuildSystem.hiddenLocation(projectRoot, buildSystem);
Files.mkdirp(hiddenLocation);

Log.log("Get ocaml stdlib dirs");
let%try stdlibs = BuildSystem.getStdlib(projectRoot, buildSystem);

let%try (pathsForModule, nameForPath, localModules, depsModules, includeDirectories) = if (true) {
let (pathsForModule_, nameForPath, localModules, depsModules, includeDirectories) = MerlinFile.getModulesFromMerlin(rootPath, merlinRaw);
let (pathsForModule_, nameForPath, localModules, depsModules, includeDirectories) = MerlinFile.getModulesFromMerlin(
~stdlibs,
rootPath, merlinRaw);
let pathsForModule = Hashtbl.create(Stdlib.Hashtbl.length(pathsForModule_));
pathsForModule_ |> Hashtbl.iter((k, v) => pathsForModule->Hashtbl.replace(k, pathToPath(v)));
// pathsForModule->Hasthbl.map
Expand All @@ -307,8 +312,6 @@ let newJbuilderPackage = (~overrideBuildSystem=?, ~reportDiagnostics, state, roo
);
Log.log("=== Build dir: " ++ buildDir);

Log.log("Get ocaml stdlib dirs");
let%try stdlibs = BuildSystem.getStdlib(projectRoot, buildSystem);

/* TODO support binaries, and other directories */
let includeSubdirs = JbuildFile.hasIncludeSubdirs(jbuildConfig);
Expand Down
2 changes: 1 addition & 1 deletion src/lsp/Main.re
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ let singleDefinition = (rootPath, filePath, line, col) => {
let uri = Utils.toUri(filePath);
switch (processFile(~state, ~uri)) {
| Some((package, Some({file, extra}))) => {
let res = {
let _ = {
let%opt_consume (location, loc) = References.locForPos(~extra, (line, col - 1)) |> orLog(
Printf.sprintf("Nothing definable found at %s:%d:%d", filePath, line, col)
);
Expand Down
2 changes: 2 additions & 0 deletions src/lsp/MessageHandlers.re
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ let handlers: list((string, (state, Json.t) => result((state, Json.t), string)))
let tokenParts = Utils.split_on_char('.', lident);
let rawOpens = PartialParser.findOpens(text, offset);
let%opt declared = NewCompletions.findDeclaredValue(
~useStdlib=package.compilerVersion->BuildSystem.usesStdlib,
~full,
~package,
~rawOpens,
Expand Down Expand Up @@ -142,6 +143,7 @@ let handlers: list((string, (state, Json.t) => result((state, Json.t), string)))
let%try {SharedTypes.file, extra} = State.getBestDefinitions(uri, state, ~package);
let allModules = package.localModules @ package.dependencyModules;
let items = NewCompletions.get(
~useStdlib=package.compilerVersion->BuildSystem.usesStdlib,
~full={file, extra},
~package,
~rawOpens,
Expand Down
5 changes: 4 additions & 1 deletion util/MerlinFile.re
Original file line number Diff line number Diff line change
Expand Up @@ -126,9 +126,12 @@ let calcPaths = (mname, files) => {
};

/** Returns a `pathsForModule`, `nameForPath`, `localModules` and `dependencyModules` */
let getModulesFromMerlin = (base, text) => {
let getModulesFromMerlin = (~stdlibs, base, text) => {
let (source, build, _flags) = parseMerlin(base, text);

let source = stdlibs @ source;
let build = stdlibs @ build;

let (localSource, depSource) = source->Belt.List.partition(isRelativePath);

maybeLog(Printf.sprintf("Local %d, Deps %d", List.length(localSource), List.length(depSource)));
Expand Down
2 changes: 1 addition & 1 deletion util/MerlinFile.rei
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ let calcPaths:
string,
);
let getModulesFromMerlin:
(string, string) =>
(~stdlibs: list(string), string, string) =>
(
Hashtbl.t(
string,
Expand Down

0 comments on commit 8d236a8

Please sign in to comment.