Skip to content

Commit

Permalink
Fix fwd search regression when formatting on save
Browse files Browse the repository at this point in the history
See #880.
  • Loading branch information
pfoerster committed Apr 29, 2023
1 parent 7fb38fa commit b61313e
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Fixed

- Fix spurious completion results when completing environments ([#883](https://github.com/latex-lsp/texlab/issues/883))
- Fix regression when guessing cursor position after formatting ([#880](https://github.com/latex-lsp/texlab/issues/880))

## [5.5.0] - 2023-04-16

Expand Down
17 changes: 16 additions & 1 deletion crates/texlab/src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ use base_db::{Config, Owner, Workspace};
use commands::{BuildCommand, CleanCommand, CleanTarget, ForwardSearch};
use crossbeam_channel::{Receiver, Sender};
use distro::{Distro, Language};
use itertools::{FoldWhile, Itertools};
use lsp_server::{Connection, ErrorCode, Message, RequestId};
use lsp_types::{notification::*, request::*, *};
use parking_lot::{Mutex, RwLock};
Expand Down Expand Up @@ -387,13 +388,27 @@ impl Server {
}
None => {
let language = document.language;
let line_col = document.line_index.line_col(document.cursor);

let (_, new_cursor) = change
.text
.lines()
.fold_while((0, 0), |(number, index), line| {
if number == line_col.line {
FoldWhile::Done((number, index))
} else {
itertools::FoldWhile::Continue((number + 1, index + line.len()))
}
})
.into_inner();

drop(document);
workspace.open(
uri.clone(),
change.text,
language,
Owner::Client,
TextSize::default(),
TextSize::from(new_cursor as u32),
);
}
};
Expand Down

0 comments on commit b61313e

Please sign in to comment.