diff --git a/src/rescript-editor-support/EditorSupportCommands.re b/src/rescript-editor-support/EditorSupportCommands.re index dd6e014f..faeb504e 100644 --- a/src/rescript-editor-support/EditorSupportCommands.re +++ b/src/rescript-editor-support/EditorSupportCommands.re @@ -101,7 +101,7 @@ let dumpLocations = (state, ~package, ~file, ~extra, ~selectPos, uri) => { }) |> l; - print_endline(Json.stringify(locationsInfo)); + Json.stringify(locationsInfo); }; let dump = files => { @@ -129,11 +129,15 @@ let dump = files => { }; let filePath = maybeConcat(Unix.getcwd(), filePath); let uri = Utils.toUri(filePath); - switch (State.getFullFromCmt(uri, state)) { - | Error(message) => print_endline(message) - | Ok((package, {file, extra})) => - dumpLocations(state, ~package, ~file, ~extra, ~selectPos, uri) - }; + let result = + switch (State.getFullFromCmt(uri, state)) { + | Error(message) => + prerr_endline(message); + "[]"; + | Ok((package, {file, extra})) => + dumpLocations(state, ~package, ~file, ~extra, ~selectPos, uri) + }; + print_endline(result); }); }; @@ -222,7 +226,7 @@ let autocomplete = (~currentFile, ~full, ~package, ~pos, ~state) => { }) |> l; - print_endline(Json.stringify(completions)); + Json.stringify(completions); }; let complete = (~pathWithPos, ~currentFile) => { @@ -242,12 +246,16 @@ let complete = (~pathWithPos, ~currentFile) => { let pos = (line |> int_of_string, char |> int_of_string); let filePath = maybeConcat(Unix.getcwd(), filePath); let uri = Utils.toUri(filePath); - switch (State.getFullFromCmt(uri, state)) { - | Error(message) => print_endline(message) - | Ok((package, full)) => - Hashtbl.replace(state.lastDefinitions, uri, full); - autocomplete(~currentFile, ~full, ~package, ~pos, ~state); - }; + let result = + switch (State.getFullFromCmt(uri, state)) { + | Error(message) => + prerr_endline(message); + "[]"; + | Ok((package, full)) => + Hashtbl.replace(state.lastDefinitions, uri, full); + autocomplete(~currentFile, ~full, ~package, ~pos, ~state); + }; + print_endline(result); | _ => () }; }; diff --git a/src/rescript-editor-support/Pretty.ml b/src/rescript-editor-support/Pretty.ml index 6ca8f663..57e62851 100644 --- a/src/rescript-editor-support/Pretty.ml +++ b/src/rescript-editor-support/Pretty.ml @@ -79,12 +79,6 @@ let text ?len string = single_line = true; } -let print_indentation n = - print_char '\n'; - for _ = 1 to n do - print_char ' '; - done - let rec flatten doc = match doc.node with | Append (a, b) -> append (flatten a) (flatten b) @@ -118,8 +112,8 @@ let push offset node (stack: stack) = let print ?width:(width=70) - ?output:(output=print_string) - ?indent:(indent=print_indentation) + ~output + ~indent doc = let rec loop currentIndent stack = match stack with diff --git a/src/rescript-editor-support/Pretty.mli b/src/rescript-editor-support/Pretty.mli index d826eb8a..47e821d2 100644 --- a/src/rescript-editor-support/Pretty.mli +++ b/src/rescript-editor-support/Pretty.mli @@ -51,7 +51,7 @@ val back : int -> string -> doc "indent" function that defines how to print a newline and indent to a desired level. The default arguments print to stdout. *) val print : ?width: int -> - ?output: (string -> unit) -> - ?indent: (int -> unit) -> + output: (string -> unit) -> + indent: (int -> unit) -> doc -> unit diff --git a/src/rescript-editor-support/RescriptEditorSupport.re b/src/rescript-editor-support/RescriptEditorSupport.re index 2c58eaae..07a866fd 100644 --- a/src/rescript-editor-support/RescriptEditorSupport.re +++ b/src/rescript-editor-support/RescriptEditorSupport.re @@ -117,7 +117,7 @@ let tick = state => { let orLog = (message, v) => switch (v) { | None => - print_endline(message); + prerr_endline(message); None; | Some(x) => Some(x) }; @@ -125,170 +125,27 @@ let orLog = (message, v) => let processFile = (~state, ~uri, ~quiet) => { switch (Packages.getPackage(~reportDiagnostics=(_, _) => (), uri, state)) { | Error(message) => - print_endline(" Unable to get package: " ++ uri); - print_endline(message); + prerr_endline(" Unable to get package: " ++ uri); + prerr_endline(message); None; | Ok(package) => switch (State.getCompilationResult(uri, state, ~package)) { | Error(message) => - print_endline(" Invalid compilation result: " ++ message); + prerr_endline(" Invalid compilation result: " ++ message); Some((package, None)); | Ok(Success(_message, contents)) => if (!quiet) { - print_endline(" Good: " ++ uri); + prerr_endline(" Good: " ++ uri); }; Some((package, Some(contents))); | Ok(TypeError(message, _) | SyntaxError(message, _, _)) => - print_endline(" Error compiling: " ++ uri); - print_endline(message); + prerr_endline(" Error compiling: " ++ uri); + prerr_endline(message); Some((package, None)); } }; }; -let singleDefinition = (~quiet, rootPath, filePath, line, col) => { - Log.log( - "# Reason Langauge Server - checking individual files to ensure they load & process correctly", - ); - let rootPath = - rootPath == "." ? Unix.getcwd() : maybeConcat(Unix.getcwd(), rootPath); - let filePath = maybeConcat(Unix.getcwd(), filePath); - let state = { - ...TopTypes.empty(), - rootPath, - rootUri: Utils.toUri(rootPath), - }; - - let uri = Utils.toUri(filePath); - switch (processFile(~state, ~uri, ~quiet)) { - | Some((package, Some({file, extra}))) => - 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, - ), - ); - let%opt_consume (fname, dlocation) = - References.definitionForLoc( - ~pathsForModule=package.pathsForModule, - ~file, - ~getUri=State.fileForUri(state, ~package), - ~getModule=State.fileForModule(state, ~package), - loc, - ) - |> orLog( - Printf.sprintf( - "Unable to resolve a definition for %s:%d:%d", - filePath, - location.loc_start.pos_lnum, - location.loc_start.pos_cnum - location.loc_start.pos_bol + 1, - ), - ); - let%opt_consume fname = Utils.parseUri(fname); - Printf.printf( - "Definition for %s:%d:%d found at %s:%d:%d\n", - filePath, - location.loc_start.pos_lnum, - location.loc_start.pos_cnum - location.loc_start.pos_bol + 1, - fname, - dlocation.loc_start.pos_lnum, - dlocation.loc_start.pos_cnum - dlocation.loc_start.pos_bol + 1, - ); - }; - print_endline(" Good: " ++ uri); - | _ => () - }; -}; - -let check = (~definitions, ~quiet, rootPath, files) => { - Log.log( - "# Reason Langauge Server - checking individual files to ensure they load & process correctly", - ); - let rootPath = - rootPath == "." ? Unix.getcwd() : maybeConcat(Unix.getcwd(), rootPath); - let state = { - ...TopTypes.empty(), - rootPath, - rootUri: Utils.toUri(rootPath), - }; - files - |> List.iter(filePath => { - let filePath = maybeConcat(Unix.getcwd(), filePath); - let uri = Utils.toUri(filePath); - switch (processFile(~state, ~uri, ~quiet)) { - | Some((package, result)) => - if (!definitions) { - Log.log(State.Show.state(state, package)); - } else { - switch (result) { - | None => () - | Some({file, extra}) => - let missing = ref([]); - extra.locations - |> List.iter(((location, loc)) => { - switch (loc) { - | SharedTypes.Typed(_, LocalReference(tag, Type)) - when tag <= 15 => - () - | Typed( - _, - GlobalReference(_, _, Constructor("[]" | "::")), - ) => - () - | Typed( - _, - (LocalReference(_, _) | GlobalReference(_, _, _)) as t, - ) - when !location.Location.loc_ghost => - switch ( - References.definitionForLoc( - ~pathsForModule=package.pathsForModule, - ~file, - ~getUri=State.fileForUri(state, ~package), - ~getModule=State.fileForModule(state, ~package), - loc, - ) - ) { - | None => - // missing := 1 + missing^; - missing := - [ - Printf.sprintf( - " - \"%s:%d:%d\" : %s", - filePath, - location.loc_start.pos_lnum, - location.loc_start.pos_cnum - - location.loc_start.pos_bol - + 1, - SharedTypes.locKindToString(t), - ), - ...missing^, - ] - | Some(_defn) => () - } - | _ => () - } - }); - if (missing^ != []) { - print_endline(filePath); - print_endline( - " > " ++ string_of_int(List.length(missing^)) ++ " missing", - ); - missing^ |> List.iter(text => print_endline(text)); - }; - }; - } - | _ => () - }; - }); - Log.log("Ok"); -}; - let parseArgs = args => { switch (args) { | [] => assert(false) @@ -331,7 +188,7 @@ The dump command can also omit `:line:column`, to show results for every positio |}; let showHelp = () => { - print_endline(help); + prerr_endline(help); }; let main = () => { @@ -353,28 +210,6 @@ let main = () => { ); Log.log("Finished"); Log.out^ |?< close_out; - | (opts, ["definition", rootPath, file, line, col]) => - let line = int_of_string(line); - let col = int_of_string(col); - let quiet = hasOpts(opts, ["-q", "--quiet"]); - if (opts |> hasVerbose) { - Log.spamError := true; - References.debugReferences := true; - MerlinFile.debug := true; - }; - singleDefinition(~quiet, rootPath, file, line, col); - | (opts, ["check", rootPath, ...files]) => - let definitions = hasOpts(opts, ["-d", "--definitions"]); - let quiet = hasOpts(opts, ["-q", "--quiet"]); - if (opts |> hasVerbose) { - Log.spamError := true; - // if (!definitions) { - MerlinFile.debug := true; - // } - } else { - Log.spamError := false; - }; - check(~definitions, ~quiet, rootPath, files); | (_opts, ["dump", ...files]) => EditorSupportCommands.dump(files) | (_opts, ["complete", pathWithPos, currentFile]) => EditorSupportCommands.complete(~pathWithPos, ~currentFile) diff --git a/src/rescript-editor-support/vendor/omd/omd_parser.ml b/src/rescript-editor-support/vendor/omd/omd_parser.ml index 3e4b8bc9..174ade35 100644 --- a/src/rescript-editor-support/vendor/omd/omd_parser.ml +++ b/src/rescript-editor-support/vendor/omd/omd_parser.ml @@ -154,24 +154,6 @@ struct extraction a portion of another lexing tree. *) let fix l = let rec loop accu = function - (* code to generate what follows... - List.iter (fun e -> - Printf.printf " - | %s::%s::tl -> - if trackfix then eprintf \"%s 1\\n%!\"; - loop accu (%ss 0::tl) - | %ss n::%s::tl -> - if trackfix then eprintf \"%s 2\\n%!\"; - loop accu (%ss(n+1)::tl) - | %s::%ss n::tl -> - if trackfix then eprintf \"%s 3\\n%!\"; - loop accu (%ss(n+1)::tl) - | %ss a::%ss b::tl -> - if trackfix then eprintf \"%s 4\\n%!\"; - loop accu (%ss(a+b+2)::tl)" - e e e e e e e e e e e e e e e e) - ["Ampersand"; "At"; "Backquote"; "Backslash"; "Bar"; "Caret"; "Cbrace"; "Colon"; "Comma"; "Cparenthesis"; "Cbracket"; "Dollar"; "Dot"; "Doublequote"; "Exclamation"; "Equal"; "Greaterthan"; "Hash"; "Lessthan"; "Minus"; "Newline"; "Obrace"; "Oparenthesis"; "Obracket"; "Percent"; "Plus"; "Question"; "Quote"; "Semicolon"; "Slash"; "Space"; "Star"; "Tab"; "Tilde"; "Underscore"]; - print_string "| x::tl -> loop (x::accu) tl\n| [] -> List.rev accu\n"; *) | Ampersand::Ampersand::tl -> if trackfix then eprintf "(OMD) Ampersand 1\n"; loop accu (Ampersands 0::tl)