Skip to content

frontend: Highlight lines with error#114

Merged
juliaogris merged 3 commits intomasterfrom
error-lines
Mar 27, 2023
Merged

frontend: Highlight lines with error#114
juliaogris merged 3 commits intomasterfrom
error-lines

Conversation

@juliaogris
Copy link
Member

@juliaogris juliaogris commented Mar 23, 2023

Highlight lines with evy errors in editor. This is done by finding the
correct token by its line and columns and adding the "err" CSS class to it.
It is becoming increasingly obvious that a more fully fledged web code
editor will be needed. Evy files with more than 700ish lines are starting
to get janky when editing. I could work around this by only updating the
relevant lines, but it all seems to get a bit to hacky.

housekeeping: Do a one-off lint pass with stylelint of CSS(requires node
to which I'm not yet ready to commit.)

@github-actions
Copy link

github-actions bot commented Mar 23, 2023

firebase-deployment: https://evy-lang--114-qbhffxqh.web.app (3e57c20)

Lint CSS with stylelint, use --fix flag and manually fix 5 remaining
errors. We are not making stylelint part of the build process with
`make ci` yet, because it requires the setup of a node module :(.
We will follow up once we add bundling.

Style line was installed with:

        npm init #  yesyesyes
        npm init stylelint
        # add `"rules": { "rule-empty-line-before": "never" }` .stylelintrc.json
        npx stylelint --fix "**/*.css"

The only violated rule that couldn't be auto-fixed was
`no-descending-specificity`: "Disallow selectors of lower specificity
from coming after overriding selectors of higher specificity." Fair
enough this has bitten me before.

Link: https://stylelint.io/user-guide/rules/no-descending-specificity
Copy link
Member

@camh- camh- left a comment

Choose a reason for hiding this comment

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

Looks all javascripty to me. 🥒

I note the PR description and second commit message says: "Evy files with more than 700ish files are starting to get janky" - I think that is meant to be "700ish lines".

Highlight lines with evy errors in editor. This is done by finding the
correct token by its line and columns and adding the "err" CSS class to
it. It is becoming increasingly obvious that a more fully fledged web
code editor will be needed. Evy files with more than 700ish lines are
starting to get janky when editing. I could work around this by only
updating the relevant lines, but it all seems to get a bit to hacky.

After this error highlight addition we will leave editor hacking for
now.
Copy link
Member

@camh- camh- left a comment

Choose a reason for hiding this comment

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

LGTM. just a comment; feel free to ignore

Copy link
Member

@camh- camh- left a comment

Choose a reason for hiding this comment

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

LGTM. just a comment; feel free to ignore...

if !paramType.Accepts(argType) && !paramType.Matches(argType) {
p.appendError("'" + funcName + "' takes " + ordinalize(i+1) + " argument of type '" + paramType.String() + "', found '" + argType.String() + "'")
msg := fmt.Sprintf("'%s' takes %s argument of type '%s', found '%s'", funcName, ordinalize(i+1), paramType.String(), argType.String())
p.appendErrorForToken(msg, arg.Token())
Copy link
Member

Choose a reason for hiding this comment

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

in my local proof of concept, I went a bit further and also added the token to the two other errors in this function:

                        if !paramType.Accepts(argType) && !paramType.Matches(argType) {
-                               p.appendError("'" + funcName + "' takes variadic arguments of type '" + paramType.String() + "', found '" + argType.String() + "'")
+                               p.appendErrorForToken("'"+funcName+"' takes variadic arguments of type '"+paramType.String()+"', found '"+argType.String()+"'", arg.Tok())
                        }

and

        if len(decl.Params) != len(args) {
-               p.appendError("'" + funcName + "' takes " + quantify(len(decl.Params), "argument") + ", found " + strconv.Itoa(len(args)))
+               tok := p.cur
+               if len(args) > len(decl.Params) {
+                       tok = args[len(decl.Params)].Tok()
+               }
+               p.appendErrorForToken("'"+funcName+"' takes "+quantify(len(decl.Params), "argument")+", found "+strconv.Itoa(len(args)), tok)
                return
        }

Copy link
Member Author

Choose a reason for hiding this comment

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

all addressed. thank you!
(I had a mental note of doing this and then I forgot. busy mind)

Add Token() to ast Node interface so that we can more accurately
pinpoint the error position, e.g.:

	func numf n:num
	    print n
	end

	numf "abc"

The example above only highlighted the end of line with the `numf` with
a message saying first argument is of wrong type, but now it also
highlights `"abc"` correctly.

This is still problematic for error sources that are whole nodes, e.g.:

	numf "abc"+"123"

Should probably highlight all of `"abc"+"123"` rather than just the
first token. However, the might end up as undesired result for _very_
long expressions or multiline array / map literals.
@juliaogris juliaogris merged commit e1b648a into master Mar 27, 2023
@juliaogris juliaogris deleted the error-lines branch March 27, 2023 03:54
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.

2 participants