Skip to content
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

Merged
merged 7 commits into from
Jun 24, 2022
Merged

Conversation

berekuk
Copy link
Collaborator

@berekuk berekuk commented Jun 21, 2022

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.

@netlify
Copy link

netlify bot commented Jun 21, 2022

Deploy Preview for squiggle-documentation ready!

Name Link
🔨 Latest commit 9da6c12
🔍 Latest deploy log https://app.netlify.com/sites/squiggle-documentation/deploys/62b42ba62dc0e500088ac492
😎 Deploy Preview https://deploy-preview-750--squiggle-documentation.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site settings.

@netlify
Copy link

netlify bot commented Jun 21, 2022

Deploy Preview for squiggle-components ready!

Name Link
🔨 Latest commit 9da6c12
🔍 Latest deploy log https://app.netlify.com/sites/squiggle-components/deploys/62b42ba6d3774700083a1b05
😎 Deploy Preview https://deploy-preview-750--squiggle-components.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

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
Copy link
Collaborator Author

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");
Copy link
Collaborator Author

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?

Copy link
Contributor

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}`
Copy link
Collaborator Author

@berekuk berekuk Jun 21, 2022

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.

Copy link
Contributor

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-commenter
Copy link

codecov-commenter commented Jun 21, 2022

Codecov Report

Merging #750 (9da6c12) into develop (06d7804) will increase coverage by 0.05%.
The diff coverage is 100.00%.

@@             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     
Impacted Files Coverage Δ
.../Reducer/Reducer_Expression/Reducer_Expression.res 88.37% <ø> (ø)
...e-lang/src/rescript/Reducer/Reducer_ErrorValue.res 65.21% <100.00%> (+4.34%) ⬆️
...ript/Reducer/Reducer_Peggy/Reducer_Peggy_Parse.res 95.74% <100.00%> (+0.18%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 06d7804...9da6c12. Read the comment docs.

@@ -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`)
Copy link
Collaborator Author

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...

Copy link
Contributor

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"
Copy link
Collaborator Author

@berekuk berekuk Jun 21, 2022

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",
Copy link
Collaborator Author

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.

Copy link
Contributor

@quinn-dougherty quinn-dougherty left a 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");
Copy link
Contributor

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}`
Copy link
Contributor

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.

Copy link
Contributor

@OAGr OAGr left a 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.

@berekuk
Copy link
Collaborator Author

berekuk commented Jun 23, 2022

Hmm, actually, should I return an expression (Reducer_Expression.parse) instead of Reducer_Peggy_Parse.parse?

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 Reducer_Expression.parse.

@OAGr
Copy link
Contributor

OAGr commented Jun 23, 2022

Hmm, actually, should I return an expression (Reducer_Expression.parse) instead of Reducer_Peggy_Parse.parse?

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 Reducer_Expression.parse.

This PR and some other work is changing some of the typescript stuff a bit. Maybe wait a few days to make the change?
#752

@OAGr
Copy link
Contributor

OAGr commented Jun 24, 2022

Going to merge, feel free to add modifications/adjustments later.

@OAGr OAGr merged commit 934608d into develop Jun 24, 2022
@OAGr OAGr deleted the language-server branch June 24, 2022 00:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants