summaryrefslogtreecommitdiff
path: root/helix-term/src/commands.rs
diff options
context:
space:
mode:
authorSkyler Hawthorne2022-10-21 07:43:22 +0000
committerGitHub2022-10-21 07:43:22 +0000
commit5a848344a9b6f476922ea004e6a7f5b6d32ef768 (patch)
tree6e5fcfb5a80bb188393a011f6a99e93c985f1026 /helix-term/src/commands.rs
parentbad49ef2d095cca88a9e0bd39da329b86bda3d75 (diff)
fix: write-all crash (#4384)
When we do auto formatting, the code that takes the LSP's response and applies the changes to the document are just getting the currently focused view and giving that to the function, basically always assuming that the document that we're applying the change to is in focus, and not in a background view. This is usually fine for a single view, even if it's a buffer in the background, because it's still the same view and the selection will get updated accordingly for when you switch back to it. But it's obviously a problem for when there are multiple views, because if you don't have the target document in focus, it will ask the document to update the wrong view, hence the crash. The problem with this is picking which view to apply any selection change to. In the absence of any more data points on the views themselves, we simply pick the first view associated with the document we are saving.
Diffstat (limited to 'helix-term/src/commands.rs')
-rw-r--r--helix-term/src/commands.rs5
1 files changed, 3 insertions, 2 deletions
diff --git a/helix-term/src/commands.rs b/helix-term/src/commands.rs
index c5ee72d2..e44b851e 100644
--- a/helix-term/src/commands.rs
+++ b/helix-term/src/commands.rs
@@ -2515,19 +2515,20 @@ fn insert_at_line_end(cx: &mut Context) {
async fn make_format_callback(
doc_id: DocumentId,
doc_version: i32,
+ view_id: ViewId,
format: impl Future<Output = Result<Transaction, FormatterError>> + Send + 'static,
write: Option<(Option<PathBuf>, bool)>,
) -> anyhow::Result<job::Callback> {
let format = format.await;
let call: job::Callback = Callback::Editor(Box::new(move |editor| {
- if !editor.documents.contains_key(&doc_id) {
+ if !editor.documents.contains_key(&doc_id) || !editor.tree.contains(view_id) {
return;
}
let scrolloff = editor.config().scrolloff;
let doc = doc_mut!(editor, &doc_id);
- let view = view_mut!(editor);
+ let view = view_mut!(editor, view_id);
if let Ok(format) = format {
if doc.version() == doc_version {