From 498ca6cbeea60592df3a4c5b64ee58cd28534850 Mon Sep 17 00:00:00 2001 From: ArneSchulze Date: Thu, 2 Dec 2021 16:09:20 +0100 Subject: [PATCH] Add support for odoc comment syntax for ReasonML comments Signed-off-by: ArneSchulze --- Readme.md | 1 + editor-extensions/coc.nvim/package.json | 5 +++++ editor-extensions/vscode/Readme.md | 1 + editor-extensions/vscode/package.json | 5 +++++ src/analyze/State.re | 21 +++++++++++++-------- src/analyze/TopTypes.re | 4 +++- src/analyze_fixture_tests/lib/TestUtils.re | 1 + src/lsp/NotificationHandlers.re | 2 ++ 8 files changed, 31 insertions(+), 9 deletions(-) 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/State.re b/src/analyze/State.re index f04a672d..41ea16a9 100644 --- a/src/analyze/State.re +++ b/src/analyze/State.re @@ -30,34 +30,35 @@ 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); +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); fold( src, - mlToOutput, - src => isMl(src) ? mlToOutput : (usePlainText ? compose(Omd.of_string, Omd.to_text) : (x => x)) + odocToOutput, + src => useOdocForReason || isMl(src) ? odocToOutput : mdToOutput ); }; -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 +84,7 @@ let docsForCmt = (~package, ~moduleName, cmt, src, state) => cmt, src, state.settings.clientNeedsPlainText, + state.settings.useOdocForReason ); } else { Some(docs); @@ -102,6 +104,7 @@ let docsForCmt = (~package, ~moduleName, cmt, src, state) => cmt, src, state.settings.clientNeedsPlainText, + state.settings.useOdocForReason ) }; }; @@ -122,6 +125,7 @@ let docsForCmt = (~package, ~moduleName, cmt, src, state) => cmt, src, state.settings.clientNeedsPlainText, + state.settings.useOdocForReason ); } else { Some(docs); @@ -141,6 +145,7 @@ let docsForCmt = (~package, ~moduleName, cmt, src, state) => cmt, src, state.settings.clientNeedsPlainText, + state.settings.useOdocForReason ) }; }; 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..45e4c0f0 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, 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 }, }); }),