Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
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
6 changes: 3 additions & 3 deletions src/analyze/AsYouType.re
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Copy link
Author

@ArneSchulze ArneSchulze Dec 3, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Providing a converter as argument is supposed to make sure that documentation comments for local symbols also display text in the correct format. Previously the doc comment text was passed around as-is, so that displaying only worked for markdown comments, not for odoc

let interface = Utils.endsWith(uri, "i");
let%try (syntaxError, astFile) = switch (refmtPath) {
| Some(refmtPath) => runRefmt(~interface, ~moduleName, ~cacheLocation, text, refmtPath);
Expand Down Expand Up @@ -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) =>
Expand Down Expand Up @@ -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)
}
}
Expand Down
32 changes: 23 additions & 9 deletions src/analyze/State.re
Original file line number Diff line number Diff line change
Expand Up @@ -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);
};
Expand All @@ -83,6 +91,7 @@ let docsForCmt = (~package, ~moduleName, cmt, src, state) =>
cmt,
src,
state.settings.clientNeedsPlainText,
state.settings.useOdocForReason
);
} else {
Some(docs);
Expand All @@ -102,6 +111,7 @@ let docsForCmt = (~package, ~moduleName, cmt, src, state) =>
cmt,
src,
state.settings.clientNeedsPlainText,
state.settings.useOdocForReason
)
};
};
Expand All @@ -122,6 +132,7 @@ let docsForCmt = (~package, ~moduleName, cmt, src, state) =>
cmt,
src,
state.settings.clientNeedsPlainText,
state.settings.useOdocForReason
);
} else {
Some(docs);
Expand All @@ -141,6 +152,7 @@ let docsForCmt = (~package, ~moduleName, cmt, src, state) =>
cmt,
src,
state.settings.clientNeedsPlainText,
state.settings.useOdocForReason
)
};
};
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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)
}
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
7 changes: 5 additions & 2 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 Expand Up @@ -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)
Expand Down Expand Up @@ -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)
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