smithy-lang / smithy-vscode

A Visual Studio Code extension to provide syntax highlighting for the Smithy IDL.
https://marketplace.visualstudio.com/items?itemName=smithy.smithy-vscode-extension
Apache License 2.0
37 stars 14 forks source link

Support Smithy IDL 2.0 syntax #18

Closed JordonPhillips closed 2 years ago

JordonPhillips commented 2 years ago

This adds support for some of the new idl syntax for 2.0. Namely it adds support for:

I do not think it is possible for a TextMate grammar to be able to distinguish between a key and a value in every case when there are no pair separators, though I would love to be proven wrong on this.

TM grammars are regex-based, but crucially regexes can never match across lines. A regex with a newline in the middle, like foo\nbar will NEVER match. This is to allow the highlighter to be able to re-start at any line if parsing failed on a previous line. To work around this somewhat, they allow you to change states with begin and end regexes. Since these state changes are regexes and regexes can't span lines, you can't have a complex end state. So you can't simply say "end after parsing a json-like value". Since we have no other indication that a pair is ended, we can't end a pair state if we enter one.

For some context, the way the JSON TM grammar works is by having an effective "value" state which is started by : and ended by , or }. This is what we used to do.

Now what we CAN do if we don't care about being 100% accurate in all cases, is try to match the key if it shares a line with the colon. This is the approach I've gone with since I'm willing to bet this will be the case most of the time.

Screenshot 2021-11-08 at 18 38 37

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

JordonPhillips commented 2 years ago

I added support for the = default sugar proposed in https://github.com/awslabs/smithy/pull/920

Screenshot 2021-11-09 at 15 05 05
JordonPhillips commented 2 years ago

Whoops, forgot mixins! While I was at it I fixed traits within shape definitions and a handful of bad captures.

Screenshot 2021-11-09 at 18 14 43