Skip to content

Commit

Permalink
Add support for odoc comment syntax for ReasonML comments
Browse files Browse the repository at this point in the history
Signed-off-by: ArneSchulze <[email protected]>
  • Loading branch information
ArneSchulze committed Dec 2, 2021
1 parent ce1b3f8 commit 498ca6c
Show file tree
Hide file tree
Showing 8 changed files with 31 additions and 9 deletions.
1 change: 1 addition & 0 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
5 changes: 5 additions & 0 deletions editor-extensions/coc.nvim/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
}
Expand Down
1 change: 1 addition & 0 deletions editor-extensions/vscode/Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions editor-extensions/vscode/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
},
Expand Down
21 changes: 13 additions & 8 deletions src/analyze/State.re
Original file line number Diff line number Diff line change
Expand Up @@ -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);
};
Expand All @@ -83,6 +84,7 @@ let docsForCmt = (~package, ~moduleName, cmt, src, state) =>
cmt,
src,
state.settings.clientNeedsPlainText,
state.settings.useOdocForReason
);
} else {
Some(docs);
Expand All @@ -102,6 +104,7 @@ let docsForCmt = (~package, ~moduleName, cmt, src, state) =>
cmt,
src,
state.settings.clientNeedsPlainText,
state.settings.useOdocForReason
)
};
};
Expand All @@ -122,6 +125,7 @@ let docsForCmt = (~package, ~moduleName, cmt, src, state) =>
cmt,
src,
state.settings.clientNeedsPlainText,
state.settings.useOdocForReason
);
} else {
Some(docs);
Expand All @@ -141,6 +145,7 @@ let docsForCmt = (~package, ~moduleName, cmt, src, state) =>
cmt,
src,
state.settings.clientNeedsPlainText,
state.settings.useOdocForReason
)
};
};
Expand Down
4 changes: 3 additions & 1 deletion src/analyze/TopTypes.re
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down Expand Up @@ -96,6 +97,7 @@ let empty = () => {
recordAllLocations: false,
autoRebuild: true,
buildSystemOverrideByRoot: [],
useOdocForReason: false,
},
};

Expand Down
1 change: 1 addition & 0 deletions src/analyze_fixture_tests/lib/TestUtils.re
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ let getState = () => {
opensCodelens: true,
dependenciesCodelens: true,
clientNeedsPlainText: false,
useOdocForReason: false,
showModulePathOnHover: false,
recordAllLocations: false,
autoRebuild: false,
Expand Down
2 changes: 2 additions & 0 deletions src/lsp/NotificationHandlers.re
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -132,6 +133,7 @@ let notificationHandlers: list((string, (state, Json.t) => result(state, string)
showModulePathOnHover,
autoRebuild,
buildSystemOverrideByRoot,
useOdocForReason
},
});
}),
Expand Down

0 comments on commit 498ca6c

Please sign in to comment.