-
Notifications
You must be signed in to change notification settings - Fork 25
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Language server; error location in SyntaxErrors #750
Conversation
✅ Deploy Preview for squiggle-documentation ready!
To edit notification comments on pull requests, go to your Netlify site settings. |
✅ Deploy Preview for squiggle-components ready!
To edit notification comments on pull requests, go to your Netlify site settings. |
): result<null, Extract<errorValue, { tag: "RESyntaxError" }>> { | ||
const maybeExpression = parseRescript(squiggleString); | ||
if (maybeExpression.tag === "Ok") { | ||
return Ok(null); // TODO - return AST |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This didn't seem too important since I was just interested in errors.
typeof maybeExpression.value !== "object" || | ||
maybeExpression.value.tag !== "RESyntaxError" | ||
) { | ||
throw new Error("Expected syntax error"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a bit hacky but I didn't want to force the consumer to check for all error types. Should we rethink error hierarchy so that parse
could return only syntax errors?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lots of options re polymorphic variants to work with subsets of errors.
@@ -50,7 +53,7 @@ let errorToString = err => | |||
| RENotAFunction(valueString) => `${valueString} is not a function` | |||
| RERecordPropertyNotFound(msg, index) => `${msg}: ${index}` | |||
| RESymbolNotFound(symbolName) => `${symbolName} is not defined` | |||
| RESyntaxError(desc) => `Syntax Error: ${desc}` | |||
| RESyntaxError(desc, _) => `Syntax Error: ${desc}` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably should've appended a location here too but I wasn't even sure where errorToString
is used and was too busy to check.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's worth it, if you can get around to it.
Codecov Report
@@ Coverage Diff @@
## develop #750 +/- ##
===========================================
+ Coverage 52.32% 52.38% +0.05%
===========================================
Files 59 59
Lines 3606 3608 +2
===========================================
+ Hits 1887 1890 +3
+ Misses 1719 1718 -1
Continue to review full report at Codecov.
|
@@ -5,11 +5,15 @@ type node = {"type": string} | |||
|
|||
@module("./Reducer_Peggy_GeneratedParser.js") external parse__: string => node = "parse" | |||
|
|||
let syntaxErrorToLocation: Js.Exn.t => Reducer_ErrorValue.location = error => %raw(`error.location`) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's probably a more elegant way to do this and I just don't know ReScript well enough. But Js.Ext
is not documented well and I gave up after ~1h of googling and trying to cast Js.Ext.t
to peggy's SyntaxError with genType
...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yea, the Rescript <> JS interop is pretty awkward and poorly documented. It's generally the worst part of working with Rescript.
@@ -142,6 +144,13 @@ | |||
"eslint": "^8.18.0", | |||
"glob": "^8.0.3", | |||
"js-yaml": "^4.1.0", | |||
"typescript": "^4.7.4" | |||
"typescript": "^4.7.4", | |||
"vsce-yarn-patch": "^1.66.2" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is for our monorepo compatibility (vsce is a tool for packaging vscode extensions), see microsoft/vscode-vsce#300 (comment).
This is what caused yesterday's issues with broken 0.1.0 and 0.1.1 versions.
Yes, it's a fork. It hasn't been updated in 2 years. Seems like everyone with a monorepo still uses it. Sigh.
@@ -58,6 +58,7 @@ | |||
"nyc": "^15.1.0", | |||
"peggy": "^2.0.1", | |||
"reanalyze": "^2.23.0", | |||
"rescript": "^9.1.4", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Docs:
Make sure the version number of bs-platform and @rescript/std match in your package.json to avoid running into runtime issues due to mismatching stdlib assumptions.
Not sure if I should be more paranoid and pin both rescript and @rescript/std to a specific version. dependabot will always update them both simultaneously and we have them pinned in yarn.lock, so it should be ok, but still, it might be bad if they ever get out of sync.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep! great stuff. I only looked at the squiggle-lang
changes really, and didn't see anything to take issue with.
typeof maybeExpression.value !== "object" || | ||
maybeExpression.value.tag !== "RESyntaxError" | ||
) { | ||
throw new Error("Expected syntax error"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lots of options re polymorphic variants to work with subsets of errors.
@@ -50,7 +53,7 @@ let errorToString = err => | |||
| RENotAFunction(valueString) => `${valueString} is not a function` | |||
| RERecordPropertyNotFound(msg, index) => `${msg}: ${index}` | |||
| RESymbolNotFound(symbolName) => `${symbolName} is not defined` | |||
| RESyntaxError(desc) => `Syntax Error: ${desc}` | |||
| RESyntaxError(desc, _) => `Syntax Error: ${desc}` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's worth it, if you can get around to it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
From what I understand, I'm fine with it. I'm not that worried about the other stuff. I recommend considering @quinn-dougherty 's comments though, of course.
Hmm, actually, should I return an It's a bit more work since I'd have to convert it to typescript values, but exposing raw peggy nodes seems wrong. Upd: I forgot I don't return any AST :) But in the future it definitely should be |
This PR and some other work is changing some of the typescript stuff a bit. Maybe wait a few days to make the change? |
Going to merge, feel free to add modifications/adjustments later. |
This is not yet released on VS Code marketplace because the extension bundle is huge.
I'll have to wrap the server code in webpack or rollup first. Or repackage squiggle-lang with @rescript/std.