Skip to content

Commit

Permalink
Merge branch 'master' into multiple-language-servers
Browse files Browse the repository at this point in the history
  • Loading branch information
Philipp-M committed May 22, 2022
2 parents f2ee673 + 682bcc3 commit 5bb5e8c
Show file tree
Hide file tree
Showing 40 changed files with 1,071 additions and 138 deletions.
1 change: 0 additions & 1 deletion base16_theme.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
"comment" = { fg = "gray" }
"ui.statusline" = { fg = "black", bg = "white" }
"ui.statusline.inactive" = { fg = "gray", bg = "white" }
"ui.help" = { modifiers = ["reversed"] }
"ui.cursor" = { fg = "white", modifiers = ["reversed"] }
"variable" = "red"
"constant.numeric" = "yellow"
Expand Down
4 changes: 3 additions & 1 deletion book/src/generated/lang-support.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
| heex || | | |
| html || | | `vscode-html-language-server` |
| iex || | | |
| java || | | |
| java || | | `jdtls` |
| javascript || || `typescript-language-server` |
| json || || `vscode-json-language-server` |
| jsx || || `typescript-language-server` |
Expand Down Expand Up @@ -76,8 +76,10 @@
| ruby |||| `solargraph` |
| rust |||| `rust-analyzer` |
| scala || || `metals` |
| scheme || | | |
| solidity || | | `solc` |
| sql || | | |
| sshclientconfig || | | |
| svelte || || `svelteserver` |
| swift || | | `sourcekit-lsp` |
| tablegen |||| |
Expand Down
2 changes: 2 additions & 0 deletions book/src/keymap.md
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@
| `%` | Select entire file | `select_all` |
| `x` | Select current line, if already selected, extend to next line | `extend_line` |
| `X` | Extend selection to line bounds (line-wise selection) | `extend_to_line_bounds` |
| `Alt-x` | Shrink selection to line bounds (line-wise selection) | `shrink_to_line_bounds` |
| `J` | Join lines inside selection | `join_selections` |
| `K` | Keep selections matching the regex | `keep_selections` |
| `Alt-K` | Remove selections matching the regex | `remove_selections` |
Expand Down Expand Up @@ -367,6 +368,7 @@ Keys to use within prompt, Remapping currently not supported.
| `Ctrl-s` | Insert a word under doc cursor, may be changed to Ctrl-r Ctrl-w later |
| `Ctrl-p`, `Up` | Select previous history |
| `Ctrl-n`, `Down` | Select next history |
| `Ctrl-r` | Insert the content of the register selected by following input char |
| `Tab` | Select next completion item |
| `BackTab` | Select previous completion item |
| `Enter` | Open selected |
Expand Down
65 changes: 35 additions & 30 deletions book/src/themes.md
Original file line number Diff line number Diff line change
Expand Up @@ -205,35 +205,40 @@ These scopes are used for theming the editor interface.
- `hover` - for hover popup ui


| Key | Notes |
| --- | --- |
| `ui.background` | |
| `ui.cursor` | |
| `ui.cursor.insert` | |
| `ui.cursor.select` | |
| `ui.cursor.match` | Matching bracket etc. |
| `ui.cursor.primary` | Cursor with primary selection |
| `ui.linenr` | Line numbers |
| `ui.linenr.selected` | Line number for the line the cursor is on |
| `ui.statusline` | Statusline |
| `ui.statusline.inactive` | Statusline (unfocused document) |
| `ui.popup` | Documentation popups (e.g space-k) |
| `ui.popup.info` | Prompt for multiple key options |
| `ui.window` | Border lines separating splits |
| `ui.help` | Description box for commands |
| `ui.text` | Command prompts, popup text, etc. |
| `ui.text.focus` | |
| `ui.text.info` | The key: command text in `ui.popup.info` boxes |
| `ui.virtual.ruler` | Ruler columns (see the [`editor.rulers` config][rulers-config])|
| `ui.virtual.whitespace` | Visible white-space characters |
| `ui.menu` | Code and command completion menus |
| `ui.menu.selected` | Selected autocomplete item |
| `ui.selection` | For selections in the editing area |
| `ui.selection.primary` | |
| `warning` | Diagnostics warning (gutter) |
| `error` | Diagnostics error (gutter) |
| `info` | Diagnostics info (gutter) |
| `hint` | Diagnostics hint (gutter) |
| `diagnostic` | For text in editing area |
| Key | Notes |
| --- | --- |
| `ui.background` | |
| `ui.background.separator` | Picker separator below input line |
| `ui.cursor` | |
| `ui.cursor.insert` | |
| `ui.cursor.select` | |
| `ui.cursor.match` | Matching bracket etc. |
| `ui.cursor.primary` | Cursor with primary selection |
| `ui.linenr` | Line numbers |
| `ui.linenr.selected` | Line number for the line the cursor is on |
| `ui.statusline` | Statusline |
| `ui.statusline.inactive` | Statusline (unfocused document) |
| `ui.popup` | Documentation popups (e.g space-k) |
| `ui.popup.info` | Prompt for multiple key options |
| `ui.window` | Border lines separating splits |
| `ui.help` | Description box for commands |
| `ui.text` | Command prompts, popup text, etc. |
| `ui.text.focus` | |
| `ui.text.info` | The key: command text in `ui.popup.info` boxes |
| `ui.virtual.ruler` | Ruler columns (see the [`editor.rulers` config][rulers-config])|
| `ui.virtual.whitespace` | Visible white-space characters |
| `ui.menu` | Code and command completion menus |
| `ui.menu.selected` | Selected autocomplete item |
| `ui.selection` | For selections in the editing area |
| `ui.selection.primary` | |
| `warning` | Diagnostics warning (gutter) |
| `error` | Diagnostics error (gutter) |
| `info` | Diagnostics info (gutter) |
| `hint` | Diagnostics hint (gutter) |
| `diagnostic` | Diagnostics fallback style (editing area) |
| `diagnostic.hint` | Diagnostics hint (editing area) |
| `diagnostic.info` | Diagnostics info (editing area) |
| `diagnostic.warning` | Diagnostics warning (editing area) |
| `diagnostic.error` | Diagnostics error (editing area) |

[rulers-config]: ./configuration.md#editor-section
52 changes: 27 additions & 25 deletions helix-core/src/syntax.rs
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,7 @@ pub struct TextObjectQuery {
pub query: Query,
}

#[derive(Debug)]
pub enum CapturedNode<'a> {
Single(Node<'a>),
/// Guaranteed to be not empty
Expand Down Expand Up @@ -269,12 +270,12 @@ impl TextObjectQuery {
/// and support for this is partial and could use improvement.
///
/// ```query
/// ;; supported:
/// (comment)+ @capture
///
/// ;; unsupported:
/// ; OR
/// (
/// (comment)+
/// (comment)*
/// .
/// (function)
/// ) @capture
/// ```
Expand All @@ -300,28 +301,29 @@ impl TextObjectQuery {
let capture_idx = capture_names
.iter()
.find_map(|cap| self.query.capture_index_for_name(cap))?;
let captures = cursor.matches(&self.query, node, RopeProvider(slice));

let nodes = captures.flat_map(move |mat| {
let captures = mat.captures.iter().filter(move |c| c.index == capture_idx);
let nodes = captures.map(|c| c.node);
let pattern_idx = mat.pattern_index;
let quantifier = self.query.capture_quantifiers(pattern_idx)[capture_idx as usize];

let iter: Box<dyn Iterator<Item = CapturedNode>> = match quantifier {
CaptureQuantifier::OneOrMore | CaptureQuantifier::ZeroOrMore => {
let nodes: Vec<Node> = nodes.collect();
if nodes.is_empty() {
Box::new(std::iter::empty())
} else {
Box::new(std::iter::once(CapturedNode::Grouped(nodes)))
}

let nodes = cursor
.captures(&self.query, node, RopeProvider(slice))
.filter_map(move |(mat, _)| {
let nodes: Vec<_> = mat
.captures
.iter()
.filter_map(|x| {
if x.index == capture_idx {
Some(x.node)
} else {
None
}
})
.collect();

if nodes.len() > 1 {
Some(CapturedNode::Grouped(nodes))
} else {
nodes.into_iter().map(CapturedNode::Single).next()
}
_ => Box::new(nodes.map(CapturedNode::Single)),
};
});

iter
});
Some(nodes)
}
}
Expand Down Expand Up @@ -1123,8 +1125,8 @@ pub(crate) fn generate_edits(
use std::sync::atomic::{AtomicUsize, Ordering};
use std::{iter, mem, ops, str, usize};
use tree_sitter::{
CaptureQuantifier, Language as Grammar, Node, Parser, Point, Query, QueryCaptures, QueryCursor,
QueryError, QueryMatch, Range, TextProvider, Tree,
Language as Grammar, Node, Parser, Point, Query, QueryCaptures, QueryCursor, QueryError,
QueryMatch, Range, TextProvider, Tree,
};

const CANCELLATION_CHECK_INTERVAL: usize = 100;
Expand Down
71 changes: 69 additions & 2 deletions helix-term/src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,7 @@ impl MappableCommand {
extend_line, "Select current line, if already selected, extend to next line",
extend_line_above, "Select current line, if already selected, extend to previous line",
extend_to_line_bounds, "Extend selection to line bounds (line-wise selection)",
shrink_to_line_bounds, "Shrink selection to line bounds (line-wise selection)",
delete_selection, "Delete selection",
delete_selection_noyank, "Delete selection, without yanking",
change_selection, "Change selection (delete and enter insert mode)",
Expand Down Expand Up @@ -360,6 +361,11 @@ impl MappableCommand {
jump_view_left, "Jump to the split to the left",
jump_view_up, "Jump to the split above",
jump_view_down, "Jump to the split below",
swap_view_right, "Swap with the split to the right",
swap_view_left, "Swap with the split to the left",
swap_view_up, "Swap with the split above",
swap_view_down, "Swap with the split below",
transpose_view, "Transpose splits",
rotate_view, "Goto next window",
hsplit, "Horizontal bottom split",
hsplit_new, "Horizontal bottom split scratch buffer",
Expand Down Expand Up @@ -1224,11 +1230,11 @@ fn replace(cx: &mut Context) {
// need to wait for next key
cx.on_next_key(move |cx, event| {
let (view, doc) = current!(cx.editor);
let ch = match event {
let ch: Option<&str> = match event {
KeyEvent {
code: KeyCode::Char(ch),
..
} => Some(&ch.encode_utf8(&mut buf[..])[..]),
} => Some(ch.encode_utf8(&mut buf[..])),
KeyEvent {
code: KeyCode::Enter,
..
Expand Down Expand Up @@ -1937,6 +1943,47 @@ fn extend_to_line_bounds(cx: &mut Context) {
);
}

fn shrink_to_line_bounds(cx: &mut Context) {
let (view, doc) = current!(cx.editor);

doc.set_selection(
view.id,
doc.selection(view.id).clone().transform(|range| {
let text = doc.text();

let (start_line, end_line) = range.line_range(text.slice(..));

// Do nothing if the selection is within one line to prevent
// conditional logic for the behavior of this command
if start_line == end_line {
return range;
}

let mut start = text.line_to_char(start_line);

// line_to_char gives us the start position of the line, so
// we need to get the start position of the next line. In
// the editor, this will correspond to the cursor being on
// the EOL whitespace charactor, which is what we want.
let mut end = text.line_to_char((end_line + 1).min(text.len_lines()));

if start != range.from() {
start = text.line_to_char((start_line + 1).min(text.len_lines()));
}

if end != range.to() {
end = text.line_to_char(end_line);
}

if range.anchor <= range.head {
Range::new(start, end)
} else {
Range::new(end, start)
}
}),
);
}

enum Operation {
Delete,
Change,
Expand Down Expand Up @@ -3860,6 +3907,26 @@ fn jump_view_down(cx: &mut Context) {
cx.editor.focus_down()
}

fn swap_view_right(cx: &mut Context) {
cx.editor.swap_right()
}

fn swap_view_left(cx: &mut Context) {
cx.editor.swap_left()
}

fn swap_view_up(cx: &mut Context) {
cx.editor.swap_up()
}

fn swap_view_down(cx: &mut Context) {
cx.editor.swap_down()
}

fn transpose_view(cx: &mut Context) {
cx.editor.transpose_view()
}

// split helper, clear it later
fn split(cx: &mut Context, action: Action) {
let (view, doc) = current!(cx.editor);
Expand Down
5 changes: 4 additions & 1 deletion helix-term/src/commands/typed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -781,8 +781,11 @@ fn reload(
_args: &[Cow<str>],
_event: PromptEvent,
) -> anyhow::Result<()> {
let scrolloff = cx.editor.config().scrolloff;
let (view, doc) = current!(cx.editor);
doc.reload(view.id)
doc.reload(view.id).map(|_| {
view.ensure_cursor_in_view(doc, scrolloff);
})
}

fn tree_sitter_scopes(
Expand Down
12 changes: 11 additions & 1 deletion helix-term/src/keymap/default.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ pub fn default() -> HashMap<Mode, Keymap> {
"%" => select_all,
"x" => extend_line,
"X" => extend_to_line_bounds,
// crop_to_whole_line
"A-x" => shrink_to_line_bounds,

"m" => { "Match"
"m" => match_brackets,
Expand Down Expand Up @@ -171,6 +171,7 @@ pub fn default() -> HashMap<Mode, Keymap> {
"C-w" | "w" => rotate_view,
"C-s" | "s" => hsplit,
"C-v" | "v" => vsplit,
"C-t" | "t" => transpose_view,
"f" => goto_file_hsplit,
"F" => goto_file_vsplit,
"C-q" | "q" => wclose,
Expand All @@ -179,6 +180,10 @@ pub fn default() -> HashMap<Mode, Keymap> {
"C-j" | "j" | "down" => jump_view_down,
"C-k" | "k" | "up" => jump_view_up,
"C-l" | "l" | "right" => jump_view_right,
"L" => swap_view_right,
"K" => swap_view_up,
"H" => swap_view_left,
"J" => swap_view_down,
"n" => { "New split scratch buffer"
"C-s" | "s" => hsplit_new,
"C-v" | "v" => vsplit_new,
Expand Down Expand Up @@ -226,6 +231,7 @@ pub fn default() -> HashMap<Mode, Keymap> {
"C-w" | "w" => rotate_view,
"C-s" | "s" => hsplit,
"C-v" | "v" => vsplit,
"C-t" | "t" => transpose_view,
"f" => goto_file_hsplit,
"F" => goto_file_vsplit,
"C-q" | "q" => wclose,
Expand All @@ -234,6 +240,10 @@ pub fn default() -> HashMap<Mode, Keymap> {
"C-j" | "j" | "down" => jump_view_down,
"C-k" | "k" | "up" => jump_view_up,
"C-l" | "l" | "right" => jump_view_right,
"H" => swap_view_left,
"J" => swap_view_down,
"K" => swap_view_up,
"L" => swap_view_right,
"n" => { "New split scratch buffer"
"C-s" | "s" => hsplit_new,
"C-v" | "v" => vsplit_new,
Expand Down
Loading

0 comments on commit 5bb5e8c

Please sign in to comment.