Skip to content
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

implement translate_offset_with_edit #325

Merged
merged 18 commits into from
Dec 27, 2018

Conversation

vemoo
Copy link
Contributor

@vemoo vemoo commented Dec 23, 2018

  • Implement translate_offset_with_edit to resolve Fix TryConvWith for SourceEdit #105
  • Add proptest impls for text, offsets and edits and use them in tests for translate_offset_with_edit and LineIndex
  • Added benchmark for translate_offset_with_edit

let mut sorted_edits: Vec<&AtomTextEdit> = Vec::with_capacity(edits.len());
for edit in edits {
let insert_index =
sorted_edits.upper_bound_by_key(&edit.delete.start(), |x| x.delete.start());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The TextEdit struct grantees that its AtomicEdits are disjoint and sorted. Can we accept an TextEdit here instead of the slice and avoid the sorting step?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes that makes sense. Although reviewing the code, when translate_offset_with_edit is called we don't have a TextEdit. Here https://github.com/vemoo/rust-analyzer/blob/0156a538089828340a823ed02da8970bf4f1175b/crates/ra_lsp_server/src/conv.rs#L204 the edits come from SourceFileNodeEdit https://github.com/vemoo/rust-analyzer/blob/0156a538089828340a823ed02da8970bf4f1175b/crates/ra_analysis/src/lib.rs#L124

Should we create a new TextEdit before calling translate_offset_with_edit or should SourceFileNodeEdit have a TextEdit?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've changed that to use TextEdit a couple of days ago :-)

https://github.com/rust-analyzer/rust-analyzer/blob/67e768466ff2e2611eead0f30b2e9c4083c80c20/crates/ra_analysis/src/lib.rs#L180

ideally, we should not expose AtomicEdit at all, but we need that precisely to be able to construct LSP edits.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So if you rebase this PR onto the current master it should be ready to go?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, I will do that later today

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've rebased and changed translate_offset_with_edit to accept TextEdit.

line_index::to_line_col(&text, offset)
}

fn edit_text(pre_edit_text: &str, mut edits: Vec<AtomTextEdit>) -> String {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could be TextEdit::apply I think?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I will change it

@matklad
Copy link
Member

matklad commented Dec 24, 2018

Overall, LGTM, however I feel slightly uncomfortable about the inclusion of becnhmarks: it adds a bit of code and quite a few dependencies, but I am not sure that, in the grand scheme of things, translating offsets takes a huge amount of time. I think currently it makes sense to focus on correctness; for performance, we really should start with high level "whole-program" benchmarks to figure out what exactly needs to be optimize.

Would do you think about removing benchmark support for now?

@vemoo
Copy link
Contributor Author

vemoo commented Dec 24, 2018

Yeah, you are right, I'll remove the benchmark. It was mostly so I could see it wasn't slower than the naive method.

@matklad
Copy link
Member

matklad commented Dec 27, 2018

bors r+

Thanks!

bors bot added a commit that referenced this pull request Dec 27, 2018
325: implement translate_offset_with_edit r=matklad a=vemoo

- Implement `translate_offset_with_edit` to resolve #105 
- Add proptest impls for text, offsets and edits and use them in tests for `translate_offset_with_edit` and `LineIndex`
- Added benchmark for `translate_offset_with_edit`

Co-authored-by: Bernardo <berublan@gmail.com>
@bors
Copy link
Contributor

bors bot commented Dec 27, 2018

Build succeeded

@bors bors bot merged commit 1cda43a into rust-lang:master Dec 27, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Fix TryConvWith for SourceEdit
2 participants