You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Jan 25, 2024. It is now read-only.
Enable incremental parsing via the LSP protocol (#37)
* Enable incremental parsing via the LSP protocol
With incremental parsing, the editor only sends a "diff" of what has
changed rather than the full file. For instance, it's pretty pointless
to send all of `all-packages.nix` from `nixpkgs` for a single-letter
change.
Given the benchmark of `rnix-parser`[1] it doesn't seem as the parsing
itself is the bottleneck a few people have reported[2], so this change
only replaces affected lines and re-parses everything using
`rnix-parser`.
While the current change seems usable on local tests, it has (at
least) two known issues:
* As soon as you type `inherit`, the LSP stalls and it seems it's due to
`rnix-parser` and steadily allocates more memory according to
`strace(1)`. I confirmed that it's indeed a problem of `rnix-parser`
by creating a file with `{ inherit` as content and the LSP refuses to
respond (with incremental parsing disabled).
* Given an expression like this:
``` nix
let a = 1; in
{
b = a;
}
```
When deleting line one and then line 2, the state ends up as `{{ }`.
This is because the range passed to LSP looks like this:
```
Range {
start: Position {
line: 1,
character: 0
},
end: Position {
line: 2,
character: 0
}
}
```
This also kills the second line of the expression above and as soon as
you delete this as well, the state will end up with bogus results.
It's a bit weird though since I got an equal message when deleting
more lines, so I'm not entirely sure if that's just a bug in the LSP
implementation of my neoVIM (and also the reason why I didn't just
insert a `\n` at the right vec entries).
[1] https://github.com/nix-community/rnix-parser/blob/v0.9.0/benches/all-packages.rs
[2] #27 (comment)
* Don't swallow empty lines if the previous one (including the `\n` separator) gets deleted
* Simplify (& hopefully fix) incremental parsing
Rather than trying to mess around in an existing datastructure and thus
running into tons of mean special cases since you have to take care of
removing/adding lines on your own, we just write everything to a fresh
string and use this for parsing and inside the HashMap containing the
AST of each known Nix expression.
Not sure if it works out the way I hope, but it seems a little bit
better now. Will test it a while on my setup before I consider this
ready.
* Fix newlines
0 commit comments