-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Add support for incremental text synchronization #4153
Conversation
8cb88db
to
87114ec
Compare
As an aside I'm surprised that this isn't something negotiated by the LSP using client/server caps. It seems weird to me that a client must support all three modes: None, Full and Incremental. |
@lnicola does this improve responsiveness? I would expect the over the wire performance to be negligible but it looks like we avoid a 200ms delay in the vscode client in incremental mode: https://github.com/microsoft/vscode-languageserver-node/blob/e5d7ad881b1a51b486e3f0e4aa0fbc25dad2be58/client/src/client.ts#L1004 |
I can't really tell, I only checked that it works. The type hints seemed pretty snappy, though. But when looking into the Builder failure I tried to sniff the client-server communication and couldn't notice the delay while typing. I hope this won't make RA burn more CPU than before. |
87114ec
to
3d1396f
Compare
I just did a quick smoke test of this and it seems to work. I didn't spot any regressions. |
Does it feel faster? |
The highlighting felt snappier but I was eyeballing it. |
This seems reasonable, though I am not sure if it works correctly with our Let's add some unit-tests here, which create an empty VFS and apply some hard-coded JSONs to it? |
(the vfs PR is published) |
I'm not sure how to structure it, is there another test working with JSON requests like that? Maybe we should add a test to |
3d1396f
to
966fde9
Compare
I mean, the tricky bit here is correctly interpreting I think just extracting this bit into a function and unit-testing it should be possible. The funciton would take two arguments: VFS and a line index, and it would apply changes to VFS. The test would take initial file contents, the I think thre required |
I'm so confused -- I can't really figure out how to use |
Hm, indeed, I think because the scanning happens in background it's not really possible to test this correctly with VFS :-( Here's as far as I got: #[test]
fn smoked_vfs() {
struct All;
impl ra_vfs::Filter for All {
fn include_dir(&self, dir_path: &relative_path::RelativePath) -> bool {
true
}
fn include_file(&self, file_path: &relative_path::RelativePath) -> bool {
true
}
}
let root = RootEntry::new("/dummy".into(), Box::new(All));
let (mut vfs, vfs_roots) =
Vfs::new(vec![root], Box::new(|task| drop(task) /* :-( */), Watch(false));
let file_id = vfs.add_file_overlay(Path::new("/dummy/foo.rs"), "fn main() {}".into()).unwrap();
let changes = vfs.commit_changes();
match changes.as_slice() {
[VfsChange::AddFile { text, .. }] => text.as_str() == "fn main() {}",
changes => panic!("{:?}", changes),
};
vfs.change_file_overlay(Path::new("/dummy/foo.rs"), "fn bar() {}".into());
vfs.commit_changes();
match changes.as_slice() {
[VfsChange::ChangeFile { text, .. }] => text.as_str() == "fn main() {}",
changes => panic!("{:?}", changes),
};
} But perhaps we don't even need VFS at all? it seems like fn apply_change(chage: lsp_types::TextDocumentChange, original_text: &mut String, line_endings: LineEndings) Should actually be enough there? What I am trying to test here is that we correctly interpret |
I've been worried about this from the start -- I'm not sure how we're supposed to handle multiple changed, maybe we should take a look at other language servers. One thing I noticed is that Code tries to sort the ranges in reverse, so they don't conflict. I didn't test inserting multiple newlines, but it might work. |
microsoft/language-server-protocol#289 applying the changes in order seems to be correct. |
Yes, they need to be applied in order, but the question is, will the offsets shift? The wont', if the changes are indeed reveres-sorted, but that's not a part of the protocol :-( |
I think that's a question for @dbaeumer.
…On Thu, Apr 30, 2020, 6:22 AM Aleksey Kladov ***@***.***> wrote:
applying the changes in order seems to be correct.
Yes, they need to be applied in order, but the question is, will the
offsets shift? The wont', if the changes are indeed reveres-sorted, but
that's not a part of the protocol :-(
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#4153 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ABBACREFMOXRQ63XL4L3CXDRPFGQDANCNFSM4MRD5VJA>
.
|
Just to make sure I got it right: if a file changes, we invalidate the line index at the turn of the main loop, so we're worried about it becoming stale while we're applying the updates? And if the ranges are sorted backwards, it's not an issue. |
Right. Specifically, let's say we start with an empty file, and the first edit added adds three The correct (albeit inneficient) algorithm would be:
|
I checked a couple of implementations:
|
17a74c9
to
24ad8e1
Compare
24ad8e1
to
015d274
Compare
015d274
to
1a2d4e2
Compare
bors d+ We can add a temporary flag to config, to allow users to opt-out if this misbehaves (and I think this can misbehave both due to our bugs, and due to client bugs). OTOH, I am also ok with merging this as is, so, at your discretion. |
✌️ lnicola can now approve this pull request. To approve and merge a pull request, simply reply with |
The capabilities seem to be sent right from the start, so I'm not sure how we can disable incremental sync by configuration. Let's merge it and we can disable it before Monday if anyone complains. bors r=matklad |
Build succeeded: |
The capabilities thing is a bug in lsp-server (see rust-analyzer/lsp-server#14) so I think we could look at the initial params or experimental client caps and change the mode if we need to. |
Do you still need an answer on this: #4153 (comment)
Should explain everything. |
Fixes #3762.
This still needs a
ra_vfs
PR, but I want to know I'm on the right track. I tested the change and it didn't crash horribly, but YMMV.