Skip to content

Commit

Permalink
configurable nodes, remove separator
Browse files Browse the repository at this point in the history
  • Loading branch information
matoous committed Oct 12, 2022
1 parent dcaf681 commit 440c940
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 18 deletions.
3 changes: 3 additions & 0 deletions helix-core/src/syntax.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,9 @@ pub struct LanguageConfiguration {
pub auto_pairs: Option<AutoPairs>,

pub rulers: Option<Vec<u16>>, // if set, override editor's rulers

/// List of LSP nodes that should be displayed in the sticky context.
pub sticky_context_nodes: Option<Vec<String>>,
}

#[derive(Debug, Serialize, Deserialize)]
Expand Down
23 changes: 8 additions & 15 deletions helix-term/src/ui/editor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ impl EditorView {
&editor.config(),
);

if editor.config().lsp.context {
if editor.config().sticky_context {
Self::render_context(editor, doc, view, surface, theme);
}

Expand Down Expand Up @@ -429,6 +429,9 @@ impl EditorView {
let text = doc.text().slice(..);
let tree = syntax.tree();
let byte = doc.selection(view.id).primary().cursor(text);
let nodes_to_match = doc
.language_config()
.and_then(|lc| lc.sticky_context_nodes.as_ref());

let mut parent = tree
.root_node()
Expand All @@ -448,7 +451,10 @@ impl EditorView {
}
}

context.push(line);
if nodes_to_match.map_or(true, |nodes| nodes.iter().any(|n| n == curr.kind())) {
context.push(line);
}

parent = curr.parent();
}

Expand All @@ -460,7 +466,6 @@ impl EditorView {
let mut context_area = view.inner_area();
context_area.height = 1;

let mut last_line = 0;
for line_num in context {
if line_num > view.offset.row {
continue;
Expand All @@ -480,19 +485,7 @@ impl EditorView {
);

context_area.y += 1;
last_line = line_num;
}

surface.clear_with(context_area, context_style);
let text_style = theme.get("ui.text");
let last_line = text.get_line(last_line).unwrap();
let padding = last_line.chars().take_while(|&c| c == ' ').count();
surface.set_string(
context_area.x,
context_area.y,
format!("{} context ----", " ".repeat(padding)),
text_style,
);
}
}

Expand Down
6 changes: 3 additions & 3 deletions helix-view/src/editor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,8 @@ pub struct Config {
pub indent_guides: IndentGuidesConfig,
/// Whether to color modes with different colors. Defaults to `false`.
pub color_modes: bool,
/// Display context of current cursor line if it is outside the view.
pub sticky_context: bool,
}

#[derive(Debug, Default, Clone, PartialEq, Serialize, Deserialize)]
Expand Down Expand Up @@ -234,8 +236,6 @@ pub struct LspConfig {
pub auto_signature_help: bool,
/// Display docs under signature help popup
pub display_signature_help_docs: bool,
/// Display context of current cursor line if it is outside the view.
pub context: bool,
}

impl Default for LspConfig {
Expand All @@ -244,7 +244,6 @@ impl Default for LspConfig {
display_messages: false,
auto_signature_help: true,
display_signature_help_docs: true,
context: false,
}
}
}
Expand Down Expand Up @@ -608,6 +607,7 @@ impl Default for Config {
bufferline: BufferLine::default(),
indent_guides: IndentGuidesConfig::default(),
color_modes: false,
sticky_context: false,
}
}
}
Expand Down
1 change: 1 addition & 0 deletions languages.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ auto-format = true
comment-token = "//"
language-server = { command = "rust-analyzer" }
indent = { tab-width = 4, unit = " " }
sticky-context-nodes = ["impl_item", "function_item", "struct_item", "enum_item", "match_expression", "match_arm", "let_declaration"]

[language.auto-pairs]
'(' = ')'
Expand Down

0 comments on commit 440c940

Please sign in to comment.