diff --git a/Readme.md b/Readme.md index e60bdb69..78ae0c63 100644 --- a/Readme.md +++ b/Readme.md @@ -131,6 +131,7 @@ The language server supports the following settings (not all of them apply to al - `dependencies_codelens` - list a files dependencies at the top (bool) - `opens_codelens` - show what values are used from an `open` (bool) - `autoRebuild` — rebuild project on save (turned on by default) (bool) +- `use_odoc_for_reason` - treat ReasonML comments as odoc comments (turned off by default) ### Debug settings diff --git a/editor-extensions/coc.nvim/package.json b/editor-extensions/coc.nvim/package.json index 6a080156..95312baa 100644 --- a/editor-extensions/coc.nvim/package.json +++ b/editor-extensions/coc.nvim/package.json @@ -97,6 +97,11 @@ "type": "boolean", "default": true, "description": "Enables autorun of bsb" + }, + "reason_language_server.use_odoc_for_reason": { + "type": "boolean", + "default": false, + "description": "Enables odoc syntax for ReasonML comments" } } } diff --git a/editor-extensions/vscode/Readme.md b/editor-extensions/vscode/Readme.md index e47dfdd8..4d3b88bb 100644 --- a/editor-extensions/vscode/Readme.md +++ b/editor-extensions/vscode/Readme.md @@ -32,6 +32,7 @@ all configuration is prefixed with `reason_language_server.` - `.dependencies_codelens` - list a files dependencies at the top - `.opens_codelens` - show what values are used from an `open` - `.autoRebuild` — rebuild project on save (turned on by default) +- `.use_odoc_for_reason` - treat ReasonML comments as odoc comments (turned off by default) ## Debugging configuration most useful if your developing the language server diff --git a/editor-extensions/vscode/package.json b/editor-extensions/vscode/package.json index 66005322..c9a375c6 100644 --- a/editor-extensions/vscode/package.json +++ b/editor-extensions/vscode/package.json @@ -126,6 +126,11 @@ "type": "boolean", "default": true, "description": "Enables autorun of bsb" + }, + "reason_language_server.use_odoc_for_reason": { + "type": "boolean", + "default": false, + "description": "Enables odoc syntax for ReasonML comments" } } }, diff --git a/src/analyze/AsYouType.re b/src/analyze/AsYouType.re index 4ca571d9..a7d60265 100644 --- a/src/analyze/AsYouType.re +++ b/src/analyze/AsYouType.re @@ -171,7 +171,7 @@ let getAst = (~cacheLocation, ~compilerVersion, ~moduleName, ~uri) => { Ok("NVM") }; */ -let process = (~uri, ~moduleName, ~basePath, ~reasonFormat, text, ~cacheLocation, ~compilerVersion, ~allLocations, compilerPath, refmtPath, includes, flags) => { +let process = (~uri, ~moduleName, ~basePath, ~reasonFormat, text, ~cacheLocation, ~compilerVersion, ~allLocations, compilerPath, refmtPath, includes, flags, converter) => { let interface = Utils.endsWith(uri, "i"); let%try (syntaxError, astFile) = switch (refmtPath) { | Some(refmtPath) => runRefmt(~interface, ~moduleName, ~cacheLocation, text, refmtPath); @@ -199,7 +199,7 @@ let process = (~uri, ~moduleName, ~basePath, ~reasonFormat, text, ~cacheLocation | Some({Unix.st_size: size}) => Log.log("Size " ++ string_of_int(size)) | _ => Log.log("Doesn't exist") }; - let%try_wrap {file, extra} = fullForCmt(cmtPath, uri, x => x); + let%try_wrap {file, extra} = fullForCmt(cmtPath, uri, converter); let errorText = String.concat("\n", lines); switch (syntaxError) { | Some(s) => @@ -227,7 +227,7 @@ let process = (~uri, ~moduleName, ~basePath, ~reasonFormat, text, ~cacheLocation // close_in(ic); // | _ => Log.log("Doesn't exist") // }; - let%try_wrap full = fullForCmt(cmtPath, uri, x => x); + let%try_wrap full = fullForCmt(cmtPath, uri, converter); Success(String.concat("\n", lines @ error), full) } } diff --git a/src/analyze/State.re b/src/analyze/State.re index f04a672d..2a633ef7 100644 --- a/src/analyze/State.re +++ b/src/analyze/State.re @@ -30,34 +30,42 @@ let isMl = path => let odocToMd = text => MarkdownOfOCamldoc.convert(text); let compose = (fn1, fn2, arg) => fn1(arg) |> fn2; -let converter = (src, usePlainText) => { - let mlToOutput = compose(odocToMd, usePlainText ? Omd.to_text : Omd.to_markdown); - fold( +let converter = (src, usePlainText, useOdocForReason) => { + let odocToOutput = compose(odocToMd, usePlainText ? Omd.to_text : Omd.to_markdown); + let mdToOutput = usePlainText ? compose(Omd.of_string, Omd.to_text) : (x => x); + let converter = fold( src, - mlToOutput, - src => isMl(src) ? mlToOutput : (usePlainText ? compose(Omd.of_string, Omd.to_text) : (x => x)) + odocToOutput, + src => useOdocForReason || isMl(src) ? odocToOutput : mdToOutput ); + + src => { + let res = converter(src); + + Log.log("src: " ++src ++ ", res: " ++ res); + res; + } }; -let newDocsForCmt = (~compilerVersion, ~moduleName, cmtCache, changed, cmt, src, clientNeedsPlainText) => { +let newDocsForCmt = (~compilerVersion, ~moduleName, cmtCache, changed, cmt, src, clientNeedsPlainText, useOdocForReason) => { let uri = Utils.toUri(src |? cmt); let%opt file = (switch compilerVersion { | BuildSystem.V402 => Process_402.fileForCmt | V406 => Process_406.fileForCmt | V407 => Process_407.fileForCmt | V408 => Process_408.fileForCmt - })(~moduleName, cmt, uri, converter(src, clientNeedsPlainText)) |> RResult.toOptionAndLog; + })(~moduleName, cmt, uri, converter(src, clientNeedsPlainText, useOdocForReason)) |> RResult.toOptionAndLog; Hashtbl.replace(cmtCache, cmt, (changed, file)); Some(file); }; -let newDocsForCmi = (~compilerVersion, ~moduleName, cmiCache, changed, cmi, src, clientNeedsPlainText) => { +let newDocsForCmi = (~compilerVersion, ~moduleName, cmiCache, changed, cmi, src, clientNeedsPlainText, useOdocForReason) => { let%opt file = (switch compilerVersion { | BuildSystem.V402 => Process_402.fileForCmi | V406 => Process_406.fileForCmi | V407 => Process_407.fileForCmi | V408 => Process_408.fileForCmi - })(~moduleName, cmi, Utils.toUri(src |? cmi), converter(src, clientNeedsPlainText)); + })(~moduleName, cmi, Utils.toUri(src |? cmi), converter(src, clientNeedsPlainText, useOdocForReason)); Hashtbl.replace(cmiCache, cmi, (changed, file)); Some(file); }; @@ -83,6 +91,7 @@ let docsForCmt = (~package, ~moduleName, cmt, src, state) => cmt, src, state.settings.clientNeedsPlainText, + state.settings.useOdocForReason ); } else { Some(docs); @@ -102,6 +111,7 @@ let docsForCmt = (~package, ~moduleName, cmt, src, state) => cmt, src, state.settings.clientNeedsPlainText, + state.settings.useOdocForReason ) }; }; @@ -122,6 +132,7 @@ let docsForCmt = (~package, ~moduleName, cmt, src, state) => cmt, src, state.settings.clientNeedsPlainText, + state.settings.useOdocForReason ); } else { Some(docs); @@ -141,6 +152,7 @@ let docsForCmt = (~package, ~moduleName, cmt, src, state) => cmt, src, state.settings.clientNeedsPlainText, + state.settings.useOdocForReason ) }; }; @@ -287,6 +299,7 @@ let getCompilationResult = (uri, state, ~package: TopTypes.package) => { refmtPath, includes, package.compilationFlags, + converter(Some(uri), state.settings.clientNeedsPlainText, state.settings.useOdocForReason) ); Hashtbl.replace(state.compiledDocuments, uri, result); switch (result) { @@ -407,6 +420,7 @@ let fileForModule = (state, ~package, modname) => { switch file { | Some(_) => file | None => + Log.log("Getting docs for module: " ++ modname); let%opt (file, _) = docsForModule(modname, state, ~package); Some(file) } diff --git a/src/analyze/TopTypes.re b/src/analyze/TopTypes.re index 5a18856d..192f0e67 100644 --- a/src/analyze/TopTypes.re +++ b/src/analyze/TopTypes.re @@ -48,7 +48,8 @@ type settings = { showModulePathOnHover: bool, recordAllLocations: bool, autoRebuild: bool, - buildSystemOverrideByRoot: list((string, BuildSystem.t)) + buildSystemOverrideByRoot: list((string, BuildSystem.t)), + useOdocForReason: bool }; type state = { @@ -96,6 +97,7 @@ let empty = () => { recordAllLocations: false, autoRebuild: true, buildSystemOverrideByRoot: [], + useOdocForReason: false, }, }; diff --git a/src/analyze_fixture_tests/lib/TestUtils.re b/src/analyze_fixture_tests/lib/TestUtils.re index 9cea6c13..68fc5a5a 100644 --- a/src/analyze_fixture_tests/lib/TestUtils.re +++ b/src/analyze_fixture_tests/lib/TestUtils.re @@ -115,6 +115,7 @@ let getState = () => { opensCodelens: true, dependenciesCodelens: true, clientNeedsPlainText: false, + useOdocForReason: false, showModulePathOnHover: false, recordAllLocations: false, autoRebuild: false, @@ -181,7 +182,8 @@ let setUp = (~projectDir, files, text) => { package.compilerPath, package.refmtPath, [tmp], - "" + "", + x => x ); switch result { | AsYouType.SyntaxError(text, _, _) => failwith("Syntax error " ++ text) @@ -211,7 +213,8 @@ let setUp = (~projectDir, files, text) => { package.compilerPath, package.refmtPath, [tmp], - "" + "", + x => x ); /* switch result { | AsYouType.SyntaxError(syntaxError, _, full) => Log.log("Syntax error! " ++ syntaxError) diff --git a/src/lsp/NotificationHandlers.re b/src/lsp/NotificationHandlers.re index 49392ea2..f651a9d2 100644 --- a/src/lsp/NotificationHandlers.re +++ b/src/lsp/NotificationHandlers.re @@ -110,6 +110,7 @@ let notificationHandlers: list((string, (state, Json.t) => result(state, string) let crossFileAsYouType = false; let showModulePathOnHover = (settings |?> Json.get("show_module_path_on_hover") |?> Json.bool) |? true; let autoRebuild = settings |?> Json.get("autoRebuild") |?> Json.bool |? true; + let useOdocForReason = (settings |?> Json.get("use_odoc_for_reason") |?> Json.bool) |? false; let buildSystemOverrideByRoot = (settings |?> Json.get("build_system_override_by_root") |?> Json.obj |? [])->Belt.List.keepMap(((key, v)) => { let%opt v = Json.string(v); @@ -132,6 +133,7 @@ let notificationHandlers: list((string, (state, Json.t) => result(state, string) showModulePathOnHover, autoRebuild, buildSystemOverrideByRoot, + useOdocForReason }, }); }),