Skip to content
Open
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions helix-term/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,8 @@ grep-searcher = "0.1.14"

dashmap = "6.0"

regex = "1"

[target.'cfg(not(windows))'.dependencies] # https://github.com/vorner/signal-hook/issues/100
signal-hook-tokio = { version = "0.3", features = ["futures-v0_3"] }
libc = "0.2.175"
Expand Down
68 changes: 43 additions & 25 deletions helix-term/src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ pub(crate) mod lsp;
pub(crate) mod syntax;
pub(crate) mod typed;

use crate::make::make_picker;
pub use dap::*;
use futures_util::FutureExt;
use helix_event::status;
Expand Down Expand Up @@ -613,6 +614,7 @@ impl MappableCommand {
goto_prev_tabstop, "Goto next snippet placeholder",
rotate_selections_first, "Make the first selection your primary one",
rotate_selections_last, "Make the last selection your primary one",
make_cmd_picker, "MAKE PICKER",
);
}

Expand Down Expand Up @@ -2448,6 +2450,40 @@ fn make_search_word_bounded(cx: &mut Context) {
}
}

// TODO(szulf): is there some more global function like this that doesnt depend on lsp stuff?
pub fn goto_location(
cx: &mut compositor::Context,
path: &PathBuf,
line_num: &usize,
action: Action,
) {
let doc = match cx.editor.open(path, action) {
Ok(id) => doc_mut!(cx.editor, &id),
Err(e) => {
cx.editor
.set_error(format!("Failed to open file '{}': {}", path.display(), e));
return;
}
};

let line_num = *line_num;
let view = view_mut!(cx.editor);
let text = doc.text();
if line_num >= text.len_lines() {
cx.editor.set_error(
"The line you jumped to does not exist anymore because the file has changed.",
);
return;
}
let start = text.line_to_char(line_num);
let end = text.line_to_char((line_num + 1).min(text.len_lines()));

doc.set_selection(view.id, Selection::single(start, end));
if action.align_view(view, doc.id()) {
align_view(doc, view, Align::Center);
}
}

fn global_search(cx: &mut Context) {
#[derive(Debug)]
struct FileResult {
Expand Down Expand Up @@ -2642,31 +2678,7 @@ fn global_search(cx: &mut Context) {
[],
config,
move |cx, FileResult { path, line_num, .. }, action| {
let doc = match cx.editor.open(path, action) {
Ok(id) => doc_mut!(cx.editor, &id),
Err(e) => {
cx.editor
.set_error(format!("Failed to open file '{}': {}", path.display(), e));
return;
}
};

let line_num = *line_num;
let view = view_mut!(cx.editor);
let text = doc.text();
if line_num >= text.len_lines() {
cx.editor.set_error(
"The line you jumped to does not exist anymore because the file has changed.",
);
return;
}
let start = text.line_to_char(line_num);
let end = text.line_to_char((line_num + 1).min(text.len_lines()));

doc.set_selection(view.id, Selection::single(start, end));
if action.align_view(view, doc.id()) {
align_view(doc, view, Align::Center);
}
goto_location(cx, path, line_num, action);
},
)
.with_preview(|_editor, FileResult { path, line_num, .. }| {
Expand Down Expand Up @@ -5370,6 +5382,12 @@ fn rotate_selections_last(cx: &mut Context) {
doc.set_selection(view.id, selection);
}

fn make_cmd_picker(cx: &mut Context) {
let root = find_workspace().0;
let picker = make_picker(cx, root);
cx.push_layer(Box::new(overlaid(picker)));
}

#[derive(Debug)]
enum ReorderStrategy {
RotateForward,
Expand Down
18 changes: 15 additions & 3 deletions helix-term/src/commands/lsp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@ use crate::{
ui::{self, overlay::overlaid, FileLocation, Picker, Popup, PromptEvent},
};

use std::{cmp::Ordering, collections::HashSet, fmt::Display, future::Future, path::Path};
use std::{
cmp::Ordering, collections::HashSet, fmt::Display, future::Future, path::Path, path::PathBuf,
};

/// Gets the first language server that is attached to a document which supports a specific feature.
/// If there is no configured language server that supports the feature, this displays a status message.
Expand All @@ -59,12 +61,22 @@ macro_rules! language_server_with_feature {
/// A wrapper around `lsp::Location` that swaps out the LSP URI for `helix_core::Uri` and adds
/// the server's offset encoding.
#[derive(Debug, Clone, PartialEq, Eq)]
struct Location {
pub struct Location {
uri: Uri,
range: lsp::Range,
offset_encoding: OffsetEncoding,
}

impl Location {
pub fn new(path: PathBuf, range: lsp::Range, offset_encoding: OffsetEncoding) -> Self {
Self {
uri: path.into(),
range: range,
offset_encoding: offset_encoding,
}
}
}

fn lsp_location_to_location(
location: lsp::Location,
offset_encoding: OffsetEncoding,
Expand Down Expand Up @@ -109,7 +121,7 @@ fn location_to_file_location(location: &Location) -> Option<FileLocation> {
Some((path.into(), line))
}

fn jump_to_location(editor: &mut Editor, location: &Location, action: Action) {
pub fn jump_to_location(editor: &mut Editor, location: &Location, action: Action) {
let (view, doc) = current!(editor);
push_jump(view, doc);

Expand Down
52 changes: 52 additions & 0 deletions helix-term/src/commands/typed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use std::io::BufReader;
use std::ops::{self, Deref};

use crate::job::Job;
use crate::make::{self, MakeFormatType};

use super::*;

Expand Down Expand Up @@ -2642,6 +2643,39 @@ fn noop(_cx: &mut compositor::Context, _args: Args, _event: PromptEvent) -> anyh
Ok(())
}

fn make(cx: &mut compositor::Context, args: Args, event: PromptEvent) -> anyhow::Result<()> {
if event != PromptEvent::Validate {
return Ok(());
}

let make_format_type = match args.get_flag("format") {
Some(flag) => MakeFormatType::from(flag),
None => MakeFormatType::Default,
};

let shell = cx.editor.config().shell.clone();
let args = args.join(" ");

let callback = async move {
let output = shell_impl_async(&shell, &args, None).await?;
let call: job::Callback = Callback::EditorCompositor(Box::new(
move |editor: &mut Editor, _compositor: &mut Compositor| {
let entries = make::parse(make_format_type, output.as_str());
let entries_count = entries.len();
editor.make_list.set(entries);
editor.set_status(format!(
"Command run. Filled make list with {} entries.",
entries_count
));
},
));
Ok(call)
};
cx.jobs.callback(callback);

Ok(())
}

/// This command accepts a single boolean --skip-visible flag and no positionals.
const BUFFER_CLOSE_OTHERS_SIGNATURE: Signature = Signature {
positionals: (0, Some(0)),
Expand Down Expand Up @@ -3668,6 +3702,24 @@ pub const TYPABLE_COMMAND_LIST: &[TypableCommand] = &[
..Signature::DEFAULT
},
},
TypableCommand {
name: "make",
aliases: &["mk"],
doc: "Executes the command and fills the make picker with its output.",
fun: make,
completer: SHELL_COMPLETER,
signature: Signature {
flags: &[
Flag {
name: "format",
alias: Some('f'),
doc: "sets the make output format",
completions: Some(&["rust", "gcc", "clang", "msvc"]),
},
],
..SHELL_SIGNATURE
},
},
];

pub static TYPABLE_COMMAND_MAP: Lazy<HashMap<&'static str, &'static TypableCommand>> =
Expand Down
1 change: 1 addition & 0 deletions helix-term/src/keymap/default.rs
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,7 @@ pub fn default() -> HashMap<Mode, KeyTrie> {
"C" => toggle_block_comments,
"A-c" => toggle_line_comments,
"?" => command_palette,
"m" => make_cmd_picker,
},
"z" => { "View"
"z" | "c" => align_view_center,
Expand Down
1 change: 1 addition & 0 deletions helix-term/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ pub mod events;
pub mod health;
pub mod job;
pub mod keymap;
pub mod make;
pub mod ui;

use std::path::Path;
Expand Down
Loading