NateLevin1/wati

Improve declaration intellisense

Closed this issue · 4 comments

For the declarations table, elem, data, type, loop, and block we get "unknown" when hovering over labels.
image
This is contrast to function declarations where we get a quick summary of what the label points to.
image
This means when referencing a label later in the file, it's not always obvious what kind of label we're dealing with (if named improperly).

Interesting - loop and block not showing hover information sounds like a bug. The others currently aren't handled (although they of course should be!)

In fact, it might be worth it to move from the current "giant regex" approach to an actual parser like @webassemblyjs/wast-parser for these features. I'm willing to implement this but I'm not sure when I'll have the time.

Yeah, a parser is definitely the right approach here. I tried the regex approach myself and missed a bunch of corner cases.

My schedule is going to be super busy the next few days, but I should be clear the end of the week to start working on these myself. I'd just like to get the docs changes merged before I start work on the more technical features.

Looks like @webassemblyjs/wast-parser does not have support for reference types and likely many more upcoming wasm features. This makes it a no-go for feature development. Our language server should not fully break when it sees new syntax. It should act more like a syntax highlighter where tokens are preserved, not parsed.

Something like @codemirror/lang-wast might be able to work. Even though it's meant as a syntax highlighter, we could probably extract the internal parser and use it for tokenization.

It's based off of lezer which uses incremental parsing (again, perfect for our use case). We could also just clone the grammar file and build it ourself.

You are right, something incremental would be ideal (well, required). Implementing that could be a huge undertaking though - if you’re interested, by all means go for it!