Skip to content
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

Cleanup path #207

Merged
merged 2 commits into from
Apr 30, 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
4 changes: 2 additions & 2 deletions analysis/.depend
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ src/FindFiles.cmx : src/Utils.cmx src/SharedTypes.cmx \
src/Files.cmx src/BuildSystem.cmx
src/Hover.cmx : src/Utils.cmx src/SharedTypes.cmx src/Shared.cmx \
src/References.cmx src/ProcessCmt.cmx
src/Infix.cmx : src/Log.cmx src/Files.cmx
src/Infix.cmx : src/Log.cmx
src/Log.cmx :
src/ModuleResolution.cmx : src/Infix.cmx src/Files.cmx
src/NewCompletions.cmx : src/Utils.cmx src/Uri2.cmx src/SharedTypes.cmx \
Expand All @@ -33,7 +33,7 @@ src/References.cmx : src/Utils.cmx src/Uri2.cmx src/SharedTypes.cmx \
src/Shared.cmx : src/PrintType.cmx src/Files.cmx
src/SharedTypes.cmx : src/Utils.cmx src/Uri2.cmx src/Shared.cmx \
src/Infix.cmx
src/Uri2.cmx : src/Files.cmx
src/Uri2.cmx :
src/Utils.cmx : src/Protocol.cmx
src/vendor/Json.cmx :
src/vendor/res_outcome_printer/res_comment.cmx : \
Expand Down
12 changes: 6 additions & 6 deletions analysis/src/Commands.ml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ let dump files =
Shared.cacheTypeToString := true;
files
|> List.iter (fun path ->
let uri = Uri2.fromLocalPath path in
let uri = Uri2.fromPath path in
let result =
match ProcessCmt.getFullFromCmt ~uri with
| None -> "[]"
Expand All @@ -30,7 +30,7 @@ let dump files =
print_endline result)

let completion ~path ~line ~col ~currentFile =
let uri = Uri2.fromLocalPath path in
let uri = Uri2.fromPath path in
let result =
match ProcessCmt.getFullFromCmt ~uri with
| None -> "[]"
Expand All @@ -43,7 +43,7 @@ let completion ~path ~line ~col ~currentFile =
print_endline result

let hover ~path ~line ~col =
let uri = Uri2.fromLocalPath path in
let uri = Uri2.fromPath path in
let result =
match ProcessCmt.getFullFromCmt ~uri with
| None -> Protocol.null
Expand Down Expand Up @@ -79,7 +79,7 @@ let hover ~path ~line ~col =
print_endline result

let definition ~path ~line ~col =
let uri = Uri2.fromLocalPath path in
let uri = Uri2.fromPath path in
let result =
match ProcessCmt.getFullFromCmt ~uri with
| None -> Protocol.null
Expand Down Expand Up @@ -114,7 +114,7 @@ let definition ~path ~line ~col =
print_endline result

let references ~path ~line ~col =
let uri = Uri2.fromLocalPath path in
let uri = Uri2.fromPath path in
let result =
match ProcessCmt.getFullFromCmt ~uri with
| None -> Protocol.null
Expand Down Expand Up @@ -143,7 +143,7 @@ let references ~path ~line ~col =
print_endline result

let documentSymbol ~path =
let uri = Uri2.fromLocalPath path in
let uri = Uri2.fromPath path in
match ProcessCmt.getFullFromCmt ~uri with
| None -> print_endline Protocol.null
| Some {file} ->
Expand Down
14 changes: 0 additions & 14 deletions analysis/src/Files.ml
Original file line number Diff line number Diff line change
Expand Up @@ -97,17 +97,3 @@ let rec collect ?(checkDir = fun _ -> true) path test =
|> List.concat
else []
| _ -> if test path then [path] else []

let fileConcat a b =
if
b <> ""
&& b.[0] = '.'
&& String.length b >= 2
&& b.[1] = Filename.dir_sep.[0]
then Filename.concat a (String.sub b 2 (String.length b - 2))
else Filename.concat a b

let isFullPath b =
b.[0] = '/' || (Sys.win32 && String.length b > 1 && b.[1] = ':')

let maybeConcat a b = if b <> "" && isFullPath b then b else fileConcat a b
4 changes: 2 additions & 2 deletions analysis/src/FindFiles.ml
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ let collectFiles directory =
let findProjectFiles ~debug namespace root sourceDirectories compiledBase =
let files =
sourceDirectories
|> List.map (Files.fileConcat root)
|> List.map (Filename.concat root)
|> ifDebug debug "Source directories" (String.concat " - ")
|> List.map (fun name -> Files.collect name isSourceFile)
|> List.concat |> Utils.dedup
Expand Down Expand Up @@ -248,7 +248,7 @@ let findDependencyFiles ~debug base config =
| Some compiledBase ->
if debug then Log.log ("Compiled base: " ^ compiledBase);
let compiledDirectories =
directories |> List.map (Files.fileConcat compiledBase)
directories |> List.map (Filename.concat compiledBase)
in
let compiledDirectories =
match namespace with
Expand Down
2 changes: 1 addition & 1 deletion analysis/src/Infix.ml
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,4 @@ let logIfAbsent message x =
None
| _ -> x

let ( /+ ) = Files.fileConcat
let ( /+ ) = Filename.concat
6 changes: 0 additions & 6 deletions analysis/src/Uri2.ml
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
module Uri : sig
type t

val fromLocalPath : string -> t

val fromPath : string -> t

val isInterface : t -> bool
Expand All @@ -28,10 +26,6 @@ end = struct

let fromPath path = {path; uri = pathToUri path}

let fromLocalPath localPath =
let path = Files.maybeConcat (Unix.getcwd ()) localPath in
fromPath path

let isInterface {path} = Filename.check_suffix path "i"

let toPath {path} = path
Expand Down