Skip to content
This repository was archived by the owner on Apr 24, 2021. It is now read-only.

Convert files back to ml #100

Merged
merged 31 commits into from
Apr 8, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
5be6ebb
Convert BuildSystem to ml
chenglou Apr 8, 2021
233bc36
Convert EditorSupportCommands to ml
chenglou Apr 8, 2021
46aa60d
Convert Files to ml
chenglou Apr 8, 2021
20f3475
Convert FindFiles to ml
chenglou Apr 8, 2021
cb23f29
Convert Infix to ml
chenglou Apr 8, 2021
3474505
Convert NewCompletions to ml
chenglou Apr 8, 2021
2b14ff1
Convert Packages to ml
chenglou Apr 8, 2021
f906698
Convert ProcessExtra to ml
chenglou Apr 8, 2021
8ae1ad6
Convert References to ml
chenglou Apr 8, 2021
5cdf2a6
Convert Shared to ml
chenglou Apr 8, 2021
950f1c6
Convert SharedTypes to ml
chenglou Apr 8, 2021
739d82b
Convert Utils to ml
chenglou Apr 8, 2021
5e656e5
Convert ModuleResolution to ml
chenglou Apr 8, 2021
f596c0c
Convert MerlinFile to ml
chenglou Apr 8, 2021
58e3bac
Convert Process_406 to ml
chenglou Apr 8, 2021
1c7327c
Convert RescriptEditorSupport to ml
chenglou Apr 8, 2021
7f4e7f4
Convert Uri2 to ml
chenglou Apr 8, 2021
5033739
Convert Hover to ml
chenglou Apr 8, 2021
2e3b59c
Convert JsonShort to ml
chenglou Apr 8, 2021
af352e0
Convert Log to ml
chenglou Apr 8, 2021
30de05d
Convert MarkdownOfOcamldoc to ml
chenglou Apr 8, 2021
51308e5
Convert PartialParser to ml
chenglou Apr 8, 2021
167b366
Convert PrepareUtil to ml
chenglou Apr 8, 2021
b87fa68
Convert PrintType to ml
chenglou Apr 8, 2021
3ff5826
Convert ProcessAttributes to ml
chenglou Apr 8, 2021
0dcf1e8
Convert ProcessCmt to ml
chenglou Apr 8, 2021
cad8284
Convert Protocol to ml
chenglou Apr 8, 2021
51796e4
Convert Query to ml
chenglou Apr 8, 2021
2b8946a
Convert RResult to ml
chenglou Apr 8, 2021
2bcf01f
Convert State to ml
chenglou Apr 8, 2021
51c5069
Convert TopTypes to ml
chenglou Apr 8, 2021
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
29 changes: 29 additions & 0 deletions src/BuildSystem.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
let namespacedName namespace name =
match namespace with
| None -> name
| Some namespace -> name ^ "-" ^ namespace

open Infix

let getBsPlatformDir rootPath =
let result =
ModuleResolution.resolveNodeModulePath ~startPath:rootPath "bs-platform"
in
let result =
if result = None then
ModuleResolution.resolveNodeModulePath ~startPath:rootPath "rescript"
else result
in
match result with
| Some path -> Ok path
| None ->
let message = "bs-platform could not be found" in
Log.log message;
Error message

let getCompiledBase root = Files.ifExists (root /+ "lib" /+ "bs")

let getStdlib base =
match getBsPlatformDir base with
| Error e -> Error e
| Ok bsPlatformDir -> Ok (bsPlatformDir /+ "lib" /+ "ocaml")
37 changes: 0 additions & 37 deletions src/BuildSystem.re

This file was deleted.

136 changes: 136 additions & 0 deletions src/EditorSupportCommands.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
module J = JsonShort

let dumpLocations state ~package ~file ~extra ~selectPos uri =
let locations =
extra.SharedTypes.locations
|> List.filter (fun (l, _) -> not l.Location.loc_ghost)
in
let locations =
match selectPos with
| Some pos -> (
let pos = Utils.cmtLocFromVscode pos in
match References.locForPos ~extra:{extra with locations} pos with
| None -> []
| Some l -> [l] )
| None -> locations
in
let dedupTable = Hashtbl.create 1 in
let dedupHover hover i =
let isCandidate = String.length hover > 10 in
if isCandidate then (
match Hashtbl.find_opt dedupTable hover with
| Some n -> J.s ("#" ^ string_of_int n)
| None ->
Hashtbl.replace dedupTable hover i;
J.s hover )
else J.s hover
in
let locationsInfo =
locations
|> Utils.filterMapIndex (fun i ((location : Location.t), loc) ->
let locIsModule =
match loc with
| SharedTypes.LModule _ | TopLevelModule _ -> true
| TypeDefinition _ | Typed _ | Constant _ | Explanation _ -> false
in
let hoverText =
Hover.newHover ~file
~getModule:(State.fileForModule state ~package)
loc
in
let hover =
match hoverText with
| None -> []
| Some s -> [("hover", dedupHover s i)]
in
let uriLocOpt =
References.definitionForLoc ~pathsForModule:package.pathsForModule
~file ~getUri:(State.fileForUri state)
~getModule:(State.fileForModule state ~package)
loc
in
let def, skipZero =
match uriLocOpt with
| None -> ([], false)
| Some (uri2, loc) ->
let uriIsCurrentFile = uri = uri2 in
let posIsZero {Lexing.pos_lnum; pos_bol; pos_cnum} =
pos_lnum = 1 && pos_cnum - pos_bol = 0
in
(* Skip if range is all zero, unless it's a module *)
let skipZero =
(not locIsModule) && loc.loc_start |> posIsZero
&& loc.loc_end |> posIsZero
in
let range = ("range", Protocol.rangeOfLoc loc) in
(
[
("definition",
J.o
(match uriIsCurrentFile with
| true -> [range]
| false -> [("uri", Json.String (Uri2.toString uri2)); range])
)
],
skipZero
)
in
let skip = skipZero || (hover = [] && def = []) in
match skip with
| true -> None
| false -> Some (J.o ([("range", Protocol.rangeOfLoc location)] @ hover @ def)))
|> J.l
in
Json.stringify locationsInfo

(* Split (line,char) from filepath:line:char *)
let splitLineChar pathWithPos =
let mkPos line char = Some (line |> int_of_string, char |> int_of_string) in
match pathWithPos |> String.split_on_char ':' with
| [filePath; line; char] -> (filePath, mkPos line char)
| [drive; rest; line; char] ->
(* c:\... on Windows *)
(drive ^ ":" ^ rest, mkPos line char)
| _ -> (pathWithPos, None)

let dump files =
Shared.cacheTypeToString := true;
let state = TopTypes.empty () in
files
|> List.iter (fun pathWithPos ->
let filePath, selectPos = pathWithPos |> splitLineChar in
let filePath = Files.maybeConcat (Unix.getcwd ()) filePath in
let uri = Uri2.fromPath filePath in
let result =
match State.getFullFromCmt ~state ~uri with
| Error message ->
prerr_endline message;
"[]"
| Ok (package, {file; extra}) ->
dumpLocations state ~package ~file ~extra ~selectPos uri
in
print_endline result)

let autocomplete ~currentFile ~full ~package ~pos ~state =
let maybeText = Files.readFile currentFile in
let completions =
NewCompletions.computeCompletions ~full ~maybeText ~package ~pos ~state
in
Json.stringify completions

let complete ~pathWithPos ~currentFile =
let state = TopTypes.empty () in
match pathWithPos |> splitLineChar with
| filePath, Some pos ->
let filePath = Files.maybeConcat (Unix.getcwd ()) filePath in
let uri = Uri2.fromPath filePath in
let result =
match State.getFullFromCmt ~state ~uri with
| Error message ->
prerr_endline message;
"[]"
| Ok (package, full) ->
autocomplete ~currentFile ~full ~package ~pos ~state
in
print_endline result
| _ -> ()
171 changes: 0 additions & 171 deletions src/EditorSupportCommands.re

This file was deleted.

Loading