Skip to content

Commit

Permalink
Show warnings (#139)
Browse files Browse the repository at this point in the history
* update deps

* update ui
  • Loading branch information
jchavarri authored Oct 31, 2023
1 parent c3eb5f8 commit 4afafef
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 12 deletions.
6 changes: 4 additions & 2 deletions documentation-site.opam
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,10 @@ depends: [
]
dev-repo: "git+https://github.com/melange-re/melange-re.github.io.git"
pin-depends: [
[ "melange.dev" "git+https://github.com/melange-re/melange.git#e565471cdb086cc3632687366d8ea503d5da39e7" ]
[ "melange-playground.dev" "git+https://github.com/melange-re/melange.git#e565471cdb086cc3632687366d8ea503d5da39e7" ]
[ "melange.dev" "git+https://github.com/melange-re/melange.git#1cd8dded9fc52dcfdb9a504dd29c120a1cfbb309" ]
[ "melange-playground.dev" "git+https://github.com/melange-re/melange.git#1cd8dded9fc52dcfdb9a504dd29c120a1cfbb309" ]
[ "reason-react.dev" "git+https://github.com/reasonml/reason-react.git#18a8fa2b3524b5f5cf0154875f963db096a992e9" ]
[ "reason-react-ppx.dev" "git+https://github.com/reasonml/reason-react.git#18a8fa2b3524b5f5cf0154875f963db096a992e9" ]
[ "cmarkit.dev" "git+https://github.com/dbuenzli/cmarkit.git#f37c8ea86fd0be8dba7a8babcee3682e0e047d91" ]
]
build: [
Expand Down
28 changes: 18 additions & 10 deletions playground/src/app.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ function Sidebar({ onExampleClick }) {
<div className="Versions">
<span className="Version">
<span className="Text-xs">{"Melange"}</span>
<span className="Text-xs Number">{"2.1.0"}</span>
<span className="Text-xs Number">{"dev"}</span>
</span>
<span className="Version">
<span className="Text-xs">{"OCaml"}</span>
Expand All @@ -149,7 +149,7 @@ function Sidebar({ onExampleClick }) {
</span>
<span className="Version">
<span className="Text-xs">{"ReasonReact"}</span>
<span className="Text-xs Number">{"0.13.0"}</span>
<span className="Text-xs Number">{"dev"}</span>
</span>
</div>
</div>) : null}
Expand Down Expand Up @@ -379,14 +379,14 @@ function OutputEditor({ language, value }) {
}

const problemFromCompile = ({
js_error_msg,
js_warning_error_msg,
row,
column,
endRow,
endColumn,
text,
}) => ({
msg: js_error_msg,
msg: js_warning_error_msg,
loc: {
row: row + 1,
column: column + 1,
Expand All @@ -396,13 +396,13 @@ const problemFromCompile = ({
},
});

const toMonaco = (problem) => ({
const toMonaco = (severity) => (problem) => ({
startLineNumber: problem.loc.row,
startColumn: problem.loc.column,
endLineNumber: problem.loc.endRow,
endColumn: problem.loc.endColumn,
message: problem.msg,
severity: monaco.MarkerSeverity.Error,
severity: severity,
});

const compile = (language, code) => {
Expand All @@ -412,12 +412,12 @@ const compile = (language, code) => {
? ocaml.compileRE(code)
: ocaml.compileML(code);
} catch (error) {
compilation = { js_error_msg: error.message };
compilation = { js_warning_error_msg: error.message };
}

if (compilation) {
let problems = undefined;
if (compilation.js_error_msg) {
if (compilation.js_warning_error_msg) {
problems = [problemFromCompile(compilation)];
} else if (compilation.warning_errors) {
problems = compilation.warning_errors.map(problemFromCompile);
Expand Down Expand Up @@ -449,14 +449,15 @@ const compile = (language, code) => {
}
}),
javascriptCode: compilation.js_code,
warnings: compilation.warnings.map(problemFromCompile),
}
}
} else {
return {
typeHints: [],
problems: [
{
js_error_msg: "No result was returned from compilation",
js_warning_error_msg: "No result was returned from compilation",
row,
column,
endRow,
Expand All @@ -475,7 +476,14 @@ function updateMarkers(monaco, editorRef, compilation) {
monaco.editor.setModelMarkers(
editorRef.current.getModel(),
owner,
compilation.problems.map(toMonaco)
compilation.problems.map(toMonaco(monaco.MarkerSeverity.Error))
);
} else if (compilation?.warnings) {
console.log(compilation.warnings.map(toMonaco(monaco.MarkerSeverity.Warning)));
monaco.editor.setModelMarkers(
editorRef.current.getModel(),
owner,
compilation.warnings.map(toMonaco(monaco.MarkerSeverity.Warning))
);
} else {
monaco.editor.removeAllMarkers(owner);
Expand Down

0 comments on commit 4afafef

Please sign in to comment.