5 ms·
You would only get the top half of your code highlighted because a compiler doesnt usually continue when encountering syntax errors due to partial code
by pawelmurias 3y ago
You would only get the top half of your code highlighted because a compiler doesnt usually continue when encountering syntax errors due to partial code
- craftkiller 3y agoThat's sort-of already the case whenever we start a string in any language that supports multi-line strings. You type the first " and then the rest of your file gets re-interpreted as a string. It is annoying but I still think its a worthy trade-off, because I spend a lot more time reading code than being mid-edit with invalid syntax.
- troupo 3y agoSyntax errors are not limited to just typing a quote
- craftkiller 3y agoI never said they were. I'm just pointing out that we already experience the same problem in the case of quotes without the world ending, and I don't think expanding the problem to all syntax errors will make it much worse.
- troupo 3y agoIt would make it significantly much worse. Because every incomplete statement that you're just writing would break all syntax highlighting right after your cursor. And if you use any modern editor or IDE this doesn't happen.
- _flux 3y agoIf the code was valid at some point (e.g. when opening it) it could remember the old colorings of the rest of the code. Though handling opening and closing a string and still ending up in an illegal state would need some more logic.. Maybe not worth it.
- morelisp 3y ago> If the code was valid at some point (e.g. when opening it) it could remember the old colorings of the rest of the code. If you continue down this line of thinking a few more steps, eventually you produce tree-sitter.
- lelanthran 3y ago> You would only get the top half of your code highlighted because a compiler doesnt usually continue when encountering syntax errors due to partial code Sounds like a feature - don't need to scan for tiny squiggly red lines, or examine some tiny font output in a status bar somewhere. I'd love it.
- G3rn0ti 3y ago> You would only get the top half of your code highlighted because a compiler Your comment implies a language server taps into the language's compiler/interpreter. That is a popular misconception. Almost all LSP severs don't actually use the compiler backend of the language they are servicing. All the LSP server implementations I've seen at least just use a static parsing approach (or even worse i.e. just a tokenizer) similar to what Treesitter does. It is just not limited to a single file. That's why I still think Treesitter has the potential to not only improve syntax highlighting but also to simplify language servers or even -- in the long run with some extensions of the the language modes -- replace it altogether.
- gpderetta 3y agoBut some do. Most notably clangd. Still clangd tries parse broken code using recovery heuristics (which can still be useful in a compiler to produce decent error messages).
- morelisp 3y ago> Your comment implies a language server taps into the language's compiler/interpreter. That is a popular misconception. But it is a misconception which framed the discussion, not a misconception of the answerer. The claim was that LSP was > performed by 100% accurate parsers instead of approximations