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

Highlight unreachable element in Cram files #748

Closed
mnxn opened this issue Oct 18, 2021 · 6 comments · Fixed by #754
Closed

Highlight unreachable element in Cram files #748

mnxn opened this issue Oct 18, 2021 · 6 comments · Fixed by #754

Comments

@mnxn
Copy link
Collaborator

mnxn commented Oct 18, 2021

Highlight ***** UNREACHABLE ***** in Cram .t files.

ocaml/dune#4981 (comment)

@SaySayo
Copy link
Contributor

SaySayo commented Oct 19, 2021

I'd like to work on this

@tmattio
Copy link
Collaborator

tmattio commented Oct 19, 2021

Sounds good @SaySayo 🙂 FYI, here's a test that you can use to test the highlighting:

Syntax error inside a cram command
  $ mkdir foo && cd foo
  $ cat >dune-project <<EOF
  > (lang dune 3.0)
  > EOF

  $ cat >t1.t <<EOF
  >   $ foo-bar() { true; }
  > EOF

  $ dune runtest --auto-promote 2>&1 | sed -E -e 's/.+\.sh:/$SUBTEST.sh:/' -e 's/cd.*\&\&.*.sh/cd $DIR \&\& $SUBTEST.sh/'
  File "t1.t", line 1, characters 0-0:
  Error: Files _build/default/t1.t and _build/default/t1.t.corrected differ.
  Promoting _build/default/t1.t.corrected to t1.t.

  $ cat >t1.t <<EOF
  >   $ exit 1
  >   $ echo foobar
  > EOF
  $ dune runtest --auto-promote
  File "t1.t", line 1, characters 0-0:
  Error: Files _build/default/t1.t and _build/default/t1.t.corrected differ.
  Promoting _build/default/t1.t.corrected to t1.t.
  [1]
  $ cat t1.t
    $ exit 1
    ***** UNREACHABLE *****
    $ echo foobar
    ***** UNREACHABLE *****

@mnxn
Copy link
Collaborator Author

mnxn commented Oct 19, 2021

Making the syntax name start with invalid (for example invalid.unreachable.cram) will make most vscode themes highlight it in red.

I think that would be the best option if I'm correctly interpreting ***** UNREACHABLE ***** as an error.

@SaySayo
Copy link
Contributor

SaySayo commented Oct 25, 2021

Screenshot 2021-10-25 at 09 43 07

Here's the language grammar I wrote for it. I added it to the cram.json file but I see no changes when I run it in development.

@mnxn
Copy link
Collaborator Author

mnxn commented Oct 25, 2021

In your grammar rule, match includes \\( and \\), which will look for parentheses in the cram files.
The unreachable element has no parentheses, so it will not be currently highlighted.

In other words,
you need to highlight ***** UNREACHABLE *****,
but you're currently highlighting (***** UNREACHABLE *****)

Another suggestion I can make is to remove the captures sections, because the entire unreachable element (both the word and asterisks) should be highlighted the same. There's no reason to capture anything.
You can replace the entire captures section with just "name": "invalid.unreachable.cram".

@mnxn
Copy link
Collaborator Author

mnxn commented Oct 26, 2021

Closed by #754

@mnxn mnxn closed this as completed Oct 26, 2021
@rgrinberg rgrinberg added this to the 1.9.0 milestone Feb 21, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants