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

Impelement reload-all command #2476

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions helix-term/src/commands/typed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -785,6 +785,19 @@ fn reload(
doc.reload(view.id)
}

fn reload_all(
cx: &mut compositor::Context,
_args: &[Cow<str>],
_event: PromptEvent,
) -> anyhow::Result<()> {
for doc in cx.editor.documents_mut() {
doc.selections().keys().for_each(|view_id| {
doc.reload(*view_id);
Copy link
Member

Choose a reason for hiding this comment

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

You shouldn't be calling reload() multiple times since it'll reload the file from disk on each call. Instead reload should be called with a single view (pick one at random)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The reload method seems to be updating selections belonging to that view as well as history, does that not matter? I thought about refactoring the internal methods (apply, etc) to be view agnostic, but maybe they should loop through all views instead of doing it here?

});
}
Ok(())
}

fn tree_sitter_scopes(
cx: &mut compositor::Context,
_args: &[Cow<str>],
Expand Down Expand Up @@ -1523,6 +1536,13 @@ pub const TYPABLE_COMMAND_LIST: &[TypableCommand] = &[
fun: reload,
completer: None,
},
TypableCommand {
name: "reload-all",
aliases: &[],
doc: "Discard changes and reload all buffers from the source file.",
fun: reload_all,
completer: None,
},
TypableCommand {
name: "tree-sitter-scopes",
aliases: &[],
Expand Down