From dfa5382c51978c6a582d4586c65aa0f677be2ee8 Mon Sep 17 00:00:00 2001 From: Ryan Mehri <52933714+rmehri01@users.noreply.github.com> Date: Sun, 25 Feb 2024 02:37:54 -0800 Subject: [PATCH 001/114] Don't run scheduled builds on forks (#9718) --- .github/workflows/build.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 3d47c2088..7ba46ce56 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -12,6 +12,7 @@ jobs: check: name: Check (msrv) runs-on: ubuntu-latest + if: github.repository == 'helix-editor/helix' || github.event_name != 'schedule' steps: - name: Checkout sources uses: actions/checkout@v4 @@ -31,6 +32,7 @@ jobs: test: name: Test Suite runs-on: ${{ matrix.os }} + if: github.repository == 'helix-editor/helix' || github.event_name != 'schedule' env: RUST_BACKTRACE: 1 HELIX_LOG_LEVEL: info @@ -65,6 +67,7 @@ jobs: lints: name: Lints runs-on: ubuntu-latest + if: github.repository == 'helix-editor/helix' || github.event_name != 'schedule' steps: - name: Checkout sources uses: actions/checkout@v4 @@ -92,6 +95,7 @@ jobs: docs: name: Docs runs-on: ubuntu-latest + if: github.repository == 'helix-editor/helix' || github.event_name != 'schedule' steps: - name: Checkout sources uses: actions/checkout@v4 From 8141a4a1ab78084df94c19e6225fc3c64a05b88f Mon Sep 17 00:00:00 2001 From: Michael Davis Date: Sun, 27 Aug 2023 13:32:17 -0500 Subject: [PATCH 002/114] LSP: Key diagnostics off file path instead of URI URIs need to be normalized to be comparable. For example a language server could send a URI for a path containing '+' as '%2B' but we might encode this in something like 'Document::url' as just '+'. We can normalize the URI straight into a PathBuf though since this is the only value we compare these diagnostics URIs against. This also covers edge-cases like windows drive letter capitalization. --- helix-term/src/application.rs | 6 +-- helix-term/src/commands/lsp.rs | 72 ++++++++++++++++------------------ helix-view/src/editor.rs | 9 ++--- 3 files changed, 39 insertions(+), 48 deletions(-) diff --git a/helix-term/src/application.rs b/helix-term/src/application.rs index 30df3981c..0ef200c2f 100644 --- a/helix-term/src/application.rs +++ b/helix-term/src/application.rs @@ -753,9 +753,7 @@ impl Application { let lang_conf = doc.language.clone(); if let Some(lang_conf) = &lang_conf { - if let Some(old_diagnostics) = - self.editor.diagnostics.get(¶ms.uri) - { + if let Some(old_diagnostics) = self.editor.diagnostics.get(&path) { if !lang_conf.persistent_diagnostic_sources.is_empty() { // Sort diagnostics first by severity and then by line numbers. // Note: The `lsp::DiagnosticSeverity` enum is already defined in decreasing order @@ -788,7 +786,7 @@ impl Application { // Insert the original lsp::Diagnostics here because we may have no open document // for diagnosic message and so we can't calculate the exact position. // When using them later in the diagnostics picker, we calculate them on-demand. - let diagnostics = match self.editor.diagnostics.entry(params.uri) { + let diagnostics = match self.editor.diagnostics.entry(path) { Entry::Occupied(o) => { let current_diagnostics = o.into_mut(); // there may entries of other language servers, which is why we can't overwrite the whole entry diff --git a/helix-term/src/commands/lsp.rs b/helix-term/src/commands/lsp.rs index a1f7bf17d..a3168dc2d 100644 --- a/helix-term/src/commands/lsp.rs +++ b/helix-term/src/commands/lsp.rs @@ -38,7 +38,7 @@ use std::{ collections::{BTreeMap, HashSet}, fmt::Write, future::Future, - path::PathBuf, + path::{Path, PathBuf}, }; /// Gets the first language server that is attached to a document which supports a specific feature. @@ -134,7 +134,7 @@ struct DiagnosticStyles { } struct PickerDiagnostic { - url: lsp::Url, + path: PathBuf, diag: lsp::Diagnostic, offset_encoding: OffsetEncoding, } @@ -167,8 +167,7 @@ impl ui::menu::Item for PickerDiagnostic { let path = match format { DiagnosticsFormat::HideSourcePath => String::new(), DiagnosticsFormat::ShowSourcePath => { - let file_path = self.url.to_file_path().unwrap(); - let path = path::get_truncated_path(file_path); + let path = path::get_truncated_path(&self.path); format!("{}: ", path.to_string_lossy()) } }; @@ -208,24 +207,33 @@ fn jump_to_location( return; } }; + jump_to_position(editor, &path, location.range, offset_encoding, action); +} - let doc = match editor.open(&path, action) { +fn jump_to_position( + editor: &mut Editor, + path: &Path, + range: lsp::Range, + offset_encoding: OffsetEncoding, + action: Action, +) { + let doc = match editor.open(path, action) { Ok(id) => doc_mut!(editor, &id), Err(err) => { - let err = format!("failed to open path: {:?}: {:?}", location.uri, err); + let err = format!("failed to open path: {:?}: {:?}", path, err); editor.set_error(err); return; } }; let view = view_mut!(editor); // TODO: convert inside server - let new_range = - if let Some(new_range) = lsp_range_to_range(doc.text(), location.range, offset_encoding) { - new_range - } else { - log::warn!("lsp position out of bounds - {:?}", location.range); - return; - }; + let new_range = if let Some(new_range) = lsp_range_to_range(doc.text(), range, offset_encoding) + { + new_range + } else { + log::warn!("lsp position out of bounds - {:?}", range); + return; + }; // we flip the range so that the cursor sits on the start of the symbol // (for example start of the function). doc.set_selection(view.id, Selection::single(new_range.head, new_range.anchor)); @@ -258,21 +266,20 @@ enum DiagnosticsFormat { fn diag_picker( cx: &Context, - diagnostics: BTreeMap>, - _current_path: Option, + diagnostics: BTreeMap>, format: DiagnosticsFormat, ) -> Picker { // TODO: drop current_path comparison and instead use workspace: bool flag? // flatten the map to a vec of (url, diag) pairs let mut flat_diag = Vec::new(); - for (url, diags) in diagnostics { + for (path, diags) in diagnostics { flat_diag.reserve(diags.len()); for (diag, ls) in diags { if let Some(ls) = cx.editor.language_server_by_id(ls) { flat_diag.push(PickerDiagnostic { - url: url.clone(), + path: path.clone(), diag, offset_encoding: ls.offset_encoding(), }); @@ -292,22 +299,17 @@ fn diag_picker( (styles, format), move |cx, PickerDiagnostic { - url, + path, diag, offset_encoding, }, action| { - jump_to_location( - cx.editor, - &lsp::Location::new(url.clone(), diag.range), - *offset_encoding, - action, - ) + jump_to_position(cx.editor, path, diag.range, *offset_encoding, action) }, ) - .with_preview(move |_editor, PickerDiagnostic { url, diag, .. }| { - let location = lsp::Location::new(url.clone(), diag.range); - Some(location_to_file_location(&location)) + .with_preview(move |_editor, PickerDiagnostic { path, diag, .. }| { + let line = Some((diag.range.start.line as usize, diag.range.end.line as usize)); + Some((path.clone().into(), line)) }) .truncate_start(false) } @@ -470,17 +472,16 @@ pub fn workspace_symbol_picker(cx: &mut Context) { pub fn diagnostics_picker(cx: &mut Context) { let doc = doc!(cx.editor); - if let Some(current_url) = doc.url() { + if let Some(current_path) = doc.path() { let diagnostics = cx .editor .diagnostics - .get(¤t_url) + .get(current_path) .cloned() .unwrap_or_default(); let picker = diag_picker( cx, - [(current_url.clone(), diagnostics)].into(), - Some(current_url), + [(current_path.clone(), diagnostics)].into(), DiagnosticsFormat::HideSourcePath, ); cx.push_layer(Box::new(overlaid(picker))); @@ -488,16 +489,9 @@ pub fn diagnostics_picker(cx: &mut Context) { } pub fn workspace_diagnostics_picker(cx: &mut Context) { - let doc = doc!(cx.editor); - let current_url = doc.url(); // TODO not yet filtered by LanguageServerFeature, need to do something similar as Document::shown_diagnostics here for all open documents let diagnostics = cx.editor.diagnostics.clone(); - let picker = diag_picker( - cx, - diagnostics, - current_url, - DiagnosticsFormat::ShowSourcePath, - ); + let picker = diag_picker(cx, diagnostics, DiagnosticsFormat::ShowSourcePath); cx.push_layer(Box::new(overlaid(picker))); } diff --git a/helix-view/src/editor.rs b/helix-view/src/editor.rs index fffbe6207..f46a0d6a6 100644 --- a/helix-view/src/editor.rs +++ b/helix-view/src/editor.rs @@ -914,7 +914,7 @@ pub struct Editor { pub macro_recording: Option<(char, Vec)>, pub macro_replaying: Vec, pub language_servers: helix_lsp::Registry, - pub diagnostics: BTreeMap>, + pub diagnostics: BTreeMap>, pub diff_providers: DiffProviderRegistry, pub debugger: Option, @@ -1815,7 +1815,7 @@ impl Editor { /// Returns all supported diagnostics for the document pub fn doc_diagnostics<'a>( language_servers: &'a helix_lsp::Registry, - diagnostics: &'a BTreeMap>, + diagnostics: &'a BTreeMap>, document: &Document, ) -> impl Iterator + 'a { Editor::doc_diagnostics_with_filter(language_servers, diagnostics, document, |_, _| true) @@ -1825,7 +1825,7 @@ impl Editor { /// filtered by `filter` which is invocated with the raw `lsp::Diagnostic` and the language server id it came from pub fn doc_diagnostics_with_filter<'a>( language_servers: &'a helix_lsp::Registry, - diagnostics: &'a BTreeMap>, + diagnostics: &'a BTreeMap>, document: &Document, filter: impl Fn(&lsp::Diagnostic, usize) -> bool + 'a, @@ -1834,8 +1834,7 @@ impl Editor { let language_config = document.language.clone(); document .path() - .and_then(|path| url::Url::from_file_path(path).ok()) // TODO log error? - .and_then(|uri| diagnostics.get(&uri)) + .and_then(|path| diagnostics.get(path)) .map(|diags| { diags.iter().filter_map(move |(diagnostic, lsp_id)| { let ls = language_servers.get_by_id(*lsp_id)?; From 928bf80d9a1d6206f864e9b375f67662a49a6265 Mon Sep 17 00:00:00 2001 From: Michael Davis Date: Sat, 17 Jun 2023 17:01:36 -0500 Subject: [PATCH 003/114] LSP: Normalize diagnostic file paths --- helix-term/src/application.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/helix-term/src/application.rs b/helix-term/src/application.rs index 0ef200c2f..809393c7f 100644 --- a/helix-term/src/application.rs +++ b/helix-term/src/application.rs @@ -724,7 +724,7 @@ impl Application { } Notification::PublishDiagnostics(mut params) => { let path = match params.uri.to_file_path() { - Ok(path) => path, + Ok(path) => helix_stdx::path::normalize(&path), Err(_) => { log::error!("Unsupported file URI: {}", params.uri); return; From a87614858571ed7f9ab4a3145187cf598ec0faeb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carsten=20F=C3=BChrmann?= Date: Mon, 26 Feb 2024 02:53:59 +0100 Subject: [PATCH 004/114] Fix colors of tokyonight diagnostic undercurls (#9724) --- runtime/themes/tokyonight.toml | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/runtime/themes/tokyonight.toml b/runtime/themes/tokyonight.toml index 95ebd4087..fbd8f2ed5 100644 --- a/runtime/themes/tokyonight.toml +++ b/runtime/themes/tokyonight.toml @@ -58,13 +58,13 @@ variable = { fg = "fg" } "diff.plus" = { fg = "add" } error = { fg = "error" } -hint = { fg = "hint" } -info = { fg = "info" } warning = { fg = "yellow" } -"diagnostic.error" = { underline = { style = "curl" } } -"diagnostic.warning" = { underline = { style = "curl" } } -"diagnostic.info" = { underline = { style = "curl" } } -"diagnostic.hint" = { underline = { style = "curl" } } +info = { fg = "info" } +hint = { fg = "hint" } +"diagnostic.error" = { underline = { style = "curl", color = "error" } } +"diagnostic.warning" = { underline = { style = "curl", color = "yellow"} } +"diagnostic.info" = { underline = { style = "curl", color = "info"} } +"diagnostic.hint" = { underline = { style = "curl", color = "hint" } } "ui.background" = { bg = "bg", fg = "fg" } "ui.cursor" = { modifiers = ["reversed"] } @@ -114,8 +114,8 @@ change = "#6183bb" delete = "#914c54" error = "#db4b4b" -hint = "#1abc9c" info = "#0db9d7" +hint = "#1abc9c" fg = "#c0caf5" fg-dark = "#a9b1d6" From c68ec92c5e1bd3a2bf402fb583de23693f59b722 Mon Sep 17 00:00:00 2001 From: Tobias Hunger Date: Mon, 26 Feb 2024 08:08:31 +0100 Subject: [PATCH 005/114] slint: Update SHA of tree-sitter parser (#9698) --- languages.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/languages.toml b/languages.toml index 112333ea9..750ec9088 100644 --- a/languages.toml +++ b/languages.toml @@ -2178,7 +2178,7 @@ language-servers = [ "slint-lsp" ] [[grammar]] name = "slint" -source = { git = "https://github.com/slint-ui/tree-sitter-slint", rev = "15618215b79b9db08f824a5c97a12d073dcc1c00" } +source = { git = "https://github.com/slint-ui/tree-sitter-slint", rev = "3c82235f41b63f35a01ae3888206e93585cbb84a" } [[language]] name = "task" From cd02976fa3a55c2c1f01b95c40d178061968f797 Mon Sep 17 00:00:00 2001 From: Pascal Kuthe Date: Mon, 26 Feb 2024 08:45:20 +0100 Subject: [PATCH 006/114] switch to regex-cursor (#9422) --- Cargo.lock | 18 ++++++- helix-core/src/selection.rs | 96 +++++++++++++++++++++++-------------- helix-core/src/syntax.rs | 12 +++-- helix-stdx/Cargo.toml | 1 + helix-stdx/src/rope.rs | 45 ++++++++++++++++- helix-term/src/commands.rs | 56 ++++++++-------------- helix-term/src/ui/mod.rs | 33 +++++++++---- 7 files changed, 175 insertions(+), 86 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 2b8a25c85..b8d375c51 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1344,6 +1344,7 @@ version = "23.10.0" dependencies = [ "dunce", "etcetera", + "regex-cursor", "ropey", "tempfile", "which", @@ -1938,15 +1939,28 @@ dependencies = [ [[package]] name = "regex-automata" -version = "0.4.4" +version = "0.4.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3b7fa1134405e2ec9353fd416b17f8dacd46c473d7d3fd1cf202706a14eb792a" +checksum = "5bb987efffd3c6d0d8f5f89510bb458559eab11e4f869acb20bf845e016259cd" dependencies = [ "aho-corasick", "memchr", "regex-syntax", ] +[[package]] +name = "regex-cursor" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a43718aa0040434d45728c43f56bd53bda75a91c46954cdf0f2ff4dbc8aabbe7" +dependencies = [ + "log", + "memchr", + "regex-automata", + "regex-syntax", + "ropey", +] + [[package]] name = "regex-syntax" version = "0.8.2" diff --git a/helix-core/src/selection.rs b/helix-core/src/selection.rs index c44685eea..91f1d0de5 100644 --- a/helix-core/src/selection.rs +++ b/helix-core/src/selection.rs @@ -7,9 +7,11 @@ use crate::{ ensure_grapheme_boundary_next, ensure_grapheme_boundary_prev, next_grapheme_boundary, prev_grapheme_boundary, }, + line_ending::get_line_ending, movement::Direction, Assoc, ChangeSet, RopeGraphemes, RopeSlice, }; +use helix_stdx::rope::{self, RopeSliceExt}; use smallvec::{smallvec, SmallVec}; use std::borrow::Cow; @@ -708,12 +710,12 @@ impl IntoIterator for Selection { pub fn keep_or_remove_matches( text: RopeSlice, selection: &Selection, - regex: &crate::regex::Regex, + regex: &rope::Regex, remove: bool, ) -> Option { let result: SmallVec<_> = selection .iter() - .filter(|range| regex.is_match(&range.fragment(text)) ^ remove) + .filter(|range| regex.is_match(text.regex_input_at(range.from()..range.to())) ^ remove) .copied() .collect(); @@ -724,25 +726,20 @@ pub fn keep_or_remove_matches( None } +// TODO: support to split on capture #N instead of whole match pub fn select_on_matches( text: RopeSlice, selection: &Selection, - regex: &crate::regex::Regex, + regex: &rope::Regex, ) -> Option { let mut result = SmallVec::with_capacity(selection.len()); for sel in selection { - // TODO: can't avoid occasional allocations since Regex can't operate on chunks yet - let fragment = sel.fragment(text); - - let sel_start = sel.from(); - let start_byte = text.char_to_byte(sel_start); - - for mat in regex.find_iter(&fragment) { + for mat in regex.find_iter(text.regex_input_at(sel.from()..sel.to())) { // TODO: retain range direction - let start = text.byte_to_char(start_byte + mat.start()); - let end = text.byte_to_char(start_byte + mat.end()); + let start = text.byte_to_char(mat.start()); + let end = text.byte_to_char(mat.end()); let range = Range::new(start, end); // Make sure the match is not right outside of the selection. @@ -761,12 +758,7 @@ pub fn select_on_matches( None } -// TODO: support to split on capture #N instead of whole match -pub fn split_on_matches( - text: RopeSlice, - selection: &Selection, - regex: &crate::regex::Regex, -) -> Selection { +pub fn split_on_newline(text: RopeSlice, selection: &Selection) -> Selection { let mut result = SmallVec::with_capacity(selection.len()); for sel in selection { @@ -776,21 +768,47 @@ pub fn split_on_matches( continue; } - // TODO: can't avoid occasional allocations since Regex can't operate on chunks yet - let fragment = sel.fragment(text); - let sel_start = sel.from(); let sel_end = sel.to(); - let start_byte = text.char_to_byte(sel_start); + let mut start = sel_start; + for mat in sel.slice(text).lines() { + let len = mat.len_chars(); + let line_end_len = get_line_ending(&mat).map(|le| le.len_chars()).unwrap_or(0); + // TODO: retain range direction + result.push(Range::new(start, start + len - line_end_len)); + start += len; + } + + if start < sel_end { + result.push(Range::new(start, sel_end)); + } + } + + // TODO: figure out a new primary index + Selection::new(result, 0) +} + +pub fn split_on_matches(text: RopeSlice, selection: &Selection, regex: &rope::Regex) -> Selection { + let mut result = SmallVec::with_capacity(selection.len()); + + for sel in selection { + // Special case: zero-width selection. + if sel.from() == sel.to() { + result.push(*sel); + continue; + } + + let sel_start = sel.from(); + let sel_end = sel.to(); let mut start = sel_start; - for mat in regex.find_iter(&fragment) { + for mat in regex.find_iter(text.regex_input_at(sel_start..sel_end)) { // TODO: retain range direction - let end = text.byte_to_char(start_byte + mat.start()); + let end = text.byte_to_char(mat.start()); result.push(Range::new(start, end)); - start = text.byte_to_char(start_byte + mat.end()); + start = text.byte_to_char(mat.end()); } if start < sel_end { @@ -1021,14 +1039,12 @@ mod test { #[test] fn test_select_on_matches() { - use crate::regex::{Regex, RegexBuilder}; - let r = Rope::from_str("Nobody expects the Spanish inquisition"); let s = r.slice(..); let selection = Selection::single(0, r.len_chars()); assert_eq!( - select_on_matches(s, &selection, &Regex::new(r"[A-Z][a-z]*").unwrap()), + select_on_matches(s, &selection, &rope::Regex::new(r"[A-Z][a-z]*").unwrap()), Some(Selection::new( smallvec![Range::new(0, 6), Range::new(19, 26)], 0 @@ -1038,8 +1054,14 @@ mod test { let r = Rope::from_str("This\nString\n\ncontains multiple\nlines"); let s = r.slice(..); - let start_of_line = RegexBuilder::new(r"^").multi_line(true).build().unwrap(); - let end_of_line = RegexBuilder::new(r"$").multi_line(true).build().unwrap(); + let start_of_line = rope::RegexBuilder::new() + .syntax(rope::Config::new().multi_line(true)) + .build(r"^") + .unwrap(); + let end_of_line = rope::RegexBuilder::new() + .syntax(rope::Config::new().multi_line(true)) + .build(r"$") + .unwrap(); // line without ending assert_eq!( @@ -1077,9 +1099,9 @@ mod test { select_on_matches( s, &Selection::single(0, s.len_chars()), - &RegexBuilder::new(r"^[a-z ]*$") - .multi_line(true) - .build() + &rope::RegexBuilder::new() + .syntax(rope::Config::new().multi_line(true)) + .build(r"^[a-z ]*$") .unwrap() ), Some(Selection::new( @@ -1171,13 +1193,15 @@ mod test { #[test] fn test_split_on_matches() { - use crate::regex::Regex; - let text = Rope::from(" abcd efg wrs xyz 123 456"); let selection = Selection::new(smallvec![Range::new(0, 9), Range::new(11, 20),], 0); - let result = split_on_matches(text.slice(..), &selection, &Regex::new(r"\s+").unwrap()); + let result = split_on_matches( + text.slice(..), + &selection, + &rope::Regex::new(r"\s+").unwrap(), + ); assert_eq!( result.ranges(), diff --git a/helix-core/src/syntax.rs b/helix-core/src/syntax.rs index a9344448f..0d8559ca9 100644 --- a/helix-core/src/syntax.rs +++ b/helix-core/src/syntax.rs @@ -12,6 +12,7 @@ use arc_swap::{ArcSwap, Guard}; use bitflags::bitflags; use globset::GlobSet; use hashbrown::raw::RawTable; +use helix_stdx::rope::{self, RopeSliceExt}; use slotmap::{DefaultKey as LayerId, HopSlotMap}; use std::{ @@ -1961,11 +1962,16 @@ impl HighlightConfiguration { node_slice }; - static SHEBANG_REGEX: Lazy = Lazy::new(|| Regex::new(SHEBANG).unwrap()); + static SHEBANG_REGEX: Lazy = + Lazy::new(|| rope::Regex::new(SHEBANG).unwrap()); injection_capture = SHEBANG_REGEX - .captures(&Cow::from(lines)) - .map(|cap| InjectionLanguageMarker::Shebang(cap[1].to_owned())) + .captures_iter(lines.regex_input()) + .map(|cap| { + let cap = lines.byte_slice(cap.get_group(1).unwrap().range()); + InjectionLanguageMarker::Shebang(cap.into()) + }) + .next() } else if index == self.injection_content_capture_index { content_node = Some(capture.node); } diff --git a/helix-stdx/Cargo.toml b/helix-stdx/Cargo.toml index 540a1b99a..5ac7c011f 100644 --- a/helix-stdx/Cargo.toml +++ b/helix-stdx/Cargo.toml @@ -16,6 +16,7 @@ dunce = "1.0" etcetera = "0.8" ropey = { version = "1.6.1", default-features = false } which = "6.0" +regex-cursor = "0.1.3" [dev-dependencies] tempfile = "3.10" diff --git a/helix-stdx/src/rope.rs b/helix-stdx/src/rope.rs index 4ee39d4a8..7b4edda4f 100644 --- a/helix-stdx/src/rope.rs +++ b/helix-stdx/src/rope.rs @@ -1,11 +1,22 @@ +use std::ops::{Bound, RangeBounds}; + +pub use regex_cursor::engines::meta::{Builder as RegexBuilder, Regex}; +pub use regex_cursor::regex_automata::util::syntax::Config; +use regex_cursor::{Input as RegexInput, RopeyCursor}; use ropey::RopeSlice; -pub trait RopeSliceExt: Sized { +pub trait RopeSliceExt<'a>: Sized { fn ends_with(self, text: &str) -> bool; fn starts_with(self, text: &str) -> bool; + fn regex_input(self) -> RegexInput>; + fn regex_input_at_bytes>( + self, + byte_range: R, + ) -> RegexInput>; + fn regex_input_at>(self, char_range: R) -> RegexInput>; } -impl RopeSliceExt for RopeSlice<'_> { +impl<'a> RopeSliceExt<'a> for RopeSlice<'a> { fn ends_with(self, text: &str) -> bool { let len = self.len_bytes(); if len < text.len() { @@ -23,4 +34,34 @@ impl RopeSliceExt for RopeSlice<'_> { self.get_byte_slice(..len - text.len()) .map_or(false, |start| start == text) } + + fn regex_input(self) -> RegexInput> { + RegexInput::new(self) + } + + fn regex_input_at>(self, char_range: R) -> RegexInput> { + let start_bound = match char_range.start_bound() { + Bound::Included(&val) => Bound::Included(self.char_to_byte(val)), + Bound::Excluded(&val) => Bound::Excluded(self.char_to_byte(val)), + Bound::Unbounded => Bound::Unbounded, + }; + let end_bound = match char_range.end_bound() { + Bound::Included(&val) => Bound::Included(self.char_to_byte(val)), + Bound::Excluded(&val) => Bound::Excluded(self.char_to_byte(val)), + Bound::Unbounded => Bound::Unbounded, + }; + self.regex_input_at_bytes((start_bound, end_bound)) + } + fn regex_input_at_bytes>( + self, + byte_range: R, + ) -> RegexInput> { + let input = match byte_range.start_bound() { + Bound::Included(&pos) | Bound::Excluded(&pos) => { + RegexInput::new(RopeyCursor::at(self, pos)) + } + Bound::Unbounded => RegexInput::new(self), + }; + input.range(byte_range) + } } diff --git a/helix-term/src/commands.rs b/helix-term/src/commands.rs index 51a1ede9b..fdad31a81 100644 --- a/helix-term/src/commands.rs +++ b/helix-term/src/commands.rs @@ -3,6 +3,7 @@ pub(crate) mod lsp; pub(crate) mod typed; pub use dap::*; +use helix_stdx::rope::{self, RopeSliceExt}; use helix_vcs::Hunk; pub use lsp::*; use tui::widgets::Row; @@ -19,7 +20,7 @@ use helix_core::{ match_brackets, movement::{self, move_vertically_visual, Direction}, object, pos_at_coords, - regex::{self, Regex, RegexBuilder}, + regex::{self, Regex}, search::{self, CharMatcher}, selection, shellwords, surround, syntax::LanguageServerFeature, @@ -1907,11 +1908,7 @@ fn split_selection(cx: &mut Context) { fn split_selection_on_newline(cx: &mut Context) { let (view, doc) = current!(cx.editor); let text = doc.text().slice(..); - // only compile the regex once - #[allow(clippy::trivial_regex)] - static REGEX: Lazy = - Lazy::new(|| Regex::new(r"\r\n|[\n\r\u{000B}\u{000C}\u{0085}\u{2028}\u{2029}]").unwrap()); - let selection = selection::split_on_matches(text, doc.selection(view.id), ®EX); + let selection = selection::split_on_newline(text, doc.selection(view.id)); doc.set_selection(view.id, selection); } @@ -1930,8 +1927,7 @@ fn merge_consecutive_selections(cx: &mut Context) { #[allow(clippy::too_many_arguments)] fn search_impl( editor: &mut Editor, - contents: &str, - regex: &Regex, + regex: &rope::Regex, movement: Movement, direction: Direction, scrolloff: usize, @@ -1959,23 +1955,20 @@ fn search_impl( // do a reverse search and wraparound to the end, we don't need to search // the text before the current cursor position for matches, but by slicing // it out, we need to add it back to the position of the selection. - let mut offset = 0; + let doc = doc!(editor).text().slice(..); // use find_at to find the next match after the cursor, loop around the end // Careful, `Regex` uses `bytes` as offsets, not character indices! let mut mat = match direction { - Direction::Forward => regex.find_at(contents, start), - Direction::Backward => regex.find_iter(&contents[..start]).last(), + Direction::Forward => regex.find(doc.regex_input_at_bytes(start..)), + Direction::Backward => regex.find_iter(doc.regex_input_at_bytes(..start)).last(), }; if mat.is_none() { if wrap_around { mat = match direction { - Direction::Forward => regex.find(contents), - Direction::Backward => { - offset = start; - regex.find_iter(&contents[start..]).last() - } + Direction::Forward => regex.find(doc.regex_input()), + Direction::Backward => regex.find_iter(doc.regex_input_at_bytes(start..)).last(), }; } if show_warnings { @@ -1992,8 +1985,8 @@ fn search_impl( let selection = doc.selection(view.id); if let Some(mat) = mat { - let start = text.byte_to_char(mat.start() + offset); - let end = text.byte_to_char(mat.end() + offset); + let start = text.byte_to_char(mat.start()); + let end = text.byte_to_char(mat.end()); if end == 0 { // skip empty matches that don't make sense @@ -2037,13 +2030,7 @@ fn searcher(cx: &mut Context, direction: Direction) { let scrolloff = config.scrolloff; let wrap_around = config.search.wrap_around; - let doc = doc!(cx.editor); - // TODO: could probably share with select_on_matches? - - // HAXX: sadly we can't avoid allocating a single string for the whole buffer since we can't - // feed chunks into the regex yet - let contents = doc.text().slice(..).to_string(); let completions = search_completions(cx, Some(reg)); ui::regex_prompt( @@ -2065,7 +2052,6 @@ fn searcher(cx: &mut Context, direction: Direction) { } search_impl( cx.editor, - &contents, ®ex, Movement::Move, direction, @@ -2085,8 +2071,6 @@ fn search_next_or_prev_impl(cx: &mut Context, movement: Movement, direction: Dir let config = cx.editor.config(); let scrolloff = config.scrolloff; if let Some(query) = cx.editor.registers.first(register, cx.editor) { - let doc = doc!(cx.editor); - let contents = doc.text().slice(..).to_string(); let search_config = &config.search; let case_insensitive = if search_config.smart_case { !query.chars().any(char::is_uppercase) @@ -2094,15 +2078,17 @@ fn search_next_or_prev_impl(cx: &mut Context, movement: Movement, direction: Dir false }; let wrap_around = search_config.wrap_around; - if let Ok(regex) = RegexBuilder::new(&query) - .case_insensitive(case_insensitive) - .multi_line(true) - .build() + if let Ok(regex) = rope::RegexBuilder::new() + .syntax( + rope::Config::new() + .case_insensitive(case_insensitive) + .multi_line(true), + ) + .build(&query) { for _ in 0..count { search_impl( cx.editor, - &contents, ®ex, movement, direction, @@ -2239,7 +2225,7 @@ fn global_search(cx: &mut Context) { let reg = cx.register.unwrap_or('/'); let completions = search_completions(cx, Some(reg)); - ui::regex_prompt( + ui::raw_regex_prompt( cx, "global-search:".into(), Some(reg), @@ -2250,7 +2236,7 @@ fn global_search(cx: &mut Context) { .map(|comp| (0.., std::borrow::Cow::Owned(comp.clone()))) .collect() }, - move |cx, regex, event| { + move |cx, _, input, event| { if event != PromptEvent::Validate { return; } @@ -2265,7 +2251,7 @@ fn global_search(cx: &mut Context) { if let Ok(matcher) = RegexMatcherBuilder::new() .case_smart(smart_case) - .build(regex.as_str()) + .build(input) { let search_root = helix_stdx::env::current_working_dir(); if !search_root.exists() { diff --git a/helix-term/src/ui/mod.rs b/helix-term/src/ui/mod.rs index 0873116cb..a4b148af3 100644 --- a/helix-term/src/ui/mod.rs +++ b/helix-term/src/ui/mod.rs @@ -18,6 +18,7 @@ use crate::filter_picker_entry; use crate::job::{self, Callback}; pub use completion::{Completion, CompletionItem}; pub use editor::EditorView; +use helix_stdx::rope; pub use markdown::Markdown; pub use menu::Menu; pub use picker::{DynamicPicker, FileLocation, Picker}; @@ -26,8 +27,6 @@ pub use prompt::{Prompt, PromptEvent}; pub use spinner::{ProgressSpinners, Spinner}; pub use text::Text; -use helix_core::regex::Regex; -use helix_core::regex::RegexBuilder; use helix_view::Editor; use std::path::PathBuf; @@ -63,7 +62,22 @@ pub fn regex_prompt( prompt: std::borrow::Cow<'static, str>, history_register: Option, completion_fn: impl FnMut(&Editor, &str) -> Vec + 'static, - fun: impl Fn(&mut crate::compositor::Context, Regex, PromptEvent) + 'static, + fun: impl Fn(&mut crate::compositor::Context, rope::Regex, PromptEvent) + 'static, +) { + raw_regex_prompt( + cx, + prompt, + history_register, + completion_fn, + move |cx, regex, _, event| fun(cx, regex, event), + ); +} +pub fn raw_regex_prompt( + cx: &mut crate::commands::Context, + prompt: std::borrow::Cow<'static, str>, + history_register: Option, + completion_fn: impl FnMut(&Editor, &str) -> Vec + 'static, + fun: impl Fn(&mut crate::compositor::Context, rope::Regex, &str, PromptEvent) + 'static, ) { let (view, doc) = current!(cx.editor); let doc_id = view.doc; @@ -94,10 +108,13 @@ pub fn regex_prompt( false }; - match RegexBuilder::new(input) - .case_insensitive(case_insensitive) - .multi_line(true) - .build() + match rope::RegexBuilder::new() + .syntax( + rope::Config::new() + .case_insensitive(case_insensitive) + .multi_line(true), + ) + .build(input) { Ok(regex) => { let (view, doc) = current!(cx.editor); @@ -110,7 +127,7 @@ pub fn regex_prompt( view.jumps.push((doc_id, snapshot.clone())); } - fun(cx, regex, event); + fun(cx, regex, input, event); let (view, doc) = current!(cx.editor); view.ensure_cursor_in_view(doc, config.scrolloff); From b43d9aa306099ca1b85543bac8453cf7b67eab3e Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 27 Feb 2024 01:22:00 +0100 Subject: [PATCH 007/114] build(deps): bump ahash from 0.8.6 to 0.8.9 (#9737) Bumps [ahash](https://github.com/tkaitchuck/ahash) from 0.8.6 to 0.8.9. - [Release notes](https://github.com/tkaitchuck/ahash/releases) - [Commits](https://github.com/tkaitchuck/ahash/commits/v0.8.9) --- updated-dependencies: - dependency-name: ahash dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- Cargo.lock | 4 ++-- helix-core/Cargo.toml | 2 +- helix-event/Cargo.toml | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index b8d375c51..9430cce26 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -19,9 +19,9 @@ checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" [[package]] name = "ahash" -version = "0.8.6" +version = "0.8.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "91429305e9f0a25f6205c5b8e0d2db09e0708a7a6df0f42212bb56c32c8ac97a" +checksum = "d713b3834d76b85304d4d525563c1276e2e30dc97cc67bfb4585a4a29fc2c89f" dependencies = [ "cfg-if", "getrandom", diff --git a/helix-core/Cargo.toml b/helix-core/Cargo.toml index 0b0dd7452..be5ea5eb8 100644 --- a/helix-core/Cargo.toml +++ b/helix-core/Cargo.toml @@ -32,7 +32,7 @@ once_cell = "1.19" arc-swap = "1" regex = "1" bitflags = "2.4" -ahash = "0.8.6" +ahash = "0.8.9" hashbrown = { version = "0.14.3", features = ["raw"] } dunce = "1.0" diff --git a/helix-event/Cargo.toml b/helix-event/Cargo.toml index a5c88e93d..8711568e8 100644 --- a/helix-event/Cargo.toml +++ b/helix-event/Cargo.toml @@ -12,7 +12,7 @@ homepage.workspace = true # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -ahash = "0.8.3" +ahash = "0.8.9" hashbrown = "0.14.0" tokio = { version = "1", features = ["rt", "rt-multi-thread", "time", "sync", "parking_lot", "macros"] } # the event registry is essentially read only but must be an rwlock so we can From d0f8261141f22c7954d1665bcbc4e89bda9bd6cf Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 27 Feb 2024 01:25:17 +0100 Subject: [PATCH 008/114] build(deps): bump tempfile from 3.10.0 to 3.10.1 (#9733) Bumps [tempfile](https://github.com/Stebalien/tempfile) from 3.10.0 to 3.10.1. - [Changelog](https://github.com/Stebalien/tempfile/blob/master/CHANGELOG.md) - [Commits](https://github.com/Stebalien/tempfile/compare/v3.10.0...v3.10.1) --- updated-dependencies: - dependency-name: tempfile dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- Cargo.lock | 4 ++-- helix-loader/Cargo.toml | 2 +- helix-term/Cargo.toml | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 9430cce26..d376538e4 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2215,9 +2215,9 @@ dependencies = [ [[package]] name = "tempfile" -version = "3.10.0" +version = "3.10.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a365e8cd18e44762ef95d87f284f4b5cd04107fec2ff3052bd6a3e6069669e67" +checksum = "85b77fafb263dd9d05cbeac119526425676db3784113aa9295c88498cbf8bff1" dependencies = [ "cfg-if", "fastrand", diff --git a/helix-loader/Cargo.toml b/helix-loader/Cargo.toml index 25b559696..d15d87f95 100644 --- a/helix-loader/Cargo.toml +++ b/helix-loader/Cargo.toml @@ -30,7 +30,7 @@ log = "0.4" # cloning/compiling tree-sitter grammars cc = { version = "1" } threadpool = { version = "1.0" } -tempfile = "3.10.0" +tempfile = "3.10.1" dunce = "1.0.4" [target.'cfg(not(target_arch = "wasm32"))'.dependencies] diff --git a/helix-term/Cargo.toml b/helix-term/Cargo.toml index 1e21ec161..8c6ae9f42 100644 --- a/helix-term/Cargo.toml +++ b/helix-term/Cargo.toml @@ -84,4 +84,4 @@ helix-loader = { path = "../helix-loader" } [dev-dependencies] smallvec = "1.13" indoc = "2.0.4" -tempfile = "3.10.0" +tempfile = "3.10.1" From ea95c687751ebee391088bde269f0b40267dfdf0 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 27 Feb 2024 01:25:52 +0100 Subject: [PATCH 009/114] build(deps): bump serde_json from 1.0.113 to 1.0.114 (#9735) Bumps [serde_json](https://github.com/serde-rs/json) from 1.0.113 to 1.0.114. - [Release notes](https://github.com/serde-rs/json/releases) - [Commits](https://github.com/serde-rs/json/compare/v1.0.113...v1.0.114) --- updated-dependencies: - dependency-name: serde_json dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- Cargo.lock | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index d376538e4..6f4d9758e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2045,9 +2045,9 @@ dependencies = [ [[package]] name = "serde_json" -version = "1.0.113" +version = "1.0.114" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "69801b70b1c3dac963ecb03a364ba0ceda9cf60c71cfe475e99864759c8b8a79" +checksum = "c5f09b1bd632ef549eaa9f60a1f8de742bdbc698e6cee2095fc84dde5f549ae0" dependencies = [ "itoa", "ryu", From 1a82aeeae91be33cb0923c9f652fa6db250efd7f Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 27 Feb 2024 01:26:24 +0100 Subject: [PATCH 010/114] build(deps): bump serde from 1.0.196 to 1.0.197 (#9736) Bumps [serde](https://github.com/serde-rs/serde) from 1.0.196 to 1.0.197. - [Release notes](https://github.com/serde-rs/serde/releases) - [Commits](https://github.com/serde-rs/serde/compare/v1.0.196...v1.0.197) --- updated-dependencies: - dependency-name: serde dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- Cargo.lock | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 6f4d9758e..7f57b75d3 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2025,18 +2025,18 @@ checksum = "1792db035ce95be60c3f8853017b3999209281c24e2ba5bc8e59bf97a0c590c1" [[package]] name = "serde" -version = "1.0.196" +version = "1.0.197" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "870026e60fa08c69f064aa766c10f10b1d62db9ccd4d0abb206472bee0ce3b32" +checksum = "3fb1c873e1b9b056a4dc4c0c198b24c3ffa059243875552b2bd0933b1aee4ce2" dependencies = [ "serde_derive", ] [[package]] name = "serde_derive" -version = "1.0.196" +version = "1.0.197" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "33c85360c95e7d137454dc81d9a4ed2b8efd8fbe19cee57357b32b9771fccb67" +checksum = "7eb0b34b42edc17f6b7cac84a52a1c5f0e1bb2227e997ca9011ea3dd34e8610b" dependencies = [ "proc-macro2", "quote", From 358ac6bc1f512ca7303856dc904d4b4cdc1fe718 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B7=A2=E9=B9=8F?= Date: Mon, 26 Feb 2024 19:41:50 -0500 Subject: [PATCH 011/114] add fidl support (#9713) --- book/src/generated/lang-support.md | 1 + languages.toml | 18 ++++++++ runtime/queries/fidl/folds.scm | 6 +++ runtime/queries/fidl/highlights.scm | 64 +++++++++++++++++++++++++++++ runtime/queries/fidl/injections.scm | 2 + 5 files changed, 91 insertions(+) create mode 100644 runtime/queries/fidl/folds.scm create mode 100644 runtime/queries/fidl/highlights.scm create mode 100644 runtime/queries/fidl/injections.scm diff --git a/book/src/generated/lang-support.md b/book/src/generated/lang-support.md index 7aec37778..1bc6b0817 100644 --- a/book/src/generated/lang-support.md +++ b/book/src/generated/lang-support.md @@ -44,6 +44,7 @@ | erb | ✓ | | | | | erlang | ✓ | ✓ | | `erlang_ls` | | esdl | ✓ | | | | +| fidl | ✓ | | | | | fish | ✓ | ✓ | ✓ | | | forth | ✓ | | | `forth-lsp` | | fortran | ✓ | | ✓ | `fortls` | diff --git a/languages.toml b/languages.toml index 750ec9088..313b3d95e 100644 --- a/languages.toml +++ b/languages.toml @@ -3140,3 +3140,21 @@ indent = { tab-width = 2, unit = " " } [[grammar]] name = "groovy" source = { git = "https://github.com/Decodetalkers/tree-sitter-groovy", rev = "7e023227f46fee428b16a0288eeb0f65ee2523ec" } + +[[language]] +name = "fidl" +scope = "source.fidl" +injection-regex = "fidl" +file-types = ["fidl"] +comment-token = "//" +indent = { tab-width = 4, unit = " " } + +[language.auto-pairs] +'"' = '"' +'{' = '}' +'(' = ')' +'<' = '>' + +[[grammar]] +name = "fidl" +source = { git = "https://github.com/google/tree-sitter-fidl", rev = "bdbb635a7f5035e424f6173f2f11b9cd79703f8d" } diff --git a/runtime/queries/fidl/folds.scm b/runtime/queries/fidl/folds.scm new file mode 100644 index 000000000..f524c455b --- /dev/null +++ b/runtime/queries/fidl/folds.scm @@ -0,0 +1,6 @@ +[ + (layout_declaration) + (protocol_declaration) + (resource_declaration) + (service_declaration) +] @fold diff --git a/runtime/queries/fidl/highlights.scm b/runtime/queries/fidl/highlights.scm new file mode 100644 index 000000000..c70d22198 --- /dev/null +++ b/runtime/queries/fidl/highlights.scm @@ -0,0 +1,64 @@ +[ + "ajar" + "alias" + "as" + "bits" + "closed" + "compose" + "const" + "enum" + "error" + "flexible" + "library" + "open" + ; "optional" we did not specify a node for optional yet + "overlay" + "protocol" + "reserved" + "resource" + "service" + "strict" + "struct" + "table" + "type" + "union" + "using" +] @keyword + +(primitives_type) @type.builtin + +(builtin_complex_type) @type.builtin + +(const_declaration + (identifier) @constant) + +[ + "=" + "|" + "&" + "->" +] @operator + +(attribute + "@" @attribute + (identifier) @attribute) + +(string_literal) @string + +(numeric_literal) @constant.numeric + +[ + (true) + (false) +] @constant.builtin.boolean + +(comment) @comment + +[ + "(" + ")" + "<" + ">" + "{" + "}" +] @punctuation.bracket diff --git a/runtime/queries/fidl/injections.scm b/runtime/queries/fidl/injections.scm new file mode 100644 index 000000000..2f0e58eb6 --- /dev/null +++ b/runtime/queries/fidl/injections.scm @@ -0,0 +1,2 @@ +((comment) @injection.content + (#set! injection.language "comment")) From f46a09ab4f945273c7baf32e58438b501914fabb Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 27 Feb 2024 02:06:37 +0100 Subject: [PATCH 012/114] build(deps): bump cc from 1.0.85 to 1.0.88 (#9734) Bumps [cc](https://github.com/rust-lang/cc-rs) from 1.0.85 to 1.0.88. - [Release notes](https://github.com/rust-lang/cc-rs/releases) - [Commits](https://github.com/rust-lang/cc-rs/compare/1.0.85...1.0.88) --- updated-dependencies: - dependency-name: cc dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- Cargo.lock | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 7f57b75d3..08fa4789e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -145,9 +145,9 @@ checksum = "df8670b8c7b9dae1793364eafadf7239c40d669904660c5960d74cfd80b46a53" [[package]] name = "cc" -version = "1.0.85" +version = "1.0.88" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9b918671670962b48bc23753aef0c51d072dca6f52f01f800854ada6ddb7f7d3" +checksum = "02f341c093d19155a6e41631ce5971aac4e9a868262212153124c15fa22d1cdc" [[package]] name = "cfg-if" From 26b3dc29be886c5a2ed1a5caaaf09eb730829c3e Mon Sep 17 00:00:00 2001 From: Gabriel Dinner-David <82682503+gabydd@users.noreply.github.com> Date: Tue, 27 Feb 2024 08:36:25 -0500 Subject: [PATCH 013/114] toggling of block comments (#4718) --- book/src/keymap.md | 4 + book/src/languages.md | 5 +- helix-core/src/comment.rs | 270 ++++++++++++++++++++++++++++++- helix-core/src/indent.rs | 4 +- helix-core/src/lib.rs | 3 - helix-core/src/syntax.rs | 67 +++++++- helix-core/tests/indent.rs | 3 +- helix-stdx/src/rope.rs | 11 ++ helix-term/src/commands.rs | 136 ++++++++++++++-- helix-term/src/keymap/default.rs | 3 + languages.toml | 91 ++++++++++- 11 files changed, 568 insertions(+), 29 deletions(-) diff --git a/book/src/keymap.md b/book/src/keymap.md index ac84147cd..bb09b0319 100644 --- a/book/src/keymap.md +++ b/book/src/keymap.md @@ -12,6 +12,7 @@ - [Match mode](#match-mode) - [Window mode](#window-mode) - [Space mode](#space-mode) + - [Comment mode](#comment-mode) - [Popup](#popup) - [Unimpaired](#unimpaired) - [Insert mode](#insert-mode) @@ -289,6 +290,9 @@ This layer is a kludge of mappings, mostly pickers. | `h` | Select symbol references (**LSP**) | `select_references_to_symbol_under_cursor` | | `'` | Open last fuzzy picker | `last_picker` | | `w` | Enter [window mode](#window-mode) | N/A | +| `c` | Comment/uncomment selections | `toggle_comments` | +| `C` | Block comment/uncomment selections | `toggle_block_comments` | +| `Alt-c` | Line comment/uncomment selections | `toggle_line_comments` | | `p` | Paste system clipboard after selections | `paste_clipboard_after` | | `P` | Paste system clipboard before selections | `paste_clipboard_before` | | `y` | Yank selections to clipboard | `yank_to_clipboard` | diff --git a/book/src/languages.md b/book/src/languages.md index e3900dca9..dd93fec53 100644 --- a/book/src/languages.md +++ b/book/src/languages.md @@ -42,7 +42,7 @@ name = "mylang" scope = "source.mylang" injection-regex = "mylang" file-types = ["mylang", "myl"] -comment-token = "#" +comment-tokens = "#" indent = { tab-width = 2, unit = " " } formatter = { command = "mylang-formatter" , args = ["--stdin"] } language-servers = [ "mylang-lsp" ] @@ -61,7 +61,8 @@ These configuration keys are available: | `roots` | A set of marker files to look for when trying to find the workspace root. For example `Cargo.lock`, `yarn.lock` | | `auto-format` | Whether to autoformat this language when saving | | `diagnostic-severity` | Minimal severity of diagnostic for it to be displayed. (Allowed values: `Error`, `Warning`, `Info`, `Hint`) | -| `comment-token` | The token to use as a comment-token | +| `comment-tokens` | The tokens to use as a comment token, either a single token `"//"` or an array `["//", "///", "//!"]` (the first token will be used for commenting). Also configurable as `comment-token` for backwards compatibility| +| `block-comment-tokens`| The start and end tokens for a multiline comment either an array or single table of `{ start = "/*", end = "*/"}`. The first set of tokens will be used for commenting, any pairs in the array can be uncommented | | `indent` | The indent to use. Has sub keys `unit` (the text inserted into the document when indenting; usually set to N spaces or `"\t"` for tabs) and `tab-width` (the number of spaces rendered for a tab) | | `language-servers` | The Language Servers used for this language. See below for more information in the section [Configuring Language Servers for a language](#configuring-language-servers-for-a-language) | | `grammar` | The tree-sitter grammar to use (defaults to the value of `name`) | diff --git a/helix-core/src/comment.rs b/helix-core/src/comment.rs index 9c7e50f33..536b710ab 100644 --- a/helix-core/src/comment.rs +++ b/helix-core/src/comment.rs @@ -1,9 +1,12 @@ //! This module contains the functionality toggle comments on lines over the selection //! using the comment character defined in the user's `languages.toml` +use smallvec::SmallVec; + use crate::{ - find_first_non_whitespace_char, Change, Rope, RopeSlice, Selection, Tendril, Transaction, + syntax::BlockCommentToken, Change, Range, Rope, RopeSlice, Selection, Tendril, Transaction, }; +use helix_stdx::rope::RopeSliceExt; use std::borrow::Cow; /// Given text, a comment token, and a set of line indices, returns the following: @@ -22,12 +25,12 @@ fn find_line_comment( ) -> (bool, Vec, usize, usize) { let mut commented = true; let mut to_change = Vec::new(); - let mut min = usize::MAX; // minimum col for find_first_non_whitespace_char + let mut min = usize::MAX; // minimum col for first_non_whitespace_char let mut margin = 1; let token_len = token.chars().count(); for line in lines { let line_slice = text.line(line); - if let Some(pos) = find_first_non_whitespace_char(line_slice) { + if let Some(pos) = line_slice.first_non_whitespace_char() { let len = line_slice.len_chars(); if pos < min { @@ -94,6 +97,222 @@ pub fn toggle_line_comments(doc: &Rope, selection: &Selection, token: Option<&st Transaction::change(doc, changes.into_iter()) } +#[derive(Debug, PartialEq, Eq)] +pub enum CommentChange { + Commented { + range: Range, + start_pos: usize, + end_pos: usize, + start_margin: bool, + end_margin: bool, + start_token: String, + end_token: String, + }, + Uncommented { + range: Range, + start_pos: usize, + end_pos: usize, + start_token: String, + end_token: String, + }, + Whitespace { + range: Range, + }, +} + +pub fn find_block_comments( + tokens: &[BlockCommentToken], + text: RopeSlice, + selection: &Selection, +) -> (bool, Vec) { + let mut commented = true; + let mut only_whitespace = true; + let mut comment_changes = Vec::with_capacity(selection.len()); + let default_tokens = tokens.first().cloned().unwrap_or_default(); + // TODO: check if this can be removed on MSRV bump + #[allow(clippy::redundant_clone)] + let mut start_token = default_tokens.start.clone(); + #[allow(clippy::redundant_clone)] + let mut end_token = default_tokens.end.clone(); + + let mut tokens = tokens.to_vec(); + // sort the tokens by length, so longer tokens will match first + tokens.sort_by(|a, b| { + if a.start.len() == b.start.len() { + b.end.len().cmp(&a.end.len()) + } else { + b.start.len().cmp(&a.start.len()) + } + }); + for range in selection { + let selection_slice = range.slice(text); + if let (Some(start_pos), Some(end_pos)) = ( + selection_slice.first_non_whitespace_char(), + selection_slice.last_non_whitespace_char(), + ) { + let mut line_commented = false; + let mut after_start = 0; + let mut before_end = 0; + let len = (end_pos + 1) - start_pos; + + for BlockCommentToken { start, end } in &tokens { + let start_len = start.chars().count(); + let end_len = end.chars().count(); + after_start = start_pos + start_len; + before_end = end_pos.saturating_sub(end_len); + + if len >= start_len + end_len { + let start_fragment = selection_slice.slice(start_pos..after_start); + let end_fragment = selection_slice.slice(before_end + 1..end_pos + 1); + + // block commented with these tokens + if start_fragment == start.as_str() && end_fragment == end.as_str() { + start_token = start.to_string(); + end_token = end.to_string(); + line_commented = true; + break; + } + } + } + + if !line_commented { + comment_changes.push(CommentChange::Uncommented { + range: *range, + start_pos, + end_pos, + start_token: default_tokens.start.clone(), + end_token: default_tokens.end.clone(), + }); + commented = false; + } else { + comment_changes.push(CommentChange::Commented { + range: *range, + start_pos, + end_pos, + start_margin: selection_slice + .get_char(after_start) + .map_or(false, |c| c == ' '), + end_margin: after_start != before_end + && selection_slice + .get_char(before_end) + .map_or(false, |c| c == ' '), + start_token: start_token.to_string(), + end_token: end_token.to_string(), + }); + } + only_whitespace = false; + } else { + comment_changes.push(CommentChange::Whitespace { range: *range }); + } + } + if only_whitespace { + commented = false; + } + (commented, comment_changes) +} + +#[must_use] +pub fn create_block_comment_transaction( + doc: &Rope, + selection: &Selection, + commented: bool, + comment_changes: Vec, +) -> (Transaction, SmallVec<[Range; 1]>) { + let mut changes: Vec = Vec::with_capacity(selection.len() * 2); + let mut ranges: SmallVec<[Range; 1]> = SmallVec::with_capacity(selection.len()); + let mut offs = 0; + for change in comment_changes { + if commented { + if let CommentChange::Commented { + range, + start_pos, + end_pos, + start_token, + end_token, + start_margin, + end_margin, + } = change + { + let from = range.from(); + changes.push(( + from + start_pos, + from + start_pos + start_token.len() + start_margin as usize, + None, + )); + changes.push(( + from + end_pos - end_token.len() - end_margin as usize + 1, + from + end_pos + 1, + None, + )); + } + } else { + // uncommented so manually map ranges through changes + match change { + CommentChange::Uncommented { + range, + start_pos, + end_pos, + start_token, + end_token, + } => { + let from = range.from(); + changes.push(( + from + start_pos, + from + start_pos, + Some(Tendril::from(format!("{} ", start_token))), + )); + changes.push(( + from + end_pos + 1, + from + end_pos + 1, + Some(Tendril::from(format!(" {}", end_token))), + )); + + let offset = start_token.chars().count() + end_token.chars().count() + 2; + ranges.push( + Range::new(from + offs, from + offs + end_pos + 1 + offset) + .with_direction(range.direction()), + ); + offs += offset; + } + CommentChange::Commented { range, .. } | CommentChange::Whitespace { range } => { + ranges.push(Range::new(range.from() + offs, range.to() + offs)); + } + } + } + } + (Transaction::change(doc, changes.into_iter()), ranges) +} + +#[must_use] +pub fn toggle_block_comments( + doc: &Rope, + selection: &Selection, + tokens: &[BlockCommentToken], +) -> Transaction { + let text = doc.slice(..); + let (commented, comment_changes) = find_block_comments(tokens, text, selection); + let (mut transaction, ranges) = + create_block_comment_transaction(doc, selection, commented, comment_changes); + if !commented { + transaction = transaction.with_selection(Selection::new(ranges, selection.primary_index())); + } + transaction +} + +pub fn split_lines_of_selection(text: RopeSlice, selection: &Selection) -> Selection { + let mut ranges = SmallVec::new(); + for range in selection.ranges() { + let (line_start, line_end) = range.line_range(text.slice(..)); + let mut pos = text.line_to_char(line_start); + for line in text.slice(pos..text.line_to_char(line_end + 1)).lines() { + let start = pos; + pos += line.len_chars(); + ranges.push(Range::new(start, pos)); + } + } + Selection::new(ranges, 0) +} + #[cfg(test)] mod test { use super::*; @@ -149,4 +368,49 @@ mod test { // TODO: account for uncommenting with uneven comment indentation } + + #[test] + fn test_find_block_comments() { + // three lines 5 characters. + let mut doc = Rope::from("1\n2\n3"); + // select whole document + let selection = Selection::single(0, doc.len_chars()); + + let text = doc.slice(..); + + let res = find_block_comments(&[BlockCommentToken::default()], text, &selection); + + assert_eq!( + res, + ( + false, + vec![CommentChange::Uncommented { + range: Range::new(0, 5), + start_pos: 0, + end_pos: 4, + start_token: "/*".to_string(), + end_token: "*/".to_string(), + }] + ) + ); + + // comment + let transaction = toggle_block_comments(&doc, &selection, &[BlockCommentToken::default()]); + transaction.apply(&mut doc); + + assert_eq!(doc, "/* 1\n2\n3 */"); + + // uncomment + let selection = Selection::single(0, doc.len_chars()); + let transaction = toggle_block_comments(&doc, &selection, &[BlockCommentToken::default()]); + transaction.apply(&mut doc); + assert_eq!(doc, "1\n2\n3"); + + // don't panic when there is just a space in comment + doc = Rope::from("/* */"); + let selection = Selection::single(0, doc.len_chars()); + let transaction = toggle_block_comments(&doc, &selection, &[BlockCommentToken::default()]); + transaction.apply(&mut doc); + assert_eq!(doc, ""); + } } diff --git a/helix-core/src/indent.rs b/helix-core/src/indent.rs index c29bb3a0b..2a0a3876c 100644 --- a/helix-core/src/indent.rs +++ b/helix-core/src/indent.rs @@ -1,10 +1,10 @@ use std::{borrow::Cow, collections::HashMap}; +use helix_stdx::rope::RopeSliceExt; use tree_sitter::{Query, QueryCursor, QueryPredicateArg}; use crate::{ chars::{char_is_line_ending, char_is_whitespace}, - find_first_non_whitespace_char, graphemes::{grapheme_width, tab_width_at}, syntax::{IndentationHeuristic, LanguageConfiguration, RopeProvider, Syntax}, tree_sitter::Node, @@ -970,7 +970,7 @@ pub fn indent_for_newline( let mut num_attempts = 0; for line_idx in (0..=line_before).rev() { let line = text.line(line_idx); - let first_non_whitespace_char = match find_first_non_whitespace_char(line) { + let first_non_whitespace_char = match line.first_non_whitespace_char() { Some(i) => i, None => { continue; diff --git a/helix-core/src/lib.rs b/helix-core/src/lib.rs index 94802eba9..1abd90d10 100644 --- a/helix-core/src/lib.rs +++ b/helix-core/src/lib.rs @@ -37,9 +37,6 @@ pub mod unicode { pub use helix_loader::find_workspace; -pub fn find_first_non_whitespace_char(line: RopeSlice) -> Option { - line.chars().position(|ch| !ch.is_whitespace()) -} mod rope_reader; pub use rope_reader::RopeReader; diff --git a/helix-core/src/syntax.rs b/helix-core/src/syntax.rs index 0d8559ca9..3b224e1b2 100644 --- a/helix-core/src/syntax.rs +++ b/helix-core/src/syntax.rs @@ -99,7 +99,19 @@ pub struct LanguageConfiguration { pub shebangs: Vec, // interpreter(s) associated with language #[serde(default)] pub roots: Vec, // these indicate project roots <.git, Cargo.toml> - pub comment_token: Option, + #[serde( + default, + skip_serializing, + deserialize_with = "from_comment_tokens", + alias = "comment-token" + )] + pub comment_tokens: Option>, + #[serde( + default, + skip_serializing, + deserialize_with = "from_block_comment_tokens" + )] + pub block_comment_tokens: Option>, pub text_width: Option, pub soft_wrap: Option, @@ -240,6 +252,59 @@ impl<'de> Deserialize<'de> for FileType { } } +fn from_comment_tokens<'de, D>(deserializer: D) -> Result>, D::Error> +where + D: serde::Deserializer<'de>, +{ + #[derive(Deserialize)] + #[serde(untagged)] + enum CommentTokens { + Multiple(Vec), + Single(String), + } + Ok( + Option::::deserialize(deserializer)?.map(|tokens| match tokens { + CommentTokens::Single(val) => vec![val], + CommentTokens::Multiple(vals) => vals, + }), + ) +} + +#[derive(Clone, Debug, Serialize, Deserialize)] +pub struct BlockCommentToken { + pub start: String, + pub end: String, +} + +impl Default for BlockCommentToken { + fn default() -> Self { + BlockCommentToken { + start: "/*".to_string(), + end: "*/".to_string(), + } + } +} + +fn from_block_comment_tokens<'de, D>( + deserializer: D, +) -> Result>, D::Error> +where + D: serde::Deserializer<'de>, +{ + #[derive(Deserialize)] + #[serde(untagged)] + enum BlockCommentTokens { + Multiple(Vec), + Single(BlockCommentToken), + } + Ok( + Option::::deserialize(deserializer)?.map(|tokens| match tokens { + BlockCommentTokens::Single(val) => vec![val], + BlockCommentTokens::Multiple(vals) => vals, + }), + ) +} + #[derive(Clone, Copy, Debug, Serialize, Deserialize, PartialEq, Eq, Hash)] #[serde(rename_all = "kebab-case")] pub enum LanguageServerFeature { diff --git a/helix-core/tests/indent.rs b/helix-core/tests/indent.rs index 53265e0b1..31946c56e 100644 --- a/helix-core/tests/indent.rs +++ b/helix-core/tests/indent.rs @@ -4,6 +4,7 @@ use helix_core::{ syntax::{Configuration, Loader}, Syntax, }; +use helix_stdx::rope::RopeSliceExt; use ropey::Rope; use std::{ops::Range, path::PathBuf, process::Command, sync::Arc}; @@ -211,7 +212,7 @@ fn test_treesitter_indent( if ignored_lines.iter().any(|range| range.contains(&(i + 1))) { continue; } - if let Some(pos) = helix_core::find_first_non_whitespace_char(line) { + if let Some(pos) = line.first_non_whitespace_char() { let tab_width: usize = 4; let suggested_indent = treesitter_indent_for_pos( indent_query, diff --git a/helix-stdx/src/rope.rs b/helix-stdx/src/rope.rs index 7b4edda4f..7e2549f5a 100644 --- a/helix-stdx/src/rope.rs +++ b/helix-stdx/src/rope.rs @@ -14,6 +14,8 @@ pub trait RopeSliceExt<'a>: Sized { byte_range: R, ) -> RegexInput>; fn regex_input_at>(self, char_range: R) -> RegexInput>; + fn first_non_whitespace_char(self) -> Option; + fn last_non_whitespace_char(self) -> Option; } impl<'a> RopeSliceExt<'a> for RopeSlice<'a> { @@ -64,4 +66,13 @@ impl<'a> RopeSliceExt<'a> for RopeSlice<'a> { }; input.range(byte_range) } + fn first_non_whitespace_char(self) -> Option { + self.chars().position(|ch| !ch.is_whitespace()) + } + fn last_non_whitespace_char(self) -> Option { + self.chars_at(self.len_chars()) + .reversed() + .position(|ch| !ch.is_whitespace()) + .map(|pos| self.len_chars() - pos - 1) + } } diff --git a/helix-term/src/commands.rs b/helix-term/src/commands.rs index fdad31a81..bd0a60b7c 100644 --- a/helix-term/src/commands.rs +++ b/helix-term/src/commands.rs @@ -12,7 +12,7 @@ pub use typed::*; use helix_core::{ char_idx_at_visual_offset, comment, doc_formatter::TextFormat, - encoding, find_first_non_whitespace_char, find_workspace, graphemes, + encoding, find_workspace, graphemes, history::UndoKind, increment, indent, indent::IndentStyle, @@ -23,7 +23,7 @@ use helix_core::{ regex::{self, Regex}, search::{self, CharMatcher}, selection, shellwords, surround, - syntax::LanguageServerFeature, + syntax::{BlockCommentToken, LanguageServerFeature}, text_annotations::TextAnnotations, textobject, tree_sitter::Node, @@ -415,6 +415,8 @@ impl MappableCommand { completion, "Invoke completion popup", hover, "Show docs for item under cursor", toggle_comments, "Comment/uncomment selections", + toggle_line_comments, "Line comment/uncomment selections", + toggle_block_comments, "Block comment/uncomment selections", rotate_selections_forward, "Rotate selections forward", rotate_selections_backward, "Rotate selections backward", rotate_selection_contents_forward, "Rotate selection contents forward", @@ -822,7 +824,7 @@ fn kill_to_line_start(cx: &mut Context) { let head = if anchor == first_char && line != 0 { // select until previous line line_end_char_index(&text, line - 1) - } else if let Some(pos) = find_first_non_whitespace_char(text.line(line)) { + } else if let Some(pos) = text.line(line).first_non_whitespace_char() { if first_char + pos < anchor { // select until first non-blank in line if cursor is after it first_char + pos @@ -884,7 +886,7 @@ fn goto_first_nonwhitespace_impl(view: &mut View, doc: &mut Document, movement: let selection = doc.selection(view.id).clone().transform(|range| { let line = range.cursor_line(text); - if let Some(pos) = find_first_non_whitespace_char(text.line(line)) { + if let Some(pos) = text.line(line).first_non_whitespace_char() { let pos = pos + text.line_to_char(line); range.put_cursor(text, pos, movement == Movement::Extend) } else { @@ -3087,11 +3089,11 @@ fn insert_with_indent(cx: &mut Context, cursor_fallback: IndentFallbackPos) { } else { // move cursor to the fallback position let pos = match cursor_fallback { - IndentFallbackPos::LineStart => { - find_first_non_whitespace_char(text.line(cursor_line)) - .map(|ws_offset| ws_offset + cursor_line_start) - .unwrap_or(cursor_line_start) - } + IndentFallbackPos::LineStart => text + .line(cursor_line) + .first_non_whitespace_char() + .map(|ws_offset| ws_offset + cursor_line_start) + .unwrap_or(cursor_line_start), IndentFallbackPos::LineEnd => line_end_char_index(&text, cursor_line), }; @@ -4462,18 +4464,124 @@ pub fn completion(cx: &mut Context) { } // comments -fn toggle_comments(cx: &mut Context) { +type CommentTransactionFn = fn( + line_token: Option<&str>, + block_tokens: Option<&[BlockCommentToken]>, + doc: &Rope, + selection: &Selection, +) -> Transaction; + +fn toggle_comments_impl(cx: &mut Context, comment_transaction: CommentTransactionFn) { let (view, doc) = current!(cx.editor); - let token = doc + let line_token: Option<&str> = doc + .language_config() + .and_then(|lc| lc.comment_tokens.as_ref()) + .and_then(|tc| tc.first()) + .map(|tc| tc.as_str()); + let block_tokens: Option<&[BlockCommentToken]> = doc .language_config() - .and_then(|lc| lc.comment_token.as_ref()) - .map(|tc| tc.as_ref()); - let transaction = comment::toggle_line_comments(doc.text(), doc.selection(view.id), token); + .and_then(|lc| lc.block_comment_tokens.as_ref()) + .map(|tc| &tc[..]); + + let transaction = + comment_transaction(line_token, block_tokens, doc.text(), doc.selection(view.id)); doc.apply(&transaction, view.id); exit_select_mode(cx); } +/// commenting behavior: +/// 1. only line comment tokens -> line comment +/// 2. each line block commented -> uncomment all lines +/// 3. whole selection block commented -> uncomment selection +/// 4. all lines not commented and block tokens -> comment uncommented lines +/// 5. no comment tokens and not block commented -> line comment +fn toggle_comments(cx: &mut Context) { + toggle_comments_impl(cx, |line_token, block_tokens, doc, selection| { + let text = doc.slice(..); + + // only have line comment tokens + if line_token.is_some() && block_tokens.is_none() { + return comment::toggle_line_comments(doc, selection, line_token); + } + + let split_lines = comment::split_lines_of_selection(text, selection); + + let default_block_tokens = &[BlockCommentToken::default()]; + let block_comment_tokens = block_tokens.unwrap_or(default_block_tokens); + + let (line_commented, line_comment_changes) = + comment::find_block_comments(block_comment_tokens, text, &split_lines); + + // block commented by line would also be block commented so check this first + if line_commented { + return comment::create_block_comment_transaction( + doc, + &split_lines, + line_commented, + line_comment_changes, + ) + .0; + } + + let (block_commented, comment_changes) = + comment::find_block_comments(block_comment_tokens, text, selection); + + // check if selection has block comments + if block_commented { + return comment::create_block_comment_transaction( + doc, + selection, + block_commented, + comment_changes, + ) + .0; + } + + // not commented and only have block comment tokens + if line_token.is_none() && block_tokens.is_some() { + return comment::create_block_comment_transaction( + doc, + &split_lines, + line_commented, + line_comment_changes, + ) + .0; + } + + // not block commented at all and don't have any tokens + comment::toggle_line_comments(doc, selection, line_token) + }) +} + +fn toggle_line_comments(cx: &mut Context) { + toggle_comments_impl(cx, |line_token, block_tokens, doc, selection| { + if line_token.is_none() && block_tokens.is_some() { + let default_block_tokens = &[BlockCommentToken::default()]; + let block_comment_tokens = block_tokens.unwrap_or(default_block_tokens); + comment::toggle_block_comments( + doc, + &comment::split_lines_of_selection(doc.slice(..), selection), + block_comment_tokens, + ) + } else { + comment::toggle_line_comments(doc, selection, line_token) + } + }); +} + +fn toggle_block_comments(cx: &mut Context) { + toggle_comments_impl(cx, |line_token, block_tokens, doc, selection| { + if line_token.is_some() && block_tokens.is_none() { + comment::toggle_line_comments(doc, selection, line_token) + } else { + let default_block_tokens = &[BlockCommentToken::default()]; + let block_comment_tokens = block_tokens.unwrap_or(default_block_tokens); + comment::toggle_block_comments(doc, selection, block_comment_tokens) + } + }); +} + fn rotate_selections(cx: &mut Context, direction: Direction) { let count = cx.count(); let (view, doc) = current!(cx.editor); diff --git a/helix-term/src/keymap/default.rs b/helix-term/src/keymap/default.rs index 92d6b5906..bab662b04 100644 --- a/helix-term/src/keymap/default.rs +++ b/helix-term/src/keymap/default.rs @@ -276,6 +276,9 @@ pub fn default() -> HashMap { "k" => hover, "r" => rename_symbol, "h" => select_references_to_symbol_under_cursor, + "c" => toggle_comments, + "C" => toggle_block_comments, + "A-c" => toggle_line_comments, "?" => command_palette, }, "z" => { "View" diff --git a/languages.toml b/languages.toml index 313b3d95e..5cfc0c28d 100644 --- a/languages.toml +++ b/languages.toml @@ -191,7 +191,12 @@ injection-regex = "rust" file-types = ["rs"] roots = ["Cargo.toml", "Cargo.lock"] auto-format = true -comment-token = "//" +comment-tokens = ["//", "///", "//!"] +block-comment-tokens = [ + { start = "/*", end = "*/" }, + { start = "/**", end = "*/" }, + { start = "/*!", end = "*/" }, +] language-servers = [ "rust-analyzer" ] indent = { tab-width = 4, unit = " " } persistent-diagnostic-sources = ["rustc", "clippy"] @@ -283,6 +288,7 @@ injection-regex = "protobuf" file-types = ["proto"] language-servers = [ "bufls", "pbkit" ] comment-token = "//" +block-comment-tokens = { start = "/*", end = "*/" } indent = { tab-width = 2, unit = " " } [[grammar]] @@ -326,6 +332,7 @@ injection-regex = "mint" file-types = ["mint"] shebangs = [] comment-token = "//" +block-comment-tokens = { start = "/*", end = "*/" } language-servers = [ "mint" ] indent = { tab-width = 2, unit = " " } @@ -408,6 +415,7 @@ scope = "source.c" injection-regex = "c" file-types = ["c"] # TODO: ["h"] comment-token = "//" +block-comment-tokens = { start = "/*", end = "*/" } language-servers = [ "clangd" ] indent = { tab-width = 2, unit = " " } @@ -444,6 +452,7 @@ scope = "source.cpp" injection-regex = "cpp" file-types = ["cc", "hh", "c++", "cpp", "hpp", "h", "ipp", "tpp", "cxx", "hxx", "ixx", "txx", "ino", "C", "H", "cu", "cuh", "cppm", "h++", "ii", "inl", { glob = ".hpp.in" }, { glob = ".h.in" }] comment-token = "//" +block-comment-tokens = { start = "/*", end = "*/" } language-servers = [ "clangd" ] indent = { tab-width = 2, unit = " " } @@ -491,6 +500,7 @@ injection-regex = "c-?sharp" file-types = ["cs", "csx", "cake"] roots = ["sln", "csproj"] comment-token = "//" +block-comment-tokens = { start = "/*", end = "*/" } indent = { tab-width = 4, unit = "\t" } language-servers = [ "omnisharp" ] @@ -549,6 +559,7 @@ file-types = ["go"] roots = ["go.work", "go.mod"] auto-format = true comment-token = "//" +block-comment-tokens = { start = "/*", end = "*/" } language-servers = [ "gopls", "golangci-lint-lsp" ] # TODO: gopls needs utf-8 offsets? indent = { tab-width = 4, unit = "\t" } @@ -614,6 +625,7 @@ scope = "source.gotmpl" injection-regex = "gotmpl" file-types = ["gotmpl"] comment-token = "//" +block-comment-tokens = { start = "/*", end = "*/" } language-servers = [ "gopls" ] indent = { tab-width = 2, unit = " " } @@ -643,6 +655,7 @@ language-id = "javascript" file-types = ["js", "mjs", "cjs", "rules", "es6", "pac", { glob = "jakefile" }] shebangs = ["node"] comment-token = "//" +block-comment-tokens = { start = "/*", end = "*/" } language-servers = [ "typescript-language-server" ] indent = { tab-width = 2, unit = " " } @@ -669,6 +682,7 @@ injection-regex = "jsx" language-id = "javascriptreact" file-types = ["jsx"] comment-token = "//" +block-comment-tokens = { start = "/*", end = "*/" } language-servers = [ "typescript-language-server" ] indent = { tab-width = 2, unit = " " } grammar = "javascript" @@ -680,6 +694,8 @@ injection-regex = "(ts|typescript)" file-types = ["ts", "mts", "cts"] language-id = "typescript" shebangs = ["deno", "ts-node"] +comment-token = "//" +block-comment-tokens = { start = "/*", end = "*/" } language-servers = [ "typescript-language-server" ] indent = { tab-width = 2, unit = " " } @@ -693,6 +709,8 @@ scope = "source.tsx" injection-regex = "(tsx)" # |typescript language-id = "typescriptreact" file-types = ["tsx"] +comment-token = "//" +block-comment-tokens = { start = "/*", end = "*/" } language-servers = [ "typescript-language-server" ] indent = { tab-width = 2, unit = " " } @@ -705,6 +723,7 @@ name = "css" scope = "source.css" injection-regex = "css" file-types = ["css", "scss"] +block-comment-tokens = { start = "/*", end = "*/" } language-servers = [ "vscode-css-language-server" ] auto-format = true indent = { tab-width = 2, unit = " " } @@ -718,6 +737,7 @@ name = "scss" scope = "source.scss" injection-regex = "scss" file-types = ["scss"] +block-comment-tokens = { start = "/*", end = "*/" } language-servers = [ "vscode-css-language-server" ] auto-format = true indent = { tab-width = 2, unit = " " } @@ -731,6 +751,7 @@ name = "html" scope = "text.html.basic" injection-regex = "html" file-types = ["html", "htm", "shtml", "xhtml", "xht", "jsp", "asp", "aspx", "jshtm", "volt", "rhtml"] +block-comment-tokens = { start = "" } language-servers = [ "vscode-html-language-server" ] auto-format = true indent = { tab-width = 2, unit = " " } @@ -901,6 +922,7 @@ injection-regex = "php" file-types = ["php", "inc", "php4", "php5", "phtml", "ctp"] shebangs = ["php"] roots = ["composer.json", "index.php"] +comment-token = "//" language-servers = [ "intelephense" ] indent = { tab-width = 4, unit = " " } @@ -913,6 +935,7 @@ name = "twig" scope = "source.twig" injection-regex = "twig" file-types = ["twig"] +block-comment-tokens = { start = "{#", end = "#}" } indent = { tab-width = 2, unit = " " } [[grammar]] @@ -966,6 +989,7 @@ injection-regex = "lean" file-types = ["lean"] roots = [ "lakefile.lean" ] comment-token = "--" +block-comment-tokens = { start = "/-", end = "-/" } language-servers = [ "lean" ] indent = { tab-width = 2, unit = " " } @@ -992,6 +1016,7 @@ file-types = ["jl"] shebangs = ["julia"] roots = ["Manifest.toml", "Project.toml"] comment-token = "#" +block-comment-tokens = { start = "#=", end = "=#" } language-servers = [ "julia" ] indent = { tab-width = 4, unit = " " } @@ -1055,6 +1080,7 @@ scope = "source.ocaml" injection-regex = "ocaml" file-types = ["ml"] shebangs = ["ocaml", "ocamlrun", "ocamlscript"] +block-comment-tokens = { start = "(*", end = "*)" } comment-token = "(**)" language-servers = [ "ocamllsp" ] indent = { tab-width = 2, unit = " " } @@ -1074,6 +1100,7 @@ name = "ocaml-interface" scope = "source.ocaml.interface" file-types = ["mli"] shebangs = [] +block-comment-tokens = { start = "(*", end = "*)" } comment-token = "(**)" language-servers = [ "ocamllsp" ] indent = { tab-width = 2, unit = " " } @@ -1096,6 +1123,7 @@ file-types = ["lua"] shebangs = ["lua", "luajit"] roots = [".luarc.json", ".luacheckrc", ".stylua.toml", "selene.toml", ".git"] comment-token = "--" +block-comment-tokens = { start = "--[[", end = "--]]" } indent = { tab-width = 2, unit = " " } language-servers = [ "lua-language-server" ] @@ -1121,6 +1149,7 @@ scope = "source.vue" injection-regex = "vue" file-types = ["vue"] roots = ["package.json"] +block-comment-tokens = { start = "" } indent = { tab-width = 2, unit = " " } language-servers = [ "vuels" ] @@ -1148,6 +1177,7 @@ injection-regex = "haskell" file-types = ["hs", "hs-boot"] roots = ["Setup.hs", "stack.yaml", "cabal.project"] comment-token = "--" +block-comment-tokens = { start = "{-", end = "-}" } language-servers = [ "haskell-language-server" ] indent = { tab-width = 2, unit = " " } @@ -1173,6 +1203,7 @@ injection-regex = "purescript" file-types = ["purs"] roots = ["spago.yaml", "spago.dhall", "bower.json"] comment-token = "--" +block-comment-tokens = { start = "{-", end = "-}" } language-servers = [ "purescript-language-server" ] indent = { tab-width = 2, unit = " " } auto-format = true @@ -1227,6 +1258,7 @@ scope = "source.prolog" file-types = ["pl", "prolog"] shebangs = ["swipl"] comment-token = "%" +block-comment-tokens = { start = "/*", end = "*/" } language-servers = [ "swipl" ] [[language]] @@ -1246,6 +1278,7 @@ name = "cmake" scope = "source.cmake" file-types = ["cmake", { glob = "CMakeLists.txt" }] comment-token = "#" +block-comment-tokens = { start = "#[[", end = "]]" } indent = { tab-width = 2, unit = " " } language-servers = [ "cmake-language-server" ] injection-regex = "cmake" @@ -1272,6 +1305,7 @@ name = "glsl" scope = "source.glsl" file-types = ["glsl", "vert", "tesc", "tese", "geom", "frag", "comp" ] comment-token = "//" +block-comment-tokens = { start = "/*", end = "*/" } indent = { tab-width = 4, unit = " " } injection-regex = "glsl" @@ -1309,6 +1343,7 @@ file-types = ["rkt", "rktd", "rktl", "scrbl"] shebangs = ["racket"] comment-token = ";" indent = { tab-width = 2, unit = " " } +block-comment-tokens = { start = "#|", end = "|#" } language-servers = [ "racket" ] grammar = "scheme" @@ -1343,6 +1378,7 @@ name = "wgsl" scope = "source.wgsl" file-types = ["wgsl"] comment-token = "//" +block-comment-tokens = { start = "/*", end = "*/" } language-servers = [ "wgsl_analyzer" ] indent = { tab-width = 4, unit = " " } @@ -1389,6 +1425,7 @@ name = "tablegen" scope = "source.tablegen" file-types = ["td"] comment-token = "//" +block-comment-tokens = { start = "/*", end = "*/" } indent = { tab-width = 2, unit = " " } injection-regex = "tablegen" @@ -1404,6 +1441,7 @@ file-types = ["md", "markdown", "mkd", "mdwn", "mdown", "markdn", "mdtxt", "mdte roots = [".marksman.toml"] language-servers = [ "marksman" ] indent = { tab-width = 2, unit = " " } +block-comment-tokens = { start = "" } [[grammar]] name = "markdown" @@ -1427,6 +1465,7 @@ file-types = ["dart"] roots = ["pubspec.yaml"] auto-format = true comment-token = "//" +block-comment-tokens = { start = "/*", end = "*/" } language-servers = [ "dart" ] indent = { tab-width = 2, unit = " " } @@ -1440,6 +1479,7 @@ scope = "source.scala" roots = ["build.sbt", "build.sc", "build.gradle", "build.gradle.kts", "pom.xml", ".scala-build"] file-types = ["scala", "sbt", "sc"] comment-token = "//" +block-comment-tokens = { start = "/*", end = "*/" } indent = { tab-width = 2, unit = " " } language-servers = [ "metals" ] @@ -1560,6 +1600,8 @@ scope = "source.graphql" injection-regex = "graphql" file-types = ["gql", "graphql", "graphqls"] language-servers = [ "graphql-language-service" ] +comment-token = "#" +block-comment-tokens = { start = "\"\"\"", end = "\"\"\"" } indent = { tab-width = 2, unit = " " } [[grammar]] @@ -1574,6 +1616,7 @@ file-types = ["elm"] roots = ["elm.json"] auto-format = true comment-token = "--" +block-comment-tokens = { start = "{-", end = "-}" } language-servers = [ "elm-language-server" ] indent = { tab-width = 4, unit = " " } @@ -1586,6 +1629,7 @@ name = "iex" scope = "source.iex" injection-regex = "iex" file-types = ["iex"] +comment-token = "#" [[grammar]] name = "iex" @@ -1599,6 +1643,7 @@ file-types = ["res"] roots = ["bsconfig.json"] auto-format = true comment-token = "//" +block-comment-tokens = { start = "/*", end = "*/" } language-servers = [ "rescript-language-server" ] indent = { tab-width = 2, unit = " " } @@ -1635,6 +1680,7 @@ scope = "source.kotlin" file-types = ["kt", "kts"] roots = ["settings.gradle", "settings.gradle.kts"] comment-token = "//" +block-comment-tokens = { start = "/*", end = "*/" } indent = { tab-width = 4, unit = " " } language-servers = [ "kotlin-language-server" ] @@ -1649,6 +1695,7 @@ injection-regex = "(hcl|tf|nomad)" language-id = "terraform" file-types = ["hcl", "tf", "nomad"] comment-token = "#" +block-comment-tokens = { start = "/*", end = "*/" } indent = { tab-width = 2, unit = " " } language-servers = [ "terraform-ls" ] auto-format = true @@ -1663,6 +1710,7 @@ scope = "source.tfvars" language-id = "terraform-vars" file-types = ["tfvars"] comment-token = "#" +block-comment-tokens = { start = "/*", end = "*/" } indent = { tab-width = 2, unit = " " } language-servers = [ "terraform-ls" ] auto-format = true @@ -1685,6 +1733,7 @@ scope = "source.sol" injection-regex = "(sol|solidity)" file-types = ["sol"] comment-token = "//" +block-comment-tokens = { start = "/*", end = "*/" } indent = { tab-width = 4, unit = " " } language-servers = [ "solc" ] @@ -1713,6 +1762,7 @@ scope = "source.ron" injection-regex = "ron" file-types = ["ron"] comment-token = "//" +block-comment-tokens = { start = "/*", end = "*/" } indent = { tab-width = 4, unit = " " } [[grammar]] @@ -1754,6 +1804,7 @@ injection-regex = "(r|R)md" file-types = ["rmd", "Rmd"] indent = { tab-width = 2, unit = " " } grammar = "markdown" +block-comment-tokens = { start = "" } language-servers = [ "r" ] [[language]] @@ -1763,6 +1814,7 @@ injection-regex = "swift" file-types = ["swift"] roots = [ "Package.swift" ] comment-token = "//" +block-comment-tokens = { start = "/*", end = "*/" } auto-format = true language-servers = [ "sourcekit-lsp" ] @@ -1775,6 +1827,7 @@ name = "erb" scope = "text.html.erb" injection-regex = "erb" file-types = ["erb"] +block-comment-tokens = { start = "" } indent = { tab-width = 2, unit = " " } grammar = "embedded-template" @@ -1783,6 +1836,7 @@ name = "ejs" scope = "text.html.ejs" injection-regex = "ejs" file-types = ["ejs"] +block-comment-tokens = { start = "" } indent = { tab-width = 2, unit = " " } grammar = "embedded-template" @@ -1796,6 +1850,7 @@ scope = "source.eex" injection-regex = "eex" file-types = ["eex"] roots = ["mix.exs", "mix.lock"] +block-comment-tokens = { start = "" } indent = { tab-width = 2, unit = " " } [[grammar]] @@ -1808,6 +1863,7 @@ scope = "source.heex" injection-regex = "heex" file-types = ["heex"] roots = ["mix.exs", "mix.lock"] +block-comment-tokens = { start = "" } indent = { tab-width = 2, unit = " " } language-servers = [ "elixir-ls" ] @@ -1820,6 +1876,7 @@ name = "sql" scope = "source.sql" file-types = ["sql", "dsql"] comment-token = "--" +block-comment-tokens = { start = "/*", end = "*/" } indent = { tab-width = 4, unit = " " } injection-regex = "sql" @@ -1878,6 +1935,7 @@ scope = "source.vala" injection-regex = "vala" file-types = ["vala", "vapi"] comment-token = "//" +block-comment-tokens = { start = "/*", end = "*/" } indent = { tab-width = 2, unit = " " } language-servers = [ "vala-language-server" ] @@ -1903,6 +1961,7 @@ scope = "source.devicetree" injection-regex = "(dtsi?|devicetree|fdt)" file-types = ["dts", "dtsi"] comment-token = "//" +block-comment-tokens = { start = "/*", end = "*/" } indent = { tab-width = 4, unit = "\t" } [[grammar]] @@ -1941,6 +2000,7 @@ file-types = ["odin"] roots = ["ols.json"] language-servers = [ "ols" ] comment-token = "//" +block-comment-tokens = { start = "/*", end = "*/" } indent = { tab-width = 4, unit = "\t" } formatter = { command = "odinfmt", args = [ "-stdin", "true" ] } @@ -1998,6 +2058,7 @@ roots = ["v.mod"] language-servers = [ "vlang-language-server" ] auto-format = true comment-token = "//" +block-comment-tokens = { start = "/*", end = "*/" } indent = { tab-width = 4, unit = "\t" } [[grammar]] @@ -2009,6 +2070,7 @@ name = "verilog" scope = "source.verilog" file-types = ["v", "vh", "sv", "svh"] comment-token = "//" +block-comment-tokens = { start = "/*", end = "*/" } language-servers = [ "svlangserver" ] indent = { tab-width = 2, unit = " " } injection-regex = "verilog" @@ -2045,6 +2107,7 @@ scope = "source.openscad" injection-regex = "openscad" file-types = ["scad"] comment-token = "//" +block-comment-tokens = { start = "/*", end = "*/" } language-servers = [ "openscad-lsp" ] indent = { tab-width = 2, unit = "\t" } @@ -2109,6 +2172,7 @@ injection-regex = "idr" file-types = ["idr"] shebangs = [] comment-token = "--" +block-comment-tokens = { start = "{-", end = "-}" } indent = { tab-width = 2, unit = " " } language-servers = [ "idris2-lsp" ] @@ -2144,6 +2208,7 @@ scope = "source.dot" injection-regex = "dot" file-types = ["dot"] comment-token = "//" +block-comment-tokens = { start = "/*", end = "*/" } indent = { tab-width = 4, unit = " " } language-servers = [ "dot-language-server" ] @@ -2173,6 +2238,7 @@ scope = "source.slint" injection-regex = "slint" file-types = ["slint"] comment-token = "//" +block-comment-tokens = { start = "/*", end = "*/" } indent = { tab-width = 4, unit = " " } language-servers = [ "slint-lsp" ] @@ -2222,6 +2288,7 @@ scope = "source.pascal" injection-regex = "pascal" file-types = ["pas", "pp", "inc", "lpr", "lfm"] comment-token = "//" +block-comment-tokens = { start = "{", end = "}" } indent = { tab-width = 2, unit = " " } language-servers = [ "pasls" ] @@ -2234,7 +2301,7 @@ name = "sml" scope = "source.sml" injection-regex = "sml" file-types = ["sml"] -comment-token = "(*" +block-comment-tokens = { start = "(*", end = "*)" } [[grammar]] name = "sml" @@ -2246,6 +2313,7 @@ scope = "source.jsonnet" file-types = ["libsonnet", "jsonnet"] roots = ["jsonnetfile.json"] comment-token = "//" +block-comment-tokens = { start = "/*", end = "*/" } indent = { tab-width = 2, unit = " " } language-servers = [ "jsonnet-language-server" ] @@ -2258,6 +2326,7 @@ name = "astro" scope = "source.astro" injection-regex = "astro" file-types = ["astro"] +block-comment-tokens = { start = "" } indent = { tab-width = 2, unit = " " } [[grammar]] @@ -2281,6 +2350,7 @@ source = { git = "https://github.com/vito/tree-sitter-bass", rev = "501133e260d7 name = "wat" scope = "source.wat" comment-token = ";;" +block-comment-tokens = { start = "(;", end = ";)" } file-types = ["wat"] [[grammar]] @@ -2291,6 +2361,7 @@ source = { git = "https://github.com/wasm-lsp/tree-sitter-wasm", rev = "2ca28a9f name = "wast" scope = "source.wast" comment-token = ";;" +block-comment-tokens = { start = "(;", end = ";)" } file-types = ["wast"] [[grammar]] @@ -2302,6 +2373,7 @@ name = "d" scope = "source.d" file-types = [ "d", "dd" ] comment-token = "//" +block-comment-tokens = { start = "/*", end = "*/" } injection-regex = "d" indent = { tab-width = 4, unit = " "} language-servers = [ "serve-d" ] @@ -2328,6 +2400,7 @@ name = "kdl" scope = "source.kdl" file-types = ["kdl"] comment-token = "//" +block-comment-tokens = { start = "/*", end = "*/" } injection-regex = "kdl" [[grammar]] @@ -2398,6 +2471,7 @@ file-types = [ "musicxml", "glif" ] +block-comment-tokens = { start = "" } indent = { tab-width = 2, unit = " " } [language.auto-pairs] @@ -2437,6 +2511,7 @@ scope = "source.wit" injection-regex = "wit" file-types = ["wit"] comment-token = "//" +block-comment-tokens = { start = "/*", end = "*/" } indent = { tab-width = 2, unit = " " } [language.auto-pairs] @@ -2501,6 +2576,7 @@ scope = "source.bicep" file-types = ["bicep"] auto-format = true comment-token = "//" +block-comment-tokens = { start = "/*", end = "*/" } indent = { tab-width = 2, unit = " "} language-servers = [ "bicep-langserver" ] @@ -2513,6 +2589,8 @@ name = "qml" scope = "source.qml" file-types = ["qml"] language-servers = [ "qmlls" ] +comment-token = "//" +block-comment-tokens = { start = "/*", end = "*/" } indent = { tab-width = 4, unit = " " } grammar = "qmljs" @@ -2552,6 +2630,7 @@ injection-regex = "pony" roots = ["corral.json", "lock.json"] indent = { tab-width = 2, unit = " " } comment-token = "//" +block-comment-tokens = { start = "/*", end = "*/" } [[grammar]] name = "ponylang" @@ -2563,6 +2642,7 @@ scope = "source.dhall" injection-regex = "dhall" file-types = ["dhall"] comment-token = "--" +block-comment-tokens = { start = "{-", end = "-}" } indent = { tab-width = 2, unit = " " } language-servers = [ "dhall-lsp-server" ] formatter = { command = "dhall" , args = ["format"] } @@ -2586,6 +2666,7 @@ scope = "source.msbuild" injection-regex = "msbuild" file-types = ["proj", "vbproj", "csproj", "fsproj", "targets", "props"] indent = { tab-width = 2, unit = " " } +block-comment-tokens = { start = "" } grammar = "xml" [language.auto-pairs] @@ -2632,7 +2713,7 @@ scope = "source.tal" injection-regex = "tal" file-types = ["tal"] auto-format = false -comment-token = "(" +block-comment-tokens = { start = "(", end = ")" } [[grammar]] name = "uxntal" @@ -2766,6 +2847,7 @@ injection-regex = "nim" file-types = ["nim", "nims", "nimble"] shebangs = [] comment-token = "#" +block-comment-tokens = { start = "#[", end = "]#" } indent = { tab-width = 2, unit = " " } language-servers = [ "nimlangserver" ] @@ -2805,6 +2887,7 @@ source = { git = "https://github.com/pfeiferj/tree-sitter-hurl", rev = "264c4206 [[language]] name = "markdoc" scope = "text.markdoc" +block-comment-tokens = { start = "" } file-types = ["mdoc"] language-servers = [ "markdoc-ls" ] @@ -2858,6 +2941,7 @@ scope = "source.blueprint" injection-regex = "blueprint" file-types = ["blp"] comment-token = "//" +block-comment-tokens = { start = "/*", end = "*/" } language-servers = [ "blueprint-compiler" ] indent = { tab-width = 4, unit = " " } @@ -2910,6 +2994,7 @@ name = "webc" scope = "text.html.webc" injection-regex = "webc" file-types = ["webc"] +block-comment-tokens = { start = "" } indent = { tab-width = 2, unit = " " } grammar = "html" From 00653c772e7df6f68071d1cb1c92bfe9ca4876f9 Mon Sep 17 00:00:00 2001 From: Mo <76752051+mo8it@users.noreply.github.com> Date: Tue, 27 Feb 2024 18:24:05 +0100 Subject: [PATCH 014/114] Avoid cloning the whole paragraph content just for rendering (#9739) * Avoid cloning the whole paragraph content just for rendering * Fix tests --- helix-term/src/ui/editor.rs | 3 ++- helix-term/src/ui/info.rs | 3 ++- helix-term/src/ui/lsp.rs | 4 ++-- helix-term/src/ui/markdown.rs | 2 +- helix-term/src/ui/text.rs | 2 +- helix-tui/src/widgets/paragraph.rs | 19 ++++++++----------- helix-tui/tests/terminal.rs | 6 ++++-- helix-tui/tests/widgets_paragraph.rs | 18 +++++++++--------- 8 files changed, 29 insertions(+), 28 deletions(-) diff --git a/helix-term/src/ui/editor.rs b/helix-term/src/ui/editor.rs index 15a7262a8..dffaeea03 100644 --- a/helix-term/src/ui/editor.rs +++ b/helix-term/src/ui/editor.rs @@ -716,7 +716,8 @@ impl EditorView { } } - let paragraph = Paragraph::new(lines) + let text = Text::from(lines); + let paragraph = Paragraph::new(&text) .alignment(Alignment::Right) .wrap(Wrap { trim: true }); let width = 100.min(viewport.width); diff --git a/helix-term/src/ui/info.rs b/helix-term/src/ui/info.rs index cc6b7483f..651e5ca93 100644 --- a/helix-term/src/ui/info.rs +++ b/helix-term/src/ui/info.rs @@ -2,6 +2,7 @@ use crate::compositor::{Component, Context}; use helix_view::graphics::{Margin, Rect}; use helix_view::info::Info; use tui::buffer::Buffer as Surface; +use tui::text::Text; use tui::widgets::{Block, Borders, Paragraph, Widget}; impl Component for Info { @@ -31,7 +32,7 @@ impl Component for Info { let inner = block.inner(area).inner(&margin); block.render(area, surface); - Paragraph::new(self.text.as_str()) + Paragraph::new(&Text::from(self.text.as_str())) .style(text_style) .render(inner, surface); } diff --git a/helix-term/src/ui/lsp.rs b/helix-term/src/ui/lsp.rs index 879f963e7..a3698e38d 100644 --- a/helix-term/src/ui/lsp.rs +++ b/helix-term/src/ui/lsp.rs @@ -77,7 +77,7 @@ impl Component for SignatureHelp { let (_, sig_text_height) = crate::ui::text::required_size(&sig_text, area.width); let sig_text_area = area.clip_top(1).with_height(sig_text_height); let sig_text_area = sig_text_area.inner(&margin).intersection(surface.area); - let sig_text_para = Paragraph::new(sig_text).wrap(Wrap { trim: false }); + let sig_text_para = Paragraph::new(&sig_text).wrap(Wrap { trim: false }); sig_text_para.render(sig_text_area, surface); if self.signature_doc.is_none() { @@ -100,7 +100,7 @@ impl Component for SignatureHelp { let sig_doc_area = area .clip_top(sig_text_area.height + 2) .clip_bottom(u16::from(cx.editor.popup_border())); - let sig_doc_para = Paragraph::new(sig_doc) + let sig_doc_para = Paragraph::new(&sig_doc) .wrap(Wrap { trim: false }) .scroll((cx.scroll.unwrap_or_default() as u16, 0)); sig_doc_para.render(sig_doc_area.inner(&margin), surface); diff --git a/helix-term/src/ui/markdown.rs b/helix-term/src/ui/markdown.rs index 749d58508..81499d039 100644 --- a/helix-term/src/ui/markdown.rs +++ b/helix-term/src/ui/markdown.rs @@ -346,7 +346,7 @@ impl Component for Markdown { let text = self.parse(Some(&cx.editor.theme)); - let par = Paragraph::new(text) + let par = Paragraph::new(&text) .wrap(Wrap { trim: false }) .scroll((cx.scroll.unwrap_or_default() as u16, 0)); diff --git a/helix-term/src/ui/text.rs b/helix-term/src/ui/text.rs index a379536f8..a9c995627 100644 --- a/helix-term/src/ui/text.rs +++ b/helix-term/src/ui/text.rs @@ -33,7 +33,7 @@ impl Component for Text { fn render(&mut self, area: Rect, surface: &mut Surface, _cx: &mut Context) { use tui::widgets::{Paragraph, Widget, Wrap}; - let par = Paragraph::new(self.contents.clone()).wrap(Wrap { trim: false }); + let par = Paragraph::new(&self.contents).wrap(Wrap { trim: false }); // .scroll(x, y) offsets par.render(area, surface); diff --git a/helix-tui/src/widgets/paragraph.rs b/helix-tui/src/widgets/paragraph.rs index 4e8391621..9c8ae127c 100644 --- a/helix-tui/src/widgets/paragraph.rs +++ b/helix-tui/src/widgets/paragraph.rs @@ -28,15 +28,15 @@ fn get_line_offset(line_width: u16, text_area_width: u16, alignment: Alignment) /// # use helix_tui::widgets::{Block, Borders, Paragraph, Wrap}; /// # use helix_tui::layout::{Alignment}; /// # use helix_view::graphics::{Style, Color, Modifier}; -/// let text = vec![ +/// let text = Text::from(vec![ /// Spans::from(vec![ /// Span::raw("First"), /// Span::styled("line",Style::default().add_modifier(Modifier::ITALIC)), /// Span::raw("."), /// ]), /// Spans::from(Span::styled("Second line", Style::default().fg(Color::Red))), -/// ]; -/// Paragraph::new(text) +/// ]); +/// Paragraph::new(&text) /// .block(Block::default().title("Paragraph").borders(Borders::ALL)) /// .style(Style::default().fg(Color::White).bg(Color::Black)) /// .alignment(Alignment::Center) @@ -51,7 +51,7 @@ pub struct Paragraph<'a> { /// How to wrap the text wrap: Option, /// The text to display - text: Text<'a>, + text: &'a Text<'a>, /// Scroll scroll: (u16, u16), /// Alignment of the text @@ -70,7 +70,7 @@ pub struct Paragraph<'a> { /// - Here is another point that is long enough to wrap"#); /// /// // With leading spaces trimmed (window width of 30 chars): -/// Paragraph::new(bullet_points.clone()).wrap(Wrap { trim: true }); +/// Paragraph::new(&bullet_points).wrap(Wrap { trim: true }); /// // Some indented points: /// // - First thing goes here and is /// // long so that it wraps @@ -78,7 +78,7 @@ pub struct Paragraph<'a> { /// // is long enough to wrap /// /// // But without trimming, indentation is preserved: -/// Paragraph::new(bullet_points).wrap(Wrap { trim: false }); +/// Paragraph::new(&bullet_points).wrap(Wrap { trim: false }); /// // Some indented points: /// // - First thing goes here /// // and is long so that it wraps @@ -92,15 +92,12 @@ pub struct Wrap { } impl<'a> Paragraph<'a> { - pub fn new(text: T) -> Paragraph<'a> - where - T: Into>, - { + pub fn new(text: &'a Text) -> Paragraph<'a> { Paragraph { block: None, style: Default::default(), wrap: None, - text: text.into(), + text, scroll: (0, 0), alignment: Alignment::Left, } diff --git a/helix-tui/tests/terminal.rs b/helix-tui/tests/terminal.rs index 2824c9f24..d2d8ca101 100644 --- a/helix-tui/tests/terminal.rs +++ b/helix-tui/tests/terminal.rs @@ -17,14 +17,16 @@ fn terminal_buffer_size_should_not_be_limited() { // let backend = TestBackend::new(10, 10); // let mut terminal = Terminal::new(backend)?; // let frame = terminal.draw(|f| { -// let paragraph = Paragraph::new("Test"); +// let text = Text::from("Test"); +// let paragraph = Paragraph::new(&text); // f.render_widget(paragraph, f.size()); // })?; // assert_eq!(frame.buffer.get(0, 0).symbol, "T"); // assert_eq!(frame.area, Rect::new(0, 0, 10, 10)); // terminal.backend_mut().resize(8, 8); // let frame = terminal.draw(|f| { -// let paragraph = Paragraph::new("test"); +// let text = Text::from("test"); +// let paragraph = Paragraph::new(&text); // f.render_widget(paragraph, f.size()); // })?; // assert_eq!(frame.buffer.get(0, 0).symbol, "t"); diff --git a/helix-tui/tests/widgets_paragraph.rs b/helix-tui/tests/widgets_paragraph.rs index a7c972eb5..3d2ac467b 100644 --- a/helix-tui/tests/widgets_paragraph.rs +++ b/helix-tui/tests/widgets_paragraph.rs @@ -21,8 +21,8 @@ // terminal // .draw(|f| { // let size = f.size(); -// let text = vec![Spans::from(SAMPLE_STRING)]; -// let paragraph = Paragraph::new(text) +// let text = Text::from(SAMPLE_STRING); +// let paragraph = Paragraph::new(&text) // .block(Block::default().borders(Borders::ALL)) // .alignment(alignment) // .wrap(Wrap { trim: true }); @@ -88,8 +88,8 @@ // terminal // .draw(|f| { // let size = f.size(); -// let text = vec![Spans::from(s)]; -// let paragraph = Paragraph::new(text) +// let text = Text::from(s); +// let paragraph = Paragraph::new(&text) // .block(Block::default().borders(Borders::ALL)) // .wrap(Wrap { trim: true }); // f.render_widget(paragraph, size); @@ -120,8 +120,8 @@ // terminal // .draw(|f| { // let size = f.size(); -// let text = vec![Spans::from(s)]; -// let paragraph = Paragraph::new(text) +// let text = Text::from(s); +// let paragraph = Paragraph::new(&text) // .block(Block::default().borders(Borders::ALL)) // .wrap(Wrap { trim: true }); // f.render_widget(paragraph, size); @@ -155,8 +155,8 @@ // terminal // .draw(|f| { // let size = f.size(); - -// let paragraph = Paragraph::new(line).block(Block::default().borders(Borders::ALL)); +// let text = Text::from(line); +// let paragraph = Paragraph::new(&text).block(Block::default().borders(Borders::ALL)); // f.render_widget(paragraph, size); // }) // .unwrap(); @@ -174,7 +174,7 @@ // let text = Text::from( // "段落现在可以水平滚动了!\nParagraph can scroll horizontally!\nShort line", // ); -// let paragraph = Paragraph::new(text) +// let paragraph = Paragraph::new(&text) // .block(Block::default().borders(Borders::ALL)) // .alignment(alignment) // .scroll(scroll); From 083a9e775d31678f4d984c526e7140c0d2bb2312 Mon Sep 17 00:00:00 2001 From: Chris Date: Wed, 28 Feb 2024 12:18:00 +0000 Subject: [PATCH 015/114] Add support for pde files (#9741) --- languages.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/languages.toml b/languages.toml index 5cfc0c28d..ea2339f8b 100644 --- a/languages.toml +++ b/languages.toml @@ -1028,7 +1028,7 @@ source = { git = "https://github.com/tree-sitter/tree-sitter-julia", rev = "8fb3 name = "java" scope = "source.java" injection-regex = "java" -file-types = ["java", "jav"] +file-types = ["java", "jav", "pde"] roots = ["pom.xml", "build.gradle", "build.gradle.kts"] language-servers = [ "jdtls" ] indent = { tab-width = 2, unit = " " } From f03b91d1b7907e78a4242c5b525e47c997f4457d Mon Sep 17 00:00:00 2001 From: Brian Dorsey Date: Wed, 28 Feb 2024 11:55:17 -0800 Subject: [PATCH 016/114] update languages.toml: tree-sitter-lua grammar (#9727) * update languages.toml: tree-sitter-lua grammar repo has moved, use new URL and the rev of the latest release (v0.0.19) * update highlight queries a novice attempt to port query updates from the source repo to Helix captures and ordering * Apply suggestions from code review Co-authored-by: Michael Davis --------- Co-authored-by: Michael Davis --- languages.toml | 2 +- runtime/queries/lua/highlights.scm | 81 +++++++++++++++++++++++++----- 2 files changed, 69 insertions(+), 14 deletions(-) diff --git a/languages.toml b/languages.toml index ea2339f8b..fb4cda225 100644 --- a/languages.toml +++ b/languages.toml @@ -1129,7 +1129,7 @@ language-servers = [ "lua-language-server" ] [[grammar]] name = "lua" -source = { git = "https://github.com/MunifTanjim/tree-sitter-lua", rev = "887dfd4e83c469300c279314ff1619b1d0b85b91" } +source = { git = "https://github.com/tree-sitter-grammars/tree-sitter-lua", rev = "88e446476a1e97a8724dff7a23e2d709855077f2" } [[language]] name = "svelte" diff --git a/runtime/queries/lua/highlights.scm b/runtime/queries/lua/highlights.scm index f48e607c5..2f3b3c05f 100644 --- a/runtime/queries/lua/highlights.scm +++ b/runtime/queries/lua/highlights.scm @@ -1,9 +1,5 @@ ;;; Highlighting for lua -;;; Builtins -((identifier) @variable.builtin - (#eq? @variable.builtin "self")) - ;; Keywords (if_statement @@ -130,16 +126,65 @@ ((identifier) @constant (#match? @constant "^[A-Z][A-Z_0-9]*$")) -;; Parameters -(parameters - (identifier) @variable.parameter) +;; Tables + +(field name: (identifier) @variable.other.member) + +(dot_index_expression field: (identifier) @variable.other.member) + +(table_constructor +[ + "{" + "}" +] @constructor) -; ;; Functions -(function_declaration name: (identifier) @function) -(function_call name: (identifier) @function.call) +;; Functions -(function_declaration name: (dot_index_expression field: (identifier) @function)) -(function_call name: (dot_index_expression field: (identifier) @function.call)) +(parameters (identifier) @variable.parameter) + +(function_call + (identifier) @function.builtin + (#any-of? @function.builtin + ;; built-in functions in Lua 5.1 + "assert" "collectgarbage" "dofile" "error" "getfenv" "getmetatable" "ipairs" + "load" "loadfile" "loadstring" "module" "next" "pairs" "pcall" "print" + "rawequal" "rawget" "rawset" "require" "select" "setfenv" "setmetatable" + "tonumber" "tostring" "type" "unpack" "xpcall")) + +(function_declaration + name: [ + (identifier) @function + (dot_index_expression + field: (identifier) @function) + ]) + +(function_declaration + name: (method_index_expression + method: (identifier) @function.method)) + +(assignment_statement + (variable_list . + name: [ + (identifier) @function + (dot_index_expression + field: (identifier) @function) + ]) + (expression_list . + value: (function_definition))) + +(table_constructor + (field + name: (identifier) @function + value: (function_definition))) + +(function_call + name: [ + (identifier) @function.call + (dot_index_expression + field: (identifier) @function.call) + (method_index_expression + method: (identifier) @function.method.call) + ]) ; TODO: incorrectly highlights variable N in `N, nop = 42, function() end` (assignment_statement @@ -153,6 +198,7 @@ ;; Nodes (comment) @comment (string) @string +(escape_sequence) @constant.character.escape (number) @constant.numeric.integer (label_statement) @label ; A bit of a tricky one, this will only match field names @@ -162,7 +208,16 @@ ;; Property (dot_index_expression field: (identifier) @variable.other.member) -;; Variable +;; Variables +((identifier) @variable.builtin + (#eq? @variable.builtin "self")) + +(variable_list + (attribute + "<" @punctuation.bracket + (identifier) @attribute + ">" @punctuation.bracket)) + (identifier) @variable ;; Error From 1143f4795414c26382a5647f2be8c20a7a62ada4 Mon Sep 17 00:00:00 2001 From: Pascal Kuthe Date: Thu, 29 Feb 2024 02:47:41 +0100 Subject: [PATCH 017/114] fix split_on_newline (#9756) --- helix-core/src/selection.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/helix-core/src/selection.rs b/helix-core/src/selection.rs index 91f1d0de5..bd252deb9 100644 --- a/helix-core/src/selection.rs +++ b/helix-core/src/selection.rs @@ -773,12 +773,12 @@ pub fn split_on_newline(text: RopeSlice, selection: &Selection) -> Selection { let mut start = sel_start; - for mat in sel.slice(text).lines() { - let len = mat.len_chars(); - let line_end_len = get_line_ending(&mat).map(|le| le.len_chars()).unwrap_or(0); + for line in sel.slice(text).lines() { + let Some(line_ending) = get_line_ending(&line) else { break }; + let line_end = start + line.len_chars(); // TODO: retain range direction - result.push(Range::new(start, start + len - line_end_len)); - start += len; + result.push(Range::new(start, line_end - line_ending.len_chars())); + start = line_end; } if start < sel_end { From e51a1e4e2ae99b8e1ad751e7dfa024a7d0e4ba8f Mon Sep 17 00:00:00 2001 From: JJ Date: Wed, 28 Feb 2024 17:49:10 -0800 Subject: [PATCH 018/114] Switch Nim tree-sitter queries to alaviss/tree-sitter-nim (#9722) --- languages.toml | 4 +- runtime/queries/nim/highlights.scm | 522 ++++++++++++++-------------- runtime/queries/nim/indents.scm | 83 +++-- runtime/queries/nim/textobjects.scm | 44 ++- 4 files changed, 348 insertions(+), 305 deletions(-) diff --git a/languages.toml b/languages.toml index fb4cda225..d2a183ded 100644 --- a/languages.toml +++ b/languages.toml @@ -50,6 +50,7 @@ metals = { command = "metals", config = { "isHttpEnabled" = true } } mint = { command = "mint", args = ["ls"] } nil = { command = "nil" } nimlangserver = { command = "nimlangserver" } +nimlsp = { command = "nimlsp" } nls = { command = "nls" } nu-lsp = { command = "nu", args = [ "--lsp" ] } ocamllsp = { command = "ocamllsp" } @@ -2858,10 +2859,9 @@ language-servers = [ "nimlangserver" ] "'" = "'" '{' = '}' -# Nim's tree-sitter grammar is in heavy development. [[grammar]] name = "nim" -source = { git = "https://github.com/aMOPel/tree-sitter-nim", rev = "240239b232550e431d67de250d1b5856209e7f06" } +source = { git = "https://github.com/alaviss/tree-sitter-nim", rev = "c5f0ce3b65222f5dbb1a12f9fe894524881ad590" } [[language]] name = "cabal" diff --git a/runtime/queries/nim/highlights.scm b/runtime/queries/nim/highlights.scm index 1d3256853..e02ba5165 100644 --- a/runtime/queries/nim/highlights.scm +++ b/runtime/queries/nim/highlights.scm @@ -1,33 +1,32 @@ ;; Constants, Comments, and Literals (comment) @comment.line -(multilineComment) @comment.block -(docComment) @comment.block.documentation -(multilineDocComment) @comment.block.documentation -; comments - -[(literal) (generalizedLit)] @constant -[(nil_lit)] @constant.builtin -[(bool_lit)] @constant.builtin.boolean -[(char_lit)] @constant.character -[(char_esc_seq) (str_esc_seq)] @constant.character.escape -[(custom_numeric_lit)] @constant.numeric -[(int_lit) (int_suffix)] @constant.numeric.integer -[(float_lit) (float_suffix)] @constant.numeric.float +(block_comment) @comment.block +[ + (documentation_comment) + (block_documentation_comment) +] @comment.block.documentation + +(nil_literal) @constant.builtin +((identifier) @constant.builtin.boolean + (#any-of? @constant.builtin.boolean "true" "false" "on" "off")) + +(char_literal) @constant.character +(escape_sequence) @constant.character.escape +(custom_numeric_literal) @constant.numeric +(integer_literal) @constant.numeric.integer +(float_literal) @constant.numeric.float ; literals -; note: somewhat irritatingly for testing, lits have the same syntax highlighting as types +; todo: literal? [ - (str_lit) - (triplestr_lit) - (rstr_lit) - (generalized_str_lit) - (generalized_triplestr_lit) - (interpolated_str_lit) - (interpolated_triplestr_lit) + (long_string_literal) + (raw_string_literal) + (generalized_string) + (interpreted_string_literal) ] @string +; (generalized_string (string_content) @none) ; todo: attempt to un-match string_content ; [] @string.regexp -; string literals [ "." @@ -44,272 +43,291 @@ "}" "{." ".}" - "#[" - "]#" ] @punctuation.bracket -(interpolated_str_lit "&" @punctuation.special) -(interpolated_str_lit "{" @punctuation.special) -(interpolated_str_lit "}" @punctuation.special) -; punctuation +; todo: interpolated_str_lit?? & { }? [ "and" "or" "xor" "not" - "in" - "notin" - "is" - "isnot" "div" "mod" "shl" "shr" + "from" + "as" + "of" + "in" + "notin" + "is" + "isnot" ] @keyword.operator -; operators: we list them explicitly to deliminate them from symbolic operators - -[(operator) (opr) "="] @operator -; all operators (must come after @keyword.operator) -(pragma) @attribute -; pragmas +[(operator) "="] @operator +(infix_expression operator: _ @operator) +(prefix_expression operator: _ @operator) +(pragma_list + (identifier)? @attribute + (colon_expression + (identifier) @attribute)?) ;; Imports and Exports -(importStmt - (keyw) @keyword.control.import - (expr (primary (symbol) @namespace))? - (expr (primary (arrayConstr (exprColonExprList (exprColonExpr (expr (primary (symbol) @namespace)))))))?) -(exportStmt - (keyw) @keyword.control.import - (expr (primary (symbol) @namespace))? - (expr (primary (arrayConstr (exprColonExprList (exprColonExpr (expr (primary (symbol) @namespace)))))))?) -(fromStmt - (keyw) @keyword.control.import - (expr (primary (symbol) @namespace))? - (expr (primary (arrayConstr (exprColonExprList (exprColonExpr (expr (primary (symbol) @namespace)))))))?) -(includeStmt - (keyw) @keyword.control.import - (expr (primary (symbol) @namespace))? - (expr (primary (arrayConstr (exprColonExprList (exprColonExpr (expr (primary (symbol) @namespace)))))))?) -(importExceptStmt - (keyw) @keyword.control.import - (expr (primary (symbol) @namespace))? - (expr (primary (arrayConstr (exprColonExprList (exprColonExpr (expr (primary (symbol) @namespace)))))))?) -; import statements -; yeah, this is a bit gross. - +[ + "import" + "export" + "include" + "from" +] @keyword.control.import + +(import_statement + [ + (identifier) @namespace + (expression_list (identifier) @namespace) + (except_clause + "except" @keyword.control.import + (expression_list (identifier) @namespace))]) +(import_from_statement + (identifier) @namespace + (expression_list (identifier) @namespace)) +(include_statement (expression_list (identifier) @namespace)) +(export_statement (expression_list (identifier) @namespace)) ;; Control Flow -(ifStmt (keyw) @keyword.control.conditional) -(whenStmt (keyw) @keyword.control.conditional) -(elifStmt (keyw) @keyword.control.conditional) -(elseStmt (keyw) @keyword.control.conditional) -(caseStmt (keyw) @keyword.control.conditional) -(ofBranch (keyw) @keyword.control.conditional) -(inlineIfStmt (keyw) @keyword.control.conditional) -(inlineWhenStmt (keyw) @keyword.control.conditional) +[ + "if" + "when" + "case" + "elif" + "else" +] @keyword.control.conditional +(of_branch "of" @keyword.control.conditional) ; conditional statements ; todo: do block -(forStmt - . (keyw) @keyword.control.repeat - . (symbol) @variable - . (keyw) @keyword.control.repeat) -(whileStmt (keyw) @keyword.control.repeat) -; loop statements - -(returnStmt (keyw) @keyword.control.repeat) -(yieldStmt (keyw) @keyword.control.repeat) -(discardStmt (keyw) @keyword.control.repeat) -(breakStmt (keyw) @keyword.control.repeat) -(continueStmt (keyw) @keyword.control.repeat) -; control flow statements - -(raiseStmt (keyw) @keyword.control.exception) -(tryStmt (keyw) @keyword.control.exception) -(tryExceptStmt (keyw) @keyword.control.exception) -(tryFinallyStmt (keyw) @keyword.control.exception) -(inlineTryStmt (keyw) @keyword.control.exception) -; (inlineTryExceptStmt (keyw) @keyword.control.exception) -; (inlineTryFinallyStmt (keyw) @keyword.control.exception) -; exception handling statements +"block" @keyword.control +(block label: (_) @label) -(staticStmt (keyw) @keyword) -(deferStmt (keyw) @keyword) -(asmStmt (keyw) @keyword) -(bindStmt (keyw) @keyword) -(mixinStmt (keyw) @keyword) -; miscellaneous blocks +[ + "for" + "while" + "continue" + "break" +] @keyword.control.repeat +(for "in" @keyword.control.repeat) -(blockStmt - (keyw) @keyword.control - (symbol) @label) -; block statements +[ + "return" + "yield" +] @keyword.control.return +; return statements +[ + "try" + "except" + "finally" + "raise" +] @keyword.control.exception +; exception handling statements -;; Types and Type Declarations +[ + "asm" + "bind" + "mixin" + "defer" + "static" +] @keyword +; miscellaneous keywords -(typeDef - (keyw) @keyword.storage.type - (symbol) @type) -; names of new types type declarations - -(exprColonEqExpr - . (expr (primary (symbol) @variable)) - . (expr (primary (symbol) @type))) -; variables in inline tuple declarations - -(primarySuffix - (indexSuffix - (exprColonEqExprList - (exprColonEqExpr - (expr - (primary - (symbol) @type)))))) -; nested types in brackets, i.e. seq[string] - -(primaryTypeDef (symbol) @type) -; primary types of type declarations (NOT nested types) - -(primaryTypeDef (primaryPrefix (keyw) @type)) -; for consistency - -(primaryTypeDesc (symbol) @type) -; type annotations, on declarations or in objects - -(primaryTypeDesc (primaryPrefix (keyw) @type)) -; var types etc - -(genericParamList (genericParam (symbol) @type)) -; types in generic blocks - -(enumDecl (keyw) @keyword.storage.type) -(enumElement (symbol) @type.enum.variant) -; enum declarations and elements - -(tupleDecl (keyw) @keyword.storage.type) -; tuple declarations - -(objectDecl (keyw) @keyword.storage.type) -(objectPart (symbol) @variable.other.member) -; object declarations and fields - -(objectCase - (keyw) @keyword.control.conditional - (symbol) @variable.other.member) -(objectBranch (keyw) @keyword.control.conditional) -(objectElif (keyw) @keyword.control.conditional) -(objectElse (keyw) @keyword.control.conditional) -(objectWhen (keyw) @keyword.control.conditional) -; variant objects - -(conceptDecl (keyw) @keyword.storage.type) -(conceptParam (keyw) @type) -(conceptParam (symbol) @variable) -; concept declarations, parameters, and qualifiers on those parameters - -((expr - (primary (symbol)) - (operator) @operator - (primary (symbol) @type)) - (#match? @operator "is")) -((exprStmt - (primary (symbol)) - (operator) @operator - (primary (symbol) @type)) - (#match? @operator "is")) -; symbols likely to be types: "x is t" means t is either a type or a type variable - -; distinct? +;; Types and Type Declarations +[ + "let" + "var" + "const" + "type" + "object" + "tuple" + "enum" + "concept" +] @keyword.storage.type + +(var_type "var" @keyword.storage.modifier) +(out_type "out" @keyword.storage.modifier) +(distinct_type "distinct" @keyword.storage.modifier) +(ref_type "ref" @keyword.storage.modifier) +(pointer_type "ptr" @keyword.storage.modifier) + +(var_parameter "var" @keyword.storage.modifier) +(type_parameter "type" @keyword.storage.modifier) +(static_parameter "static" @keyword.storage.modifier) +(ref_parameter "ref" @keyword.storage.modifier) +(pointer_parameter "ptr" @keyword.storage.modifier) +; (var_parameter (identifier) @variable.parameter) +; (type_parameter (identifier) @variable.parameter) +; (static_parameter (identifier) @variable.parameter) +; (ref_parameter (identifier) @variable.parameter) +; (pointer_parameter (identifier) @variable.parameter) +; todo: when are these used?? + +(type_section + (type_declaration + (type_symbol_declaration + name: (_) @type))) +; types in type declarations + +(enum_field_declaration + (symbol_declaration + name: (_) @type.enum.variant)) +; types as enum variants + +(variant_declaration + alternative: (of_branch + values: (expression_list (_) @type.enum.variant))) +; types as object variants + +(case + (of_branch + values: (expression_list (_) @constant))) +; case values are guaranteed to be constant + +(type_expression + [ + (identifier) @type + (bracket_expression + [ + (identifier) @type + (argument_list (identifier) @type)]) + (tuple_construction + [ + (identifier) @type + (bracket_expression + [ + (identifier) @type + (argument_list (identifier) @type)])])]) +; types in type expressions + +(call + function: (bracket_expression + right: (argument_list (identifier) @type))) +; types as generic parameters + +; (dot_generic_call +; generic_arguments: (_) @type) +; ??? + +(infix_expression + operator: + [ + "is" + "isnot" + ] + right: (_) @type) +; types in "is" comparisions + +(except_branch + values: (expression_list + [ + (identifier) @type + (infix_expression + left: (identifier) @type + operator: "as" + right: (_) @variable)])) +; types in exception branches ;; Functions -(routine - . (keyw) @keyword.function - . (symbol) @function) -; function declarations - -(routineExpr (keyw) @keyword.function) -; discarded function - -(routineExprTypeDesc (keyw) @keyword.function) -; function declarations as types - -(primary - . (symbol) @function.call - . (primarySuffix (functionCall))) -; regular function calls - -(primary - . (symbol) @function.call - . (primarySuffix (cmdCall))) -; function calls without parenthesis - -(primary - (primarySuffix (qualifiedSuffix (symbol) @function.call)) - . (primarySuffix (functionCall))) -; uniform function call syntax calls - -(primary - (primarySuffix (qualifiedSuffix (symbol) @function.call)) - . (primarySuffix (cmdCall))) -; just in case - -(primary - (symbol) @constructor - (primarySuffix (objectConstr))) -; object constructor - -; does not appear to be a way to distinguish these without verbatium matching -; [] @function.builtin -; [] @function.method -; [] @function.macro -; [] @function.special - +[ + "proc" + "func" + "method" + "converter" + "iterator" + "template" + "macro" +] @keyword.function + +(exported_symbol "*" @attribute) +(_ "=" @punctuation.delimiter [body: (_) value: (_)]) + +(proc_declaration name: (_) @function) +(func_declaration name: (_) @function) +(iterator_declaration name: (_) @function) +(converter_declaration name: (_) @function) +(method_declaration name: (_) @function.method) +(template_declaration name: (_) @function.macro) +(macro_declaration name: (_) @function.macro) +(symbol_declaration name: (_) @variable) + +(call + function: [ + (identifier) @function.call + (dot_expression + right: (identifier) @function.call) + (bracket_expression + left: [ + (identifier) @function.call + (dot_expression + right: (identifier) @function.call)])]) +(generalized_string + function: [ + (identifier) @function.call + (dot_expression + right: (identifier) @function.call) + (bracket_expression + left: [ + (identifier) @function.call + (dot_expression + right: (identifier) @function.call)])]) +(dot_generic_call function: (_) @function.call) ;; Variables -(paramList (paramColonEquals (symbol) @variable.parameter)) -; parameter identifiers - -(identColon (ident) @variable.other.member) -; named parts of tuples - -(symbolColonExpr (symbol) @variable) -; object constructor parameters - -(symbolEqExpr (symbol) @variable) -; named parameters +(parameter_declaration + (symbol_declaration_list + (symbol_declaration + name: (_) @variable.parameter))) +(argument_list + (equal_expression + left: (_) @variable.parameter)) +(concept_declaration + parameters: (parameter_list (identifier) @variable.parameter)) + +(field_declaration + (symbol_declaration_list + (symbol_declaration + name: (_) @variable.other.member))) +(call + (argument_list + (colon_expression + left: (_) @variable.other.member))) +(tuple_construction + (colon_expression + left: (_) @variable.other.member)) +(variant_declaration + (variant_discriminator_declaration + (symbol_declaration_list + (symbol_declaration + name: (_) @variable.other.member)))) + +;; Miscellaneous Matches -(variable - (keyw) @keyword.storage.type - (declColonEquals (symbol) @variable)) -; let, var, const expressions - -((primary (symbol) @variable.builtin) - (#match? @variable.builtin "result")) -; `result` is an implicit builtin variable inside function scopes - -((primary (symbol) @type) - (#match? @type "^[A-Z]")) -; assume PascalCase identifiers to be types - -((primary - (primarySuffix - (qualifiedSuffix - (symbol) @type))) - (#match? @type "^[A-Z]")) -; assume PascalCase member variables to be enum entries +[ + "cast" + "discard" + "do" +] @keyword +; also: addr end interface using -(primary (symbol) @variable) -; overzealous, matches variables +(blank_identifier) @variable.builtin +((identifier) @variable.builtin + (#eq? @variable.builtin "result")) -(primary (primarySuffix (qualifiedSuffix (symbol) @variable.other.member))) -; overzealous, matches member variables: i.e. x in foo.x +(dot_expression + left: (identifier) @variable + right: (identifier) @variable.other.member) -(keyw) @keyword -; more specific matches are done above whenever possible +(identifier) @variable diff --git a/runtime/queries/nim/indents.scm b/runtime/queries/nim/indents.scm index 677435407..3b3023868 100644 --- a/runtime/queries/nim/indents.scm +++ b/runtime/queries/nim/indents.scm @@ -1,48 +1,59 @@ [ - (typeDef) - (ifStmt) - (whenStmt) - (elifStmt) - (elseStmt) - (ofBranch) ; note: not caseStmt - (whileStmt) - (tryStmt) - (tryExceptStmt) - (tryFinallyStmt) - (forStmt) - (blockStmt) - (staticStmt) - (deferStmt) - (asmStmt) - ; exprStmt? + (if) + (when) + (elif_branch) + (else_branch) + (of_branch) ; note: not case_statement + (block) + (while) + (for) + (try) + (except_branch) + (finally_branch) + (defer) + (static_statement) + (proc_declaration) + (func_declaration) + (iterator_declaration) + (converter_declaration) + (method_declaration) + (template_declaration) + (macro_declaration) + (symbol_declaration) ] @indent ;; increase the indentation level [ - (ifStmt) - (whenStmt) - (elifStmt) - (elseStmt) - (ofBranch) ; note: not caseStmt - (whileStmt) - (tryStmt) - (tryExceptStmt) - (tryFinallyStmt) - (forStmt) - (blockStmt) - (staticStmt) - (deferStmt) - (asmStmt) - ; exprStmt? + (if) + (when) + (elif_branch) + (else_branch) + (of_branch) ; note: not case_statement + (block) + (while) + (for) + (try) + (except_branch) + (finally_branch) + (defer) + (static_statement) + (proc_declaration) + (func_declaration) + (iterator_declaration) + (converter_declaration) + (method_declaration) + (template_declaration) + (macro_declaration) + (symbol_declaration) ] @extend ;; ??? [ - (returnStmt) - (raiseStmt) - (yieldStmt) - (breakStmt) - (continueStmt) + (return_statement) + (raise_statement) + (yield_statement) + (break_statement) + (continue_statement) ] @extend.prevent-once ;; end a level of indentation while staying indented diff --git a/runtime/queries/nim/textobjects.scm b/runtime/queries/nim/textobjects.scm index 943aa7f08..eaa3e8e8c 100644 --- a/runtime/queries/nim/textobjects.scm +++ b/runtime/queries/nim/textobjects.scm @@ -1,19 +1,33 @@ -(routine - (block) @function.inside) @function.around +(proc_declaration + body: (_) @function.inside) @function.around +(func_declaration + body: (_) @function.inside) @function.around +(iterator_declaration + body: (_) @function.inside) @function.around +(converter_declaration + body: (_) @function.inside) @function.around +(method_declaration + body: (_) @function.inside) @function.around +(template_declaration + body: (_) @function.inside) @function.around +(macro_declaration + body: (_) @function.inside) @function.around -; @class.inside (types?) -; @class.around +(type_declaration (_) @class.inside) @class.around -; paramListSuffix is strange and i do not understand it -(paramList - (paramColonEquals) @parameter.inside) @parameter.around +(parameter_declaration + (symbol_declaration_list) @parameter.inside) @parameter.around -(comment) @comment.inside -(multilineComment) @comment.inside -(docComment) @comment.inside -(multilineDocComment) @comment.inside +[ + (comment) + (block_comment) + (documentation_comment) + (block_documentation_comment) +] @comment.inside -(comment)+ @comment.around -(multilineComment) @comment.around -(docComment)+ @comment.around -(multilineDocComment) @comment.around +[ + (comment)+ + (block_comment) + (documentation_comment)+ + (block_documentation_comment)+ +] @comment.around From d0bb77447138f5f70f96b174a8f29045a956c8c4 Mon Sep 17 00:00:00 2001 From: Keir Lawson Date: Thu, 29 Feb 2024 10:09:29 +0000 Subject: [PATCH 019/114] Mark GTK builder ui files as XML (#9754) --- languages.toml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/languages.toml b/languages.toml index d2a183ded..a2c10d114 100644 --- a/languages.toml +++ b/languages.toml @@ -2470,7 +2470,8 @@ file-types = [ "xul", "xoml", "musicxml", - "glif" + "glif", + "ui" ] block-comment-tokens = { start = "" } indent = { tab-width = 2, unit = " " } From 44db25939c9361272660854878eb2fc18fcf08e8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dawid=20Ci=C4=99=C5=BCarkiewicz?= Date: Thu, 29 Feb 2024 17:57:31 -0800 Subject: [PATCH 020/114] Document embracing smart-tab navigation. (#9762) Re #4443 --- book/src/configuration.md | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/book/src/configuration.md b/book/src/configuration.md index de33c1ade..d87936457 100644 --- a/book/src/configuration.md +++ b/book/src/configuration.md @@ -375,8 +375,25 @@ wrap-indicator = "" # set wrap-indicator to "" to hide it ### `[editor.smart-tab]` Section +Options for navigating and editing using tab key. | Key | Description | Default | |------------|-------------|---------| | `enable` | If set to true, then when the cursor is in a position with non-whitespace to its left, instead of inserting a tab, it will run `move_parent_node_end`. If there is only whitespace to the left, then it inserts a tab as normal. With the default bindings, to explicitly insert a tab character, press Shift-tab. | `true` | | `supersede-menu` | Normally, when a menu is on screen, such as when auto complete is triggered, the tab key is bound to cycling through the items. This means when menus are on screen, one cannot use the tab key to trigger the `smart-tab` command. If this option is set to true, the `smart-tab` command always takes precedence, which means one cannot use the tab key to cycle through menu items. One of the other bindings must be used instead, such as arrow keys or `C-n`/`C-p`. | `false` | + + +Due to lack of support for S-tab in some terminals, the default keybindings don't fully embrace smart-tab editing experience. If you enjoy smart-tab navigation and a terminal that supports the [Enhanced Keyboard protocol](https://github.com/helix-editor/helix/wiki/Terminal-Support#enhanced-keyboard-protocol), consider setting extra keybindings: + +``` +[keys.normal] +tab = "move_parent_node_end" +S-tab = "move_parent_node_start" + +[keys.insert] +S-tab = "move_parent_node_start" + +[keys.select] +tab = "extend_parent_node_end" +S-tab = "extend_parent_node_start" +``` From 062fb819a21a3b17baf0cded3463a2d9f3e6b4a9 Mon Sep 17 00:00:00 2001 From: Felix Zeller Date: Fri, 1 Mar 2024 10:10:49 -0500 Subject: [PATCH 021/114] feat: Add markdown-oxide language server (#9758) --- book/src/generated/lang-support.md | 2 +- languages.toml | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/book/src/generated/lang-support.md b/book/src/generated/lang-support.md index 1bc6b0817..c9668549e 100644 --- a/book/src/generated/lang-support.md +++ b/book/src/generated/lang-support.md @@ -104,7 +104,7 @@ | lua | ✓ | ✓ | ✓ | `lua-language-server` | | make | ✓ | | ✓ | | | markdoc | ✓ | | | `markdoc-ls` | -| markdown | ✓ | | | `marksman` | +| markdown | ✓ | | | `marksman`, `markdown-oxide` | | markdown.inline | ✓ | | | | | matlab | ✓ | ✓ | ✓ | | | mermaid | ✓ | | | | diff --git a/languages.toml b/languages.toml index a2c10d114..26f6509ce 100644 --- a/languages.toml +++ b/languages.toml @@ -45,6 +45,7 @@ kotlin-language-server = { command = "kotlin-language-server" } lean = { command = "lean", args = [ "--server" ] } ltex-ls = { command = "ltex-ls" } markdoc-ls = { command = "markdoc-ls", args = ["--stdio"] } +markdown-oxide = { command = "markdown-oxide" } marksman = { command = "marksman", args = ["server"] } metals = { command = "metals", config = { "isHttpEnabled" = true } } mint = { command = "mint", args = ["ls"] } @@ -1440,7 +1441,7 @@ scope = "source.md" injection-regex = "md|markdown" file-types = ["md", "markdown", "mkd", "mdwn", "mdown", "markdn", "mdtxt", "mdtext", "workbook", { glob = "PULLREQ_EDITMSG" }] roots = [".marksman.toml"] -language-servers = [ "marksman" ] +language-servers = [ "marksman", "markdown-oxide" ] indent = { tab-width = 2, unit = " " } block-comment-tokens = { start = "" } From 1d6db30acf91ec1041e014650bf263defdc3feee Mon Sep 17 00:00:00 2001 From: Marcin Drzymala <5504827+drzymalanet@users.noreply.github.com> Date: Sat, 2 Mar 2024 03:05:17 +0100 Subject: [PATCH 022/114] Fix bug 9703 by commenting out the wrong command (#9778) * Fix bug 9703 by commenting out the wrong command This fixes issue https://github.com/helix-editor/helix/issues/9703 by removing the wrong formatting command for justfiles. * Fix indentation width for justfile --- languages.toml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/languages.toml b/languages.toml index 26f6509ce..a4b6a5cd8 100644 --- a/languages.toml +++ b/languages.toml @@ -2915,9 +2915,9 @@ scope = "source.just" file-types = [{ glob = "justfile" }, { glob = "Justfile" }, { glob = ".justfile" }, { glob = ".Justfile" }] injection-regex = "just" comment-token = "#" -indent = { tab-width = 4, unit = "\t" } -auto-format = true -formatter = { command = "just", args = ["--dump"] } +indent = { tab-width = 4, unit = " " } +# auto-format = true +# formatter = { command = "just", args = ["--dump"] } # Please see: https://github.com/helix-editor/helix/issues/9703 [[grammar]] name = "just" From 5ca6a448e9b66f4f5b4caa7cd173252d0a78f92d Mon Sep 17 00:00:00 2001 From: Michael Davis Date: Fri, 1 Mar 2024 23:37:11 -0500 Subject: [PATCH 023/114] Support LSP diagnostic tags (#9780) --- book/src/themes.md | 2 ++ helix-lsp/src/client.rs | 6 ++++++ helix-term/src/ui/editor.rs | 15 ++++++++++++++- theme.toml | 2 ++ 4 files changed, 24 insertions(+), 1 deletion(-) diff --git a/book/src/themes.md b/book/src/themes.md index f040dfb19..04d6a69b3 100644 --- a/book/src/themes.md +++ b/book/src/themes.md @@ -333,5 +333,7 @@ These scopes are used for theming the editor interface: | `diagnostic.info` | Diagnostics info (editing area) | | `diagnostic.warning` | Diagnostics warning (editing area) | | `diagnostic.error` | Diagnostics error (editing area) | +| `diagnostic.unnecessary` | Diagnostics with unnecessary tag (editing area) | +| `diagnostic.deprecated` | Diagnostics with deprecated tag (editing area) | [editor-section]: ./configuration.md#editor-section diff --git a/helix-lsp/src/client.rs b/helix-lsp/src/client.rs index 8d03d7992..a7b3989dd 100644 --- a/helix-lsp/src/client.rs +++ b/helix-lsp/src/client.rs @@ -631,6 +631,12 @@ impl Client { }), publish_diagnostics: Some(lsp::PublishDiagnosticsClientCapabilities { version_support: Some(true), + tag_support: Some(lsp::TagSupport { + value_set: vec![ + lsp::DiagnosticTag::UNNECESSARY, + lsp::DiagnosticTag::DEPRECATED, + ], + }), ..Default::default() }), inlay_hint: Some(lsp::InlayHintClientCapabilities { diff --git a/helix-term/src/ui/editor.rs b/helix-term/src/ui/editor.rs index dffaeea03..f3bba5d1c 100644 --- a/helix-term/src/ui/editor.rs +++ b/helix-term/src/ui/editor.rs @@ -360,7 +360,7 @@ impl EditorView { doc: &Document, theme: &Theme, ) -> [Vec<(usize, std::ops::Range)>; 5] { - use helix_core::diagnostic::Severity; + use helix_core::diagnostic::{DiagnosticTag, Severity}; let get_scope_of = |scope| { theme .find_scope_index_exact(scope) @@ -380,6 +380,10 @@ impl EditorView { let error = get_scope_of("diagnostic.error"); let r#default = get_scope_of("diagnostic"); // this is a bit redundant but should be fine + // Diagnostic tags + let unnecessary = theme.find_scope_index_exact("diagnostic.unnecessary"); + let deprecated = theme.find_scope_index_exact("diagnostic.deprecated"); + let mut default_vec: Vec<(usize, std::ops::Range)> = Vec::new(); let mut info_vec = Vec::new(); let mut hint_vec = Vec::new(); @@ -396,6 +400,15 @@ impl EditorView { _ => (&mut default_vec, r#default), }; + let scope = diagnostic + .tags + .first() + .and_then(|tag| match tag { + DiagnosticTag::Unnecessary => unnecessary, + DiagnosticTag::Deprecated => deprecated, + }) + .unwrap_or(scope); + // If any diagnostic overlaps ranges with the prior diagnostic, // merge the two together. Otherwise push a new span. match vec.last_mut() { diff --git a/theme.toml b/theme.toml index dd1a5d889..8a5bfd72d 100644 --- a/theme.toml +++ b/theme.toml @@ -80,6 +80,8 @@ label = "honey" "diagnostic.info" = { underline = { color = "delta", style = "curl" } } "diagnostic.warning" = { underline = { color = "lightning", style = "curl" } } "diagnostic.error" = { underline = { color = "apricot", style = "curl" } } +"diagnostic.unnecessary" = { modifiers = ["dim"] } +"diagnostic.deprecated" = { modifiers = ["crossed_out"] } warning = "lightning" error = "apricot" From f04dafa2e23e30771db92fdf6f39fcd1f0f5d0d6 Mon Sep 17 00:00:00 2001 From: Malpha Date: Sat, 2 Mar 2024 07:47:10 +0000 Subject: [PATCH 024/114] languages.toml: add elvish shebang (#9779) --- languages.toml | 1 + 1 file changed, 1 insertion(+) diff --git a/languages.toml b/languages.toml index a4b6a5cd8..7d859c2e4 100644 --- a/languages.toml +++ b/languages.toml @@ -2157,6 +2157,7 @@ grammar = "python" [[language]] name = "elvish" scope = "source.elvish" +shebangs = ["elvish"] file-types = ["elv"] comment-token = "#" indent = { tab-width = 2, unit = " " } From d769fadde085169c26a850966a6d5d8da7cc1c12 Mon Sep 17 00:00:00 2001 From: Michael Davis Date: Sat, 2 Mar 2024 02:47:24 -0500 Subject: [PATCH 025/114] Fix precedence of svelte typescript injection (#9777) --- runtime/queries/svelte/injections.scm | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/runtime/queries/svelte/injections.scm b/runtime/queries/svelte/injections.scm index 65a6e0e41..52d430c3f 100644 --- a/runtime/queries/svelte/injections.scm +++ b/runtime/queries/svelte/injections.scm @@ -19,13 +19,6 @@ (quoted_attribute_value (attribute_value) @css)) (#eq? @_attr "style")) -((script_element - (raw_text) @injection.content) - (#set! injection.language "javascript")) - -((raw_text_expr) @injection.content - (#set! injection.language "javascript")) - ( (script_element (start_tag @@ -36,5 +29,12 @@ (#set! injection.language "typescript") ) +((script_element + (raw_text) @injection.content) + (#set! injection.language "javascript")) + +((raw_text_expr) @injection.content + (#set! injection.language "javascript")) + ((comment) @injection.content (#set! injection.language "comment")) From 5bd007266a962a534bd722619821e998735b71e2 Mon Sep 17 00:00:00 2001 From: Mike Trinkala Date: Sat, 2 Mar 2024 06:05:58 -0800 Subject: [PATCH 026/114] Fix panic when using join_selections_space (#9783) Joining lines with Alt-J does not properly select the inserted spaces when the selection contains blank lines. In the worst case it panics with an out of bounds index. thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: Char index out of bounds: char index 11, Rope/RopeSlice char length 10' Steps to reproduce: * Create a new document ``` a b c d e ``` * % (Select all) * Alt-J (join and select the spaces) --- helix-term/src/commands.rs | 23 ++++++--- helix-term/tests/test/commands.rs | 83 +++++++++++++++++++++++++++++++ 2 files changed, 100 insertions(+), 6 deletions(-) diff --git a/helix-term/src/commands.rs b/helix-term/src/commands.rs index bd0a60b7c..0b2ea0b8a 100644 --- a/helix-term/src/commands.rs +++ b/helix-term/src/commands.rs @@ -4372,16 +4372,27 @@ fn join_selections_impl(cx: &mut Context, select_space: bool) { // select inserted spaces let transaction = if select_space { + let mut offset: usize = 0; let ranges: SmallVec<_> = changes .iter() - .scan(0, |offset, change| { - let range = Range::point(change.0 - *offset); - *offset += change.1 - change.0 - 1; // -1 because cursor is 0-sized - Some(range) + .filter_map(|change| { + if change.2.is_some() { + let range = Range::point(change.0 - offset); + offset += change.1 - change.0 - 1; // -1 adjusts for the replacement of the range by a space + Some(range) + } else { + offset += change.1 - change.0; + None + } }) .collect(); - let selection = Selection::new(ranges, 0); - Transaction::change(text, changes.into_iter()).with_selection(selection) + let t = Transaction::change(text, changes.into_iter()); + if ranges.is_empty() { + t + } else { + let selection = Selection::new(ranges, 0); + t.with_selection(selection) + } } else { Transaction::change(text, changes.into_iter()) }; diff --git a/helix-term/tests/test/commands.rs b/helix-term/tests/test/commands.rs index e52b142c6..1172a7981 100644 --- a/helix-term/tests/test/commands.rs +++ b/helix-term/tests/test/commands.rs @@ -526,3 +526,86 @@ async fn test_join_selections() -> anyhow::Result<()> { Ok(()) } + +#[tokio::test(flavor = "multi_thread")] +async fn test_join_selections_space() -> anyhow::Result<()> { + // join with empty lines panic + test(( + platform_line(indoc! {"\ + #[a + + b + + c + + d + + e|]# + "}), + "", + platform_line(indoc! {"\ + a#[ |]#b#( |)#c#( |)#d#( |)#e + "}), + )) + .await?; + + // normal join + test(( + platform_line(indoc! {"\ + #[a|]#bc + def + "}), + "", + platform_line(indoc! {"\ + abc#[ |]#def + "}), + )) + .await?; + + // join with empty line + test(( + platform_line(indoc! {"\ + #[a|]#bc + + def + "}), + "", + platform_line(indoc! {"\ + #[a|]#bc + def + "}), + )) + .await?; + + // join with additional space in non-empty line + test(( + platform_line(indoc! {"\ + #[a|]#bc + + def + "}), + "", + platform_line(indoc! {"\ + abc#[ |]#def + "}), + )) + .await?; + + // join with retained trailing spaces + test(( + platform_line(indoc! {"\ + #[aaa + + bb + + c |]# + "}), + "", + platform_line(indoc! {"\ + aaa #[ |]#bb #( |)#c + "}), + )) + .await?; + + Ok(()) +} From 9267343830228490d379c90537ff1a6e4bba1260 Mon Sep 17 00:00:00 2001 From: Mike Trinkala Date: Sun, 3 Mar 2024 09:55:09 -0800 Subject: [PATCH 027/114] Fix panic when using surround_replace/delete (#9796) 1. Create a document containing `{A}` 1. C-w v # vsplit 1. gl # goto_line_end 1. b # move_prev_word_start 1. ` # switch_to_lowercase 1. mrm( # surround replace 1. C-w v # vsplit In the debug build surround_replace/delete will immedately assert with `assertion failed: last <= from', transaction.rs:597:13`. The splits and lowercase conversion are not needed to trigger the bug. In the release build the surround becomes `)a(` and the last vsplit causes the transaction to panic. `internal error: entered unreachable code: (Some(Retain(18446744073709551573)))', transaction.rs:185:46` Since the selection direction is backwards get_surround_pos returns the pairs reversed but the downstream code assumes they are in the forward direction. --- helix-core/src/surround.rs | 3 +- helix-term/tests/test/movement.rs | 54 +++++++++++++++++++++++++++++++ 2 files changed, 56 insertions(+), 1 deletion(-) diff --git a/helix-core/src/surround.rs b/helix-core/src/surround.rs index b96cce5a0..513f87493 100644 --- a/helix-core/src/surround.rs +++ b/helix-core/src/surround.rs @@ -260,7 +260,8 @@ pub fn get_surround_pos( if change_pos.contains(&open_pos) || change_pos.contains(&close_pos) { return Err(Error::CursorOverlap); } - change_pos.extend_from_slice(&[open_pos, close_pos]); + // ensure the positions are always paired in the forward direction + change_pos.extend_from_slice(&[open_pos.min(close_pos), close_pos.max(open_pos)]); } Ok(change_pos) } diff --git a/helix-term/tests/test/movement.rs b/helix-term/tests/test/movement.rs index e3c2668da..0873edbe5 100644 --- a/helix-term/tests/test/movement.rs +++ b/helix-term/tests/test/movement.rs @@ -552,3 +552,57 @@ async fn find_char_line_ending() -> anyhow::Result<()> { Ok(()) } + +#[tokio::test(flavor = "multi_thread")] +async fn test_surround_replace() -> anyhow::Result<()> { + test(( + platform_line(indoc! {"\ + (#[|a]#) + "}), + "mrm{", + platform_line(indoc! {"\ + {#[|a]#} + "}), + )) + .await?; + + test(( + platform_line(indoc! {"\ + (#[a|]#) + "}), + "mrm{", + platform_line(indoc! {"\ + {#[a|]#} + "}), + )) + .await?; + + Ok(()) +} + +#[tokio::test(flavor = "multi_thread")] +async fn test_surround_delete() -> anyhow::Result<()> { + test(( + platform_line(indoc! {"\ + (#[|a]#) + "}), + "mdm", + platform_line(indoc! {"\ + #[|a]# + "}), + )) + .await?; + + test(( + platform_line(indoc! {"\ + (#[a|]#) + "}), + "mdm", + platform_line(indoc! {"\ + #[a|]# + "}), + )) + .await?; + + Ok(()) +} From cc43e3521ed94e9d6e77c719c14073d3e7217c97 Mon Sep 17 00:00:00 2001 From: RoloEdits Date: Sun, 3 Mar 2024 09:56:18 -0800 Subject: [PATCH 028/114] feat(languages): add support for `*.Dockerfile` `file-types` naming convention (#9772) Current `file-types` only supports up to a `Dockerfile.frontend` naming scheme. With these changes `frontend.Dockerfile` now gives proper highlights and lsp actions. --- languages.toml | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/languages.toml b/languages.toml index 7d859c2e4..49672a30b 100644 --- a/languages.toml +++ b/languages.toml @@ -1494,7 +1494,20 @@ name = "dockerfile" scope = "source.dockerfile" injection-regex = "docker|dockerfile" roots = ["Dockerfile", "Containerfile"] -file-types = [{ glob = "Dockerfile*" }, { glob = "dockerfile*" }, { glob = "Containerfile*" }, { glob = "containerfile*" }] +file-types = [ + "Dockerfile", + { glob = "Dockerfile" }, + { glob = "Dockerfile.*" }, + "dockerfile", + { glob = "dockerfile" }, + { glob = "dockerfile.*" }, + "Containerfile", + { glob = "Containerfile" }, + { glob = "Containerfile.*" }, + "containerfile", + { glob = "containerfile" }, + { glob = "containerfile.*" }, +] comment-token = "#" indent = { tab-width = 2, unit = " " } language-servers = [ "docker-langserver" ] From 3f98891e7952a748f814e6741f4375c9b7aa0983 Mon Sep 17 00:00:00 2001 From: varris1 <38386180+varris1@users.noreply.github.com> Date: Tue, 5 Mar 2024 16:00:34 +0100 Subject: [PATCH 029/114] flake.lock: Bump flake inputs to prevent a warning message (#9816) --- flake.lock | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/flake.lock b/flake.lock index 9bb5dece1..48fb4a59f 100644 --- a/flake.lock +++ b/flake.lock @@ -7,11 +7,11 @@ ] }, "locked": { - "lastModified": 1701025348, - "narHash": "sha256-42GHmYH+GF7VjwGSt+fVT1CQuNpGanJbNgVHTAZppUM=", + "lastModified": 1709610799, + "narHash": "sha256-5jfLQx0U9hXbi2skYMGodDJkIgffrjIOgMRjZqms2QE=", "owner": "ipetkov", "repo": "crane", - "rev": "42afaeb1a0325194a7cdb526332d2cb92fddd07b", + "rev": "81c393c776d5379c030607866afef6406ca1be57", "type": "github" }, "original": { @@ -25,11 +25,11 @@ "systems": "systems" }, "locked": { - "lastModified": 1694529238, - "narHash": "sha256-zsNZZGTGnMOf9YpHKJqMSsa0dXbfmxeoJ7xHlrt+xmY=", + "lastModified": 1709126324, + "narHash": "sha256-q6EQdSeUZOG26WelxqkmR7kArjgWCdw5sfJVHPH/7j8=", "owner": "numtide", "repo": "flake-utils", - "rev": "ff7b65b44d01cf9ba6a71320833626af21126384", + "rev": "d465f4819400de7c8d874d50b982301f28a84605", "type": "github" }, "original": { @@ -40,11 +40,11 @@ }, "nixpkgs": { "locked": { - "lastModified": 1700794826, - "narHash": "sha256-RyJTnTNKhO0yqRpDISk03I/4A67/dp96YRxc86YOPgU=", + "lastModified": 1709479366, + "narHash": "sha256-n6F0n8UV6lnTZbYPl1A9q1BS0p4hduAv1mGAP17CVd0=", "owner": "nixos", "repo": "nixpkgs", - "rev": "5a09cb4b393d58f9ed0d9ca1555016a8543c2ac8", + "rev": "b8697e57f10292a6165a20f03d2f42920dfaf973", "type": "github" }, "original": { @@ -72,11 +72,11 @@ ] }, "locked": { - "lastModified": 1701137803, - "narHash": "sha256-0LcPAdql5IhQSUXJx3Zna0dYTgdIoYO7zUrsKgiBd04=", + "lastModified": 1709604635, + "narHash": "sha256-le4fwmWmjGRYWwkho0Gr7mnnZndOOe4XGbLw68OvF40=", "owner": "oxalica", "repo": "rust-overlay", - "rev": "9dd940c967502f844eacea52a61e9596268d4f70", + "rev": "e86c0fb5d3a22a5f30d7f64ecad88643fe26449d", "type": "github" }, "original": { From 7d8c86e4039551ebe754d9e3753b9b99e6fa6419 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 6 Mar 2024 11:08:07 +0900 Subject: [PATCH 030/114] build(deps): bump arc-swap from 1.6.0 to 1.7.0 (#9809) --- Cargo.lock | 4 ++-- helix-term/Cargo.toml | 2 +- helix-vcs/Cargo.toml | 2 +- helix-view/Cargo.toml | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 08fa4789e..43213764d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -68,9 +68,9 @@ checksum = "5ad32ce52e4161730f7098c077cd2ed6229b5804ccf99e5366be1ab72a98b4e1" [[package]] name = "arc-swap" -version = "1.6.0" +version = "1.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bddcadddf5e9015d310179a59bb28c4d4b9920ad0f11e8e14dbadf654890c9a6" +checksum = "7b3d0060af21e8d11a926981cc00c6c1541aa91dd64b9f881985c3da1094425f" [[package]] name = "autocfg" diff --git a/helix-term/Cargo.toml b/helix-term/Cargo.toml index 8c6ae9f42..accde567e 100644 --- a/helix-term/Cargo.toml +++ b/helix-term/Cargo.toml @@ -41,7 +41,7 @@ crossterm = { version = "0.27", features = ["event-stream"] } signal-hook = "0.3" tokio-stream = "0.1" futures-util = { version = "0.3", features = ["std", "async-await"], default-features = false } -arc-swap = { version = "1.6.0" } +arc-swap = { version = "1.7.0" } termini = "1" # Logging diff --git a/helix-vcs/Cargo.toml b/helix-vcs/Cargo.toml index 32aca4f09..874b92d03 100644 --- a/helix-vcs/Cargo.toml +++ b/helix-vcs/Cargo.toml @@ -17,7 +17,7 @@ helix-event = { path = "../helix-event" } tokio = { version = "1", features = ["rt", "rt-multi-thread", "time", "sync", "parking_lot", "macros"] } parking_lot = "0.12" -arc-swap = { version = "1.6.0" } +arc-swap = { version = "1.7.0" } gix = { version = "0.58.0", features = ["attributes"], default-features = false, optional = true } imara-diff = "0.1.5" diff --git a/helix-view/Cargo.toml b/helix-view/Cargo.toml index b1b444f90..fc209b00f 100644 --- a/helix-view/Cargo.toml +++ b/helix-view/Cargo.toml @@ -31,7 +31,7 @@ crossterm = { version = "0.27", optional = true } once_cell = "1.19" url = "2.5.0" -arc-swap = { version = "1.6.0" } +arc-swap = { version = "1.7.0" } tokio = { version = "1", features = ["rt", "rt-multi-thread", "io-util", "io-std", "time", "process", "macros", "fs", "parking_lot"] } tokio-stream = "0.1" From ea0b2446441fd09b304e92581f644901018846d7 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 6 Mar 2024 11:08:40 +0900 Subject: [PATCH 031/114] build(deps): bump libloading from 0.8.1 to 0.8.2 (#9810) --- Cargo.lock | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 43213764d..fd498d9ad 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1603,12 +1603,12 @@ checksum = "9c198f91728a82281a64e1f4f9eeb25d82cb32a5de251c6bd1b5154d63a8e7bd" [[package]] name = "libloading" -version = "0.8.1" +version = "0.8.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c571b676ddfc9a8c12f1f3d3085a7b163966a8fd8098a90640953ce5f6170161" +checksum = "2caa5afb8bf9f3a2652760ce7d4f62d21c4d5a423e68466fca30df82f2330164" dependencies = [ "cfg-if", - "windows-sys 0.48.0", + "windows-targets 0.52.0", ] [[package]] From 7a473c74945bb7fd28abf9f23f9dfdd5562c7cd6 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 6 Mar 2024 11:09:13 +0900 Subject: [PATCH 032/114] build(deps): bump ahash from 0.8.9 to 0.8.11 (#9813) --- Cargo.lock | 4 ++-- helix-core/Cargo.toml | 2 +- helix-event/Cargo.toml | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index fd498d9ad..a330e5872 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -19,9 +19,9 @@ checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" [[package]] name = "ahash" -version = "0.8.9" +version = "0.8.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d713b3834d76b85304d4d525563c1276e2e30dc97cc67bfb4585a4a29fc2c89f" +checksum = "e89da841a80418a9b391ebaea17f5c112ffaaa96f621d2c285b5174da76b9011" dependencies = [ "cfg-if", "getrandom", diff --git a/helix-core/Cargo.toml b/helix-core/Cargo.toml index be5ea5eb8..5e2dbd977 100644 --- a/helix-core/Cargo.toml +++ b/helix-core/Cargo.toml @@ -32,7 +32,7 @@ once_cell = "1.19" arc-swap = "1" regex = "1" bitflags = "2.4" -ahash = "0.8.9" +ahash = "0.8.11" hashbrown = { version = "0.14.3", features = ["raw"] } dunce = "1.0" diff --git a/helix-event/Cargo.toml b/helix-event/Cargo.toml index 8711568e8..616c323dc 100644 --- a/helix-event/Cargo.toml +++ b/helix-event/Cargo.toml @@ -12,7 +12,7 @@ homepage.workspace = true # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -ahash = "0.8.9" +ahash = "0.8.11" hashbrown = "0.14.0" tokio = { version = "1", features = ["rt", "rt-multi-thread", "time", "sync", "parking_lot", "macros"] } # the event registry is essentially read only but must be an rwlock so we can From 4e5f19df53cbe1f1b1e9ea590415c5bd58642b6b Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 6 Mar 2024 11:10:24 +0900 Subject: [PATCH 033/114] build(deps): bump clipboard-win from 5.1.0 to 5.2.0 (#9811) --- Cargo.lock | 4 ++-- helix-view/Cargo.toml | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index a330e5872..aa3700b93 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -180,9 +180,9 @@ dependencies = [ [[package]] name = "clipboard-win" -version = "5.1.0" +version = "5.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3ec832972fefb8cf9313b45a0d1945e29c9c251f1d4c6eafc5fe2124c02d2e81" +checksum = "12f9a0700e0127ba15d1d52dd742097f821cd9c65939303a44d970465040a297" dependencies = [ "error-code", ] diff --git a/helix-view/Cargo.toml b/helix-view/Cargo.toml index fc209b00f..335779bc2 100644 --- a/helix-view/Cargo.toml +++ b/helix-view/Cargo.toml @@ -50,7 +50,7 @@ parking_lot = "0.12.1" [target.'cfg(windows)'.dependencies] -clipboard-win = { version = "5.1", features = ["std"] } +clipboard-win = { version = "5.2", features = ["std"] } [target.'cfg(unix)'.dependencies] libc = "0.2" From b93fae9c8b955e11f427979134e3494294e8e2e0 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 6 Mar 2024 11:10:59 +0900 Subject: [PATCH 034/114] build(deps): bump mio from 0.8.9 to 0.8.11 (#9808) --- Cargo.lock | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index aa3700b93..fd74140a5 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1690,9 +1690,9 @@ dependencies = [ [[package]] name = "mio" -version = "0.8.9" +version = "0.8.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3dce281c5e46beae905d4de1870d8b1509a9142b62eedf18b443b011ca8343d0" +checksum = "a4a650543ca06a924e8b371db273b2756685faae30f8487da1b56505a8f78b0c" dependencies = [ "libc", "log", From cb01e52cd8b8021686ee98dd4d53dff8cdc826a9 Mon Sep 17 00:00:00 2001 From: Mike Trinkala Date: Thu, 7 Mar 2024 09:20:07 -0800 Subject: [PATCH 035/114] Fix panic in surround_replace/delete nested multi-cursor (#9815) Test Document ------------- ``` {{ } } ``` Steps To Reproduce ------------------ 1. 2j # move_visual_line_down 1. C # copy_selection_on_next_line 1. mdm # surround_delete Debug ----- `assertion failed: last <= from', transaction.rs:597:13` Release ------- `called `Result::unwrap()` on an `Err` value: Char range out of bounds: char range 18446744073709551614..18446744073709551615, Rope/RopeSlice char length 7', ropey-1.6.1/src/rope.rs:546:37` Description ----------- Processing the surrounding pairs in order violates the assertion the ranges are ordered. To handle nested surrounds all positions have to be sorted. Also surround_replace has to track the proper replacement character for each position. --- helix-term/src/commands.rs | 19 ++++++++++++++----- helix-term/tests/test/movement.rs | 29 +++++++++++++++++++++++++++++ 2 files changed, 43 insertions(+), 5 deletions(-) diff --git a/helix-term/src/commands.rs b/helix-term/src/commands.rs index 0b2ea0b8a..4ac2496eb 100644 --- a/helix-term/src/commands.rs +++ b/helix-term/src/commands.rs @@ -5282,12 +5282,21 @@ fn surround_replace(cx: &mut Context) { None => return doc.set_selection(view.id, selection), }; let (open, close) = surround::get_pair(to); + + // the changeset has to be sorted to allow nested surrounds + let mut sorted_pos: Vec<(usize, char)> = Vec::new(); + for p in change_pos.chunks(2) { + sorted_pos.push((p[0], open)); + sorted_pos.push((p[1], close)); + } + sorted_pos.sort_unstable(); + let transaction = Transaction::change( doc.text(), - change_pos.iter().enumerate().map(|(i, &pos)| { + sorted_pos.iter().map(|&pos| { let mut t = Tendril::new(); - t.push(if i % 2 == 0 { open } else { close }); - (pos, pos + 1, Some(t)) + t.push(pos.1); + (pos.0, pos.0 + 1, Some(t)) }), ); doc.set_selection(view.id, selection); @@ -5309,14 +5318,14 @@ fn surround_delete(cx: &mut Context) { let text = doc.text().slice(..); let selection = doc.selection(view.id); - let change_pos = match surround::get_surround_pos(text, selection, surround_ch, count) { + let mut change_pos = match surround::get_surround_pos(text, selection, surround_ch, count) { Ok(c) => c, Err(err) => { cx.editor.set_error(err.to_string()); return; } }; - + change_pos.sort_unstable(); // the changeset has to be sorted to allow nested surrounds let transaction = Transaction::change(doc.text(), change_pos.into_iter().map(|p| (p, p + 1, None))); doc.apply(&transaction, view.id); diff --git a/helix-term/tests/test/movement.rs b/helix-term/tests/test/movement.rs index 0873edbe5..4ebaae854 100644 --- a/helix-term/tests/test/movement.rs +++ b/helix-term/tests/test/movement.rs @@ -577,6 +577,23 @@ async fn test_surround_replace() -> anyhow::Result<()> { )) .await?; + test(( + platform_line(indoc! {"\ + {{ + + #(}|)# + #[}|]# + "}), + "mrm)", + platform_line(indoc! {"\ + (( + + #()|)# + #[)|]# + "}), + )) + .await?; + Ok(()) } @@ -604,5 +621,17 @@ async fn test_surround_delete() -> anyhow::Result<()> { )) .await?; + test(( + platform_line(indoc! {"\ + {{ + + #(}|)# + #[}|]# + "}), + "mdm", + platform_line("\n\n#(\n|)##[\n|]#"), + )) + .await?; + Ok(()) } From e27b04735c630140b45ac9fab1b3087ae831f34a Mon Sep 17 00:00:00 2001 From: Mike Trinkala Date: Thu, 7 Mar 2024 11:37:01 -0800 Subject: [PATCH 036/114] Fix panic in select_textobject_around (#9832) Test Document ------------- ``` a)b ``` Steps to Reproduce ------------------ 1. % # select_all 1. ms( # surround_add 1. mam # select_textobject_around Debug and Release ----------------- `thread 'main' panicked at 'Attempt to index past end of RopeSlice: char index 7, RopeSlice char length 6', ropey-1.6.1/src/slice.rs:796:13` Description ----------- An index was selected beyond the end of the slice with chars_at. The fix adds a guard check to `find_nth_open_pair`, like in the other find_nth* functions. --- helix-core/src/surround.rs | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/helix-core/src/surround.rs b/helix-core/src/surround.rs index 513f87493..ed9764883 100644 --- a/helix-core/src/surround.rs +++ b/helix-core/src/surround.rs @@ -167,6 +167,10 @@ fn find_nth_open_pair( mut pos: usize, n: usize, ) -> Option { + if pos >= text.len_chars() { + return None; + } + let mut chars = text.chars_at(pos + 1); // Adjusts pos for the first iteration, and handles the case of the @@ -383,6 +387,21 @@ mod test { ) } + #[test] + fn test_find_nth_closest_pairs_pos_index_range_panic() { + #[rustfmt::skip] + let (doc, selection, _) = + rope_with_selections_and_expectations( + "(a)c)", + "^^^^^" + ); + + assert_eq!( + find_nth_closest_pairs_pos(doc.slice(..), selection.primary(), 1), + Err(Error::PairNotFound) + ) + } + // Create a Rope and a matching Selection using a specification language. // ^ is a single-point selection. // _ is an expected index. These are returned as a Vec for use in assertions. From 301dfb07ccf3df41c381300dddb760bf76745cf5 Mon Sep 17 00:00:00 2001 From: Chris Date: Thu, 7 Mar 2024 22:39:00 +0000 Subject: [PATCH 037/114] Add PowerShell highlighting (#9827) --- book/src/generated/lang-support.md | 1 + languages.toml | 14 ++ runtime/queries/powershell/highlights.scm | 174 ++++++++++++++++++++++ runtime/queries/powershell/injections.scm | 2 + 4 files changed, 191 insertions(+) create mode 100644 runtime/queries/powershell/highlights.scm create mode 100644 runtime/queries/powershell/injections.scm diff --git a/book/src/generated/lang-support.md b/book/src/generated/lang-support.md index c9668549e..9149acadf 100644 --- a/book/src/generated/lang-support.md +++ b/book/src/generated/lang-support.md @@ -132,6 +132,7 @@ | po | ✓ | ✓ | | | | pod | ✓ | | | | | ponylang | ✓ | ✓ | ✓ | | +| powershell | ✓ | | | | | prisma | ✓ | | | `prisma-language-server` | | prolog | | | | `swipl` | | protobuf | ✓ | ✓ | ✓ | `bufls`, `pb` | diff --git a/languages.toml b/languages.toml index 49672a30b..70953b990 100644 --- a/languages.toml +++ b/languages.toml @@ -3259,3 +3259,17 @@ indent = { tab-width = 4, unit = " " } [[grammar]] name = "fidl" source = { git = "https://github.com/google/tree-sitter-fidl", rev = "bdbb635a7f5035e424f6173f2f11b9cd79703f8d" } + +[[language]] +name = "powershell" +scope = "source.powershell" +injection-regex = "(pwsh|powershell)" +file-types = [ "ps1", "psm1", "psd1", "pscc", "psrc" ] +shebangs = [ "pwsh", "powershell" ] +comment-token = '#' +block-comment-tokens = { start = "<#", end = "#>" } +indent = { tab-width = 4, unit = " " } + +[[grammar]] +name = "powershell" +source = { git = "https://github.com/airbus-cert/tree-sitter-powershell", rev = "c9316be0faca5d5b9fd3b57350de650755f42dc0" } diff --git a/runtime/queries/powershell/highlights.scm b/runtime/queries/powershell/highlights.scm new file mode 100644 index 000000000..c62c72814 --- /dev/null +++ b/runtime/queries/powershell/highlights.scm @@ -0,0 +1,174 @@ +[ + "if" + "elseif" + "else" + "switch" +] @keyword.control.conditional + +[ + "foreach" + "for" + "while" + "do" + "until" +] @keyword.control.repeat + +[ + "break" + "continue" + "return" +] @keyword.control.return + +"in" @keyword.operator + +"function" @keyword.function + +[ + "class" + "enum" +] @keyword.storage.type + +[ + "param" + "dynamicparam" + "begin" + "process" + "end" + "filter" + "workflow" + "throw" + "exit" + "trap" + "try" + "catch" + "finally" + "data" + "inlinescript" + "parallel" + "sequence" +] @keyword + +[ + "-as" + "-ccontains" + "-ceq" + "-cge" + "-cgt" + "-cle" + "-clike" + "-clt" + "-cmatch" + "-cne" + "-cnotcontains" + "-cnotlike" + "-cnotmatch" + "-contains" + "-creplace" + "-csplit" + "-eq" + "-ge" + "-gt" + "-icontains" + "-ieq" + "-ige" + "-igt" + "-ile" + "-ilike" + "-ilt" + "-imatch" + "-in" + "-ine" + "-inotcontains" + "-inotlike" + "-inotmatch" + "-ireplace" + "-is" + "-isnot" + "-isplit" + "-join" + "-le" + "-like" + "-lt" + "-match" + "-ne" + "-not" + "-notcontains" + "-notin" + "-notlike" + "-notmatch" + "-replace" + "-shl" + "-shr" + "-split" + "-and" + "-or" + "-xor" + "-band" + "-bor" + "-bxor" + "+" + "-" + "*" + "/" + "%" + "++" + "--" + "!" + "\\" + ".." + "|" +] @operator + +(assignement_operator) @operator + +[ + "(" + ")" + "{" + "}" + "[" + "]" +] @punctuation.bracket + +[ + ";" + "," + "::" +] @punctuation.delimiter + +(string_literal) @string + +(integer_literal) @constant.numeric +(real_literal) @constant.numeric + +(command + command_name: (command_name) @function) + +(function_name) @function + +(invokation_expression + (member_name) @function) + +(member_access + (member_name) @variable.other.member) + +(command_invokation_operator) @operator + +(type_spec) @type + +(variable) @variable + +(comment) @comment + +(array_expression) @punctuation.bracket + +(assignment_expression + value: (pipeline) @variable) + +(format_operator) @operator + +(command_parameter) @variable.parameter + +(command_elements) @variable.builtin + +(generic_token) @variable diff --git a/runtime/queries/powershell/injections.scm b/runtime/queries/powershell/injections.scm new file mode 100644 index 000000000..321c90add --- /dev/null +++ b/runtime/queries/powershell/injections.scm @@ -0,0 +1,2 @@ +((comment) @injection.content + (#set! injection.language "comment")) From fd89c3c8335399e344e038f1141ea0657653a591 Mon Sep 17 00:00:00 2001 From: Alexander Brevig Date: Fri, 8 Mar 2024 02:54:17 +0100 Subject: [PATCH 038/114] fix: close #9771 fix comments with `(` and `)` (#9800) * fix: close #9771 update OCaml * fix: no longer match on ( ) as the underlying grammar handles these * fix: implement excellent corrections from review * fix: module -> namespace to match theme scopes --- languages.toml | 4 +- runtime/queries/comment/highlights.scm | 5 - runtime/queries/ocaml/highlights.scm | 141 ++++++++++++------------- 3 files changed, 67 insertions(+), 83 deletions(-) diff --git a/languages.toml b/languages.toml index 70953b990..e96f06183 100644 --- a/languages.toml +++ b/languages.toml @@ -1095,7 +1095,7 @@ indent = { tab-width = 2, unit = " " } [[grammar]] name = "ocaml" -source = { git = "https://github.com/tree-sitter/tree-sitter-ocaml", rev = "23d419ba45789c5a47d31448061557716b02750a", subpath = "ocaml" } +source = { git = "https://github.com/tree-sitter/tree-sitter-ocaml", rev = "9965d208337d88bbf1a38ad0b0fe49e5f5ec9677", subpath = "ocaml" } [[language]] name = "ocaml-interface" @@ -1115,7 +1115,7 @@ indent = { tab-width = 2, unit = " " } [[grammar]] name = "ocaml-interface" -source = { git = "https://github.com/tree-sitter/tree-sitter-ocaml", rev = "23d419ba45789c5a47d31448061557716b02750a", subpath = "interface" } +source = { git = "https://github.com/tree-sitter/tree-sitter-ocaml", rev = "9965d208337d88bbf1a38ad0b0fe49e5f5ec9677", subpath = "interface" } [[language]] name = "lua" diff --git a/runtime/queries/comment/highlights.scm b/runtime/queries/comment/highlights.scm index 4cefcdf74..ba26ca0bf 100644 --- a/runtime/queries/comment/highlights.scm +++ b/runtime/queries/comment/highlights.scm @@ -1,8 +1,3 @@ -[ - "(" - ")" -] @punctuation.bracket - ":" @punctuation.delimiter ; Hint level tags diff --git a/runtime/queries/ocaml/highlights.scm b/runtime/queries/ocaml/highlights.scm index 9d3bf4c8b..f2a4f0a4c 100644 --- a/runtime/queries/ocaml/highlights.scm +++ b/runtime/queries/ocaml/highlights.scm @@ -6,9 +6,12 @@ ; Types ;------ -[(class_name) (class_type_name) (type_constructor)] @type +( + (type_constructor) @type.builtin + (#match? @type.builtin "^(int|char|bytes|string|float|bool|unit|exn|array|list|option|int32|int64|nativeint|format6|lazy_t)$") +) -(type_variable) @type.parameter +[(class_name) (class_type_name) (type_constructor)] @type [(constructor_name) (tag)] @constructor @@ -29,27 +32,34 @@ (method_name) @function.method -; Variables -;---------- - -(value_pattern) @variable.parameter - ; Application ;------------ +( + (value_name) @function.builtin + (#match? @function.builtin "^(raise(_notrace)?|failwith|invalid_arg)$") +) + (infix_expression left: (value_path (value_name) @function) - (infix_operator) @operator + operator: (concat_operator) @operator (#eq? @operator "@@")) (infix_expression - (infix_operator) @operator + operator: (rel_operator) @operator right: (value_path (value_name) @function) (#eq? @operator "|>")) (application_expression function: (value_path (value_name) @function)) +; Variables +;---------- + +[(value_name) (type_variable)] @variable + +(value_pattern) @variable.parameter + ; Properties ;----------- @@ -58,55 +68,68 @@ ; Constants ;---------- -[(boolean) (unit)] @constant - -[(number) (signed_number)] @constant.numeric.integer +(boolean) @constant.builtin.boolean -(character) @constant.character +[(number) (signed_number)] @constant.numeric -(string) @string +[(string) (character)] @string (quoted_string "{" @string "}" @string) @string (escape_sequence) @constant.character.escape +(conversion_specification) @string.special + +; Operators +;---------- + +(match_expression (match_operator) @keyword) + +(value_definition [(let_operator) (let_and_operator)] @keyword) + [ - (conversion_specification) - (pretty_printing_indication) -] @punctuation.special + (prefix_operator) + (sign_operator) + (pow_operator) + (mult_operator) + (add_operator) + (concat_operator) + (rel_operator) + (and_operator) + (or_operator) + (assign_operator) + (hash_operator) + (indexing_operator) + (let_operator) + (let_and_operator) + (match_operator) +] @operator + +["*" "#" "::" "<-"] @operator ; Keywords ;--------- [ - "and" "as" "assert" "begin" "class" "constraint" - "end" "external" "in" - "inherit" "initializer" "lazy" "let" "match" "method" "module" - "mutable" "new" "nonrec" "object" "of" "private" "rec" "sig" "struct" - "type" "val" "virtual" "when" "with" + "and" "as" "assert" "begin" "class" "constraint" "do" "done" "downto" "else" + "end" "exception" "external" "for" "fun" "function" "functor" "if" "in" + "include" "inherit" "initializer" "lazy" "let" "match" "method" "module" + "mutable" "new" "nonrec" "object" "of" "open" "private" "rec" "sig" "struct" + "then" "to" "try" "type" "val" "virtual" "when" "while" "with" ] @keyword -["fun" "function" "functor"] @keyword.function - -["if" "then" "else"] @keyword.control.conditional - -["exception" "try"] @keyword.control.exception - -["include" "open"] @keyword.control.import - -["for" "to" "downto" "while" "do" "done"] @keyword.control.repeat +; Punctuation +;------------ -; Macros -;------- +(attribute ["[@" "]"] @punctuation.special) +(item_attribute ["[@@" "]"] @punctuation.special) +(floating_attribute ["[@@@" "]"] @punctuation.special) +(extension ["[%" "]"] @punctuation.special) +(item_extension ["[%%" "]"] @punctuation.special) +(quoted_extension ["{%" "}"] @punctuation.special) +(quoted_item_extension ["{%%" "}"] @punctuation.special) -(attribute ["[@" "]"] @attribute) -(item_attribute ["[@@" "]"] @attribute) -(floating_attribute ["[@@@" "]"] @attribute) -(extension ["[%" "]"] @function.macro) -(item_extension ["[%%" "]"] @function.macro) -(quoted_extension ["{%" "}"] @function.macro) -(quoted_item_extension ["{%%" "}"] @function.macro) -"%" @function.macro +"%" @punctuation.special ["(" ")" "[" "]" "{" "}" "[|" "|]" "[<" "[>"] @punctuation.bracket @@ -117,46 +140,12 @@ "->" ";;" ":>" "+=" ":=" ".." ] @punctuation.delimiter -; Operators -;---------- - -[ - (prefix_operator) - (sign_operator) - (infix_operator) - (hash_operator) - (indexing_operator) - (let_operator) - (and_operator) - (match_operator) -] @operator - -(match_expression (match_operator) @keyword) - -(value_definition [(let_operator) (and_operator)] @keyword) - -;; TODO: this is an error now -;(prefix_operator "!" @operator) - -(infix_operator ["&" "+" "-" "=" ">" "|" "%"] @operator) - -(signed_number ["+" "-"] @operator) - -["*" "#" "::" "<-"] @operator - ; Attributes ;----------- -(attribute_id) @variable.other.member +(attribute_id) @tag ; Comments ;--------- [(comment) (line_number_directive) (directive) (shebang)] @comment - -(ERROR) @error - -; Blanket highlights -; ------------------ - -[(value_name) (type_variable)] @variable From e3c6c82828299f1728f16a8d8fcfa5c3603a3d47 Mon Sep 17 00:00:00 2001 From: Matthew Toohey Date: Sat, 9 Mar 2024 02:59:56 -0500 Subject: [PATCH 039/114] add linker script language (#9835) --- book/src/generated/lang-support.md | 1 + languages.toml | 12 ++ runtime/queries/ld/highlights.scm | 173 +++++++++++++++++++++++++++++ runtime/queries/ld/indents.scm | 12 ++ runtime/queries/ld/injections.scm | 2 + 5 files changed, 200 insertions(+) create mode 100644 runtime/queries/ld/highlights.scm create mode 100644 runtime/queries/ld/indents.scm create mode 100644 runtime/queries/ld/injections.scm diff --git a/book/src/generated/lang-support.md b/book/src/generated/lang-support.md index 9149acadf..7792bf594 100644 --- a/book/src/generated/lang-support.md +++ b/book/src/generated/lang-support.md @@ -94,6 +94,7 @@ | kdl | ✓ | ✓ | ✓ | | | kotlin | ✓ | | | `kotlin-language-server` | | latex | ✓ | ✓ | | `texlab` | +| ld | ✓ | | ✓ | | | lean | ✓ | | | `lean` | | ledger | ✓ | | | | | llvm | ✓ | ✓ | ✓ | | diff --git a/languages.toml b/languages.toml index e96f06183..2e9f5d195 100644 --- a/languages.toml +++ b/languages.toml @@ -3273,3 +3273,15 @@ indent = { tab-width = 4, unit = " " } [[grammar]] name = "powershell" source = { git = "https://github.com/airbus-cert/tree-sitter-powershell", rev = "c9316be0faca5d5b9fd3b57350de650755f42dc0" } + +[[language]] +name = "ld" +scope = "source.ld" +injection-regex = "ld" +file-types = ["ld"] +block-comment-tokens = { start = "/*", end = "*/" } +indent = { tab-width = 2, unit = " " } + +[[grammar]] +name = "ld" +source = { git = "https://github.com/mtoohey31/tree-sitter-ld", rev = "81978cde3844bfc199851e39c80a20ec6444d35e" } diff --git a/runtime/queries/ld/highlights.scm b/runtime/queries/ld/highlights.scm new file mode 100644 index 000000000..4f935e753 --- /dev/null +++ b/runtime/queries/ld/highlights.scm @@ -0,0 +1,173 @@ +; Identifiers + +(section + . + (NAME) @namespace) + +(NAME) @variable + +; Operators + +[ + "=" + "+=" + "-=" + "*=" + "/=" + "<<=" + ">>=" + "&=" + "|=" + "^=" + "*" + "/" + "%" + "+" + "-" + "<<" + ">>" + "==" + "!=" + "<=" + ">=" + "<" + ">" + "&" + "^" + "|" + "&&" + "||" + "?" +] @operator + +; Keywords + +[ + "ABSOLUTE" + "ADDR" + "ALIGNOF" + "ASSERT" + "BYTE" + "CONSTANT" + "DATA_SEGMENT_ALIGN" + "DATA_SEGMENT_END" + "DATA_SEGMENT_RELRO_END" + "DEFINED" + "LOADADDR" + "LOG2CEIL" + "LONG" + "MAX" + "MIN" + "NEXT" + "QUAD" + "SHORT" + "SIZEOF" + "SQUAD" + "FILL" + "SEGMENT_START" +] @function.builtin + +[ + "CONSTRUCTORS" + "CREATE_OBJECT_SYMBOLS" + "LINKER_VERSION" + "SIZEOF_HEADERS" +] @constant.builtin + +[ + "AFTER" + "ALIGN" + "ALIGN_WITH_INPUT" + "ASCIZ" + "AS_NEEDED" + "AT" + "BEFORE" + "BIND" + "BLOCK" + "COPY" + "DSECT" + "ENTRY" + "EXCLUDE_FILE" + "EXTERN" + "extern" + "FLOAT" + "FORCE_COMMON_ALLOCATION" + "FORCE_GROUP_ALLOCATION" + "global" + "GROUP" + "HIDDEN" + "HLL" + "INCLUDE" + "INFO" + "INHIBIT_COMMON_ALLOCATION" + "INPUT" + "INPUT_SECTION_FLAGS" + "KEEP" + "l" + "LD_FEATURE" + "len" + "LENGTH" + "local" + "MAP" + "MEMORY" + "NOCROSSREFS" + "NOCROSSREFS_TO" + "NOFLOAT" + "NOLOAD" + "o" + "ONLY_IF_RO" + "ONLY_IF_RW" + "org" + "ORIGIN" + "OUTPUT" + "OUTPUT_ARCH" + "OUTPUT_FORMAT" + "OVERLAY" + "PHDRS" + "PROVIDE" + "PROVIDE_HIDDEN" + "READONLY" + "REGION_ALIAS" + "REVERSE" + "SEARCH_DIR" + "SECTIONS" + "SORT" + "SORT_BY_ALIGNMENT" + "SORT_BY_INIT_PRIORITY" + "SORT_BY_NAME" + "SORT_NONE" + "SPECIAL" + "STARTUP" + "SUBALIGN" + "SYSLIB" + "TARGET" + "TYPE" + "VERSION" +] @keyword + +; Delimiters + +[ + "," + ";" + "&" + ":" + ">" +] @punctuation.delimiter + +[ + "(" + ")" + "[" + "]" + "{" + "}" +] @punctuation.bracket + +; Literals + +(INT) @constant.numeric.integer + +; Comment + +(comment) @comment diff --git a/runtime/queries/ld/indents.scm b/runtime/queries/ld/indents.scm new file mode 100644 index 000000000..2e2928b5d --- /dev/null +++ b/runtime/queries/ld/indents.scm @@ -0,0 +1,12 @@ +[ + (sections) + (memory) + (section) + (phdrs) + (overlay_section) + (version) + (vers_node) + (vers_defns) +] @indent + +"}" @outdent @extend.prevent-once diff --git a/runtime/queries/ld/injections.scm b/runtime/queries/ld/injections.scm new file mode 100644 index 000000000..2f0e58eb6 --- /dev/null +++ b/runtime/queries/ld/injections.scm @@ -0,0 +1,2 @@ +((comment) @injection.content + (#set! injection.language "comment")) From 0dc67ff8852ce99d40ad4464062ebe212b0b03a1 Mon Sep 17 00:00:00 2001 From: "Markus F.X.J. Oberhumer" Date: Sat, 9 Mar 2024 09:02:43 +0100 Subject: [PATCH 040/114] helix-term: allow to backspace out-of the command prompt (#9828) --- helix-term/src/ui/prompt.rs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/helix-term/src/ui/prompt.rs b/helix-term/src/ui/prompt.rs index a6ee7f05d..d46c13138 100644 --- a/helix-term/src/ui/prompt.rs +++ b/helix-term/src/ui/prompt.rs @@ -544,6 +544,10 @@ impl Component for Prompt { (self.callback_fn)(cx, &self.line, PromptEvent::Update); } ctrl!('h') | key!(Backspace) | shift!(Backspace) => { + if self.line.is_empty() { + (self.callback_fn)(cx, &self.line, PromptEvent::Abort); + return close_fn; + } self.delete_char_backwards(cx.editor); (self.callback_fn)(cx, &self.line, PromptEvent::Update); } From 3bd493299fe632a7ff09fbd4c92c702ba3d0853f Mon Sep 17 00:00:00 2001 From: Aidan Gauland Date: Sun, 10 Mar 2024 16:22:04 +1300 Subject: [PATCH 041/114] Use Nu language for NUON files (#9839) --- languages.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/languages.toml b/languages.toml index 2e9f5d195..bf726e349 100644 --- a/languages.toml +++ b/languages.toml @@ -1934,7 +1934,7 @@ source = { git = "https://github.com/PrestonKnopp/tree-sitter-godot-resource", r name = "nu" scope = "source.nu" injection-regex = "nu" -file-types = ["nu"] +file-types = ["nu", "nuon"] shebangs = ["nu"] comment-token = "#" indent = { tab-width = 2, unit = " " } From c145999bff81f763a9e2d20d28c79f32bbd1306b Mon Sep 17 00:00:00 2001 From: Kalpaj Chaudhari Date: Sun, 10 Mar 2024 08:53:33 +0530 Subject: [PATCH 042/114] treesitter: Add textobjects for native funcs and constructors (#9806) This allows native functions and constructors to be accessible as part of goto_{next,prev}_func. Change-Id: Ia1234004e8b38e1c5871331a38fcf4f267da935e --- runtime/queries/java/textobjects.scm | 3 +++ 1 file changed, 3 insertions(+) diff --git a/runtime/queries/java/textobjects.scm b/runtime/queries/java/textobjects.scm index a932c7934..b0e73a0a7 100644 --- a/runtime/queries/java/textobjects.scm +++ b/runtime/queries/java/textobjects.scm @@ -1,4 +1,7 @@ (method_declaration + body: (_)? @function.inside) @function.around + +(constructor_declaration body: (_) @function.inside) @function.around (interface_declaration From 2d589e74f057188d113c34a6e52cc614134b5f31 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 12 Mar 2024 14:38:19 +0900 Subject: [PATCH 043/114] build(deps): bump cachix/install-nix-action from 25 to 26 (#9851) Bumps [cachix/install-nix-action](https://github.com/cachix/install-nix-action) from 25 to 26. - [Release notes](https://github.com/cachix/install-nix-action/releases) - [Commits](https://github.com/cachix/install-nix-action/compare/v25...v26) --- updated-dependencies: - dependency-name: cachix/install-nix-action dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- .github/workflows/cachix.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/cachix.yml b/.github/workflows/cachix.yml index 57f0a0db4..9638137b8 100644 --- a/.github/workflows/cachix.yml +++ b/.github/workflows/cachix.yml @@ -14,7 +14,7 @@ jobs: uses: actions/checkout@v4 - name: Install nix - uses: cachix/install-nix-action@v25 + uses: cachix/install-nix-action@v26 - name: Authenticate with Cachix uses: cachix/cachix-action@v14 From 2e2a1d6f613eb964dfea655a1e377cb12d1d7b48 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 12 Mar 2024 14:41:40 +0900 Subject: [PATCH 044/114] build(deps): bump open from 5.0.1 to 5.1.2 (#9854) Bumps [open](https://github.com/Byron/open-rs) from 5.0.1 to 5.1.2. - [Release notes](https://github.com/Byron/open-rs/releases) - [Changelog](https://github.com/Byron/open-rs/blob/main/changelog.md) - [Commits](https://github.com/Byron/open-rs/compare/v5.0.1...v5.1.2) --- updated-dependencies: - dependency-name: open dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- Cargo.lock | 4 ++-- helix-term/Cargo.toml | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index fd74140a5..b67796aba 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1767,9 +1767,9 @@ checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92" [[package]] name = "open" -version = "5.0.1" +version = "5.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "90878fb664448b54c4e592455ad02831e23a3f7e157374a8b95654731aac7349" +checksum = "449f0ff855d85ddbf1edd5b646d65249ead3f5e422aaa86b7d2d0b049b103e32" dependencies = [ "is-wsl", "libc", diff --git a/helix-term/Cargo.toml b/helix-term/Cargo.toml index accde567e..bc3117d20 100644 --- a/helix-term/Cargo.toml +++ b/helix-term/Cargo.toml @@ -58,7 +58,7 @@ pulldown-cmark = { version = "0.10", default-features = false } content_inspector = "0.2.4" # opening URLs -open = "5.0.1" +open = "5.1.2" url = "2.5.0" # config From ab61874efb9e53c55f44741b2455c4c08602bec9 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 12 Mar 2024 14:41:48 +0900 Subject: [PATCH 045/114] build(deps): bump cc from 1.0.88 to 1.0.90 (#9855) Bumps [cc](https://github.com/rust-lang/cc-rs) from 1.0.88 to 1.0.90. - [Release notes](https://github.com/rust-lang/cc-rs/releases) - [Commits](https://github.com/rust-lang/cc-rs/compare/1.0.88...1.0.90) --- updated-dependencies: - dependency-name: cc dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- Cargo.lock | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index b67796aba..6fe238fe0 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -145,9 +145,9 @@ checksum = "df8670b8c7b9dae1793364eafadf7239c40d669904660c5960d74cfd80b46a53" [[package]] name = "cc" -version = "1.0.88" +version = "1.0.90" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "02f341c093d19155a6e41631ce5971aac4e9a868262212153124c15fa22d1cdc" +checksum = "8cd6604a82acf3039f1144f54b8eb34e91ffba622051189e71b781822d5ee1f5" [[package]] name = "cfg-if" From 2d15acdf6029fd9b418bf4797c2947d6004dddbd Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 12 Mar 2024 14:45:44 +0900 Subject: [PATCH 046/114] build(deps): bump libloading from 0.8.2 to 0.8.3 (#9857) Bumps [libloading](https://github.com/nagisa/rust_libloading) from 0.8.2 to 0.8.3. - [Commits](https://github.com/nagisa/rust_libloading/compare/0.8.2...0.8.3) --- updated-dependencies: - dependency-name: libloading dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- Cargo.lock | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 6fe238fe0..22b78986e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1603,9 +1603,9 @@ checksum = "9c198f91728a82281a64e1f4f9eeb25d82cb32a5de251c6bd1b5154d63a8e7bd" [[package]] name = "libloading" -version = "0.8.2" +version = "0.8.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2caa5afb8bf9f3a2652760ce7d4f62d21c4d5a423e68466fca30df82f2330164" +checksum = "0c2a198fb6b0eada2a8df47933734e6d35d350665a33a3593d7164fa52c75c19" dependencies = [ "cfg-if", "windows-targets 0.52.0", From 3915b04bd91084477b3076952e6ad6cfdd414e72 Mon Sep 17 00:00:00 2001 From: fnuttens Date: Wed, 13 Mar 2024 05:47:55 +0100 Subject: [PATCH 047/114] fix(themes-catppuccin): make inlay hints more legible (#9859) --- runtime/themes/catppuccin_mocha.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/runtime/themes/catppuccin_mocha.toml b/runtime/themes/catppuccin_mocha.toml index 1ea57e960..65ba76e4b 100644 --- a/runtime/themes/catppuccin_mocha.toml +++ b/runtime/themes/catppuccin_mocha.toml @@ -88,7 +88,7 @@ "ui.virtual" = "overlay0" "ui.virtual.ruler" = { bg = "surface0" } "ui.virtual.indent-guide" = "surface0" -"ui.virtual.inlay-hint" = { fg = "surface1", bg = "mantle" } +"ui.virtual.inlay-hint" = { fg = "overlay0", bg = "base" } "ui.selection" = { bg = "surface1" } From e01a5582942ef96d0de9c369d2b9408c6355cd1b Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 14 Mar 2024 14:13:36 +0900 Subject: [PATCH 048/114] build(deps): bump log from 0.4.20 to 0.4.21 (#9856) Bumps [log](https://github.com/rust-lang/log) from 0.4.20 to 0.4.21. - [Release notes](https://github.com/rust-lang/log/releases) - [Changelog](https://github.com/rust-lang/log/blob/master/CHANGELOG.md) - [Commits](https://github.com/rust-lang/log/compare/0.4.20...0.4.21) --- updated-dependencies: - dependency-name: log dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- Cargo.lock | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 22b78986e..9bea99ac5 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1638,9 +1638,9 @@ dependencies = [ [[package]] name = "log" -version = "0.4.20" +version = "0.4.21" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b5e6163cb8c49088c2c36f57875e58ccd8c87c7427f7fbd50ea6710b2f3f2e8f" +checksum = "90ed8c1e510134f979dbc4f070f87d4313098b704861a105fe34231c70a3901c" [[package]] name = "lsp-types" From b44b627b1403f8a3e23251bc79558d482346c4b0 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 11 Mar 2024 23:37:10 +0000 Subject: [PATCH 049/114] build(deps): bump chrono from 0.4.34 to 0.4.35 Bumps [chrono](https://github.com/chronotope/chrono) from 0.4.34 to 0.4.35. - [Release notes](https://github.com/chronotope/chrono/releases) - [Changelog](https://github.com/chronotope/chrono/blob/main/CHANGELOG.md) - [Commits](https://github.com/chronotope/chrono/compare/v0.4.34...v0.4.35) --- updated-dependencies: - dependency-name: chrono dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- Cargo.lock | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 9bea99ac5..8628d002f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -168,9 +168,9 @@ dependencies = [ [[package]] name = "chrono" -version = "0.4.34" +version = "0.4.35" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5bc015644b92d5890fab7489e49d21f879d5c990186827d42ec511919404f38b" +checksum = "8eaf5903dcbc0a39312feb77df2ff4c76387d591b9fc7b04a238dcf8bb62639a" dependencies = [ "android-tzdata", "iana-time-zone", From 6c4d986c1b1ac4e350dced513b6608ba4464cde3 Mon Sep 17 00:00:00 2001 From: Michael Davis Date: Tue, 12 Mar 2024 09:58:33 -0400 Subject: [PATCH 050/114] Use non-deprecated chrono Duration functions --- helix-core/src/increment/date_time.rs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/helix-core/src/increment/date_time.rs b/helix-core/src/increment/date_time.rs index 2980bb58b..04cff6b47 100644 --- a/helix-core/src/increment/date_time.rs +++ b/helix-core/src/increment/date_time.rs @@ -27,7 +27,7 @@ pub fn increment(selected_text: &str, amount: i64) -> Option { let date_time = NaiveDateTime::parse_from_str(date_time, format.fmt).ok()?; Some( date_time - .checked_add_signed(Duration::minutes(amount))? + .checked_add_signed(Duration::try_minutes(amount)?)? .format(format.fmt) .to_string(), ) @@ -35,14 +35,15 @@ pub fn increment(selected_text: &str, amount: i64) -> Option { (true, false) => { let date = NaiveDate::parse_from_str(date_time, format.fmt).ok()?; Some( - date.checked_add_signed(Duration::days(amount))? + date.checked_add_signed(Duration::try_days(amount)?)? .format(format.fmt) .to_string(), ) } (false, true) => { let time = NaiveTime::parse_from_str(date_time, format.fmt).ok()?; - let (adjusted_time, _) = time.overflowing_add_signed(Duration::minutes(amount)); + let (adjusted_time, _) = + time.overflowing_add_signed(Duration::try_minutes(amount)?); Some(adjusted_time.format(format.fmt).to_string()) } (false, false) => None, From 0c51ab16d0c65505705297b89ebb1147f3cc8fee Mon Sep 17 00:00:00 2001 From: Kirawi <67773714+kirawi@users.noreply.github.com> Date: Fri, 15 Mar 2024 12:38:22 -0400 Subject: [PATCH 051/114] Add a yank diagnostic command (#9640) * yank diagnostic command * improve success message * move to a typed command * docgen --- book/src/generated/typable-cmd.md | 1 + helix-term/src/commands/typed.rs | 47 +++++++++++++++++++++++++++++++ 2 files changed, 48 insertions(+) diff --git a/book/src/generated/typable-cmd.md b/book/src/generated/typable-cmd.md index f4fcb6f62..dbb8b5f38 100644 --- a/book/src/generated/typable-cmd.md +++ b/book/src/generated/typable-cmd.md @@ -86,3 +86,4 @@ | `:clear-register` | Clear given register. If no argument is provided, clear all registers. | | `:redraw` | Clear and re-render the whole UI | | `:move` | Move the current buffer and its corresponding file to a different path | +| `:yank-diagnostic` | Yank diagnostic(s) under primary cursor to register, or clipboard by default | diff --git a/helix-term/src/commands/typed.rs b/helix-term/src/commands/typed.rs index 3d7ea3fc8..384db4ac3 100644 --- a/helix-term/src/commands/typed.rs +++ b/helix-term/src/commands/typed.rs @@ -2414,6 +2414,46 @@ fn move_buffer( Ok(()) } +fn yank_diagnostic( + cx: &mut compositor::Context, + args: &[Cow], + event: PromptEvent, +) -> anyhow::Result<()> { + if event != PromptEvent::Validate { + return Ok(()); + } + + let (view, doc) = current_ref!(cx.editor); + let primary = doc.selection(view.id).primary(); + + // Look only for diagnostics that intersect with the primary selection + let diag: Vec<_> = doc + .diagnostics() + .iter() + .filter(|d| primary.overlaps(&helix_core::Range::new(d.range.start, d.range.end))) + .map(|d| d.message.clone()) + .collect(); + let n = diag.len(); + if n == 0 { + bail!("No diagnostics under primary selection"); + } + + let reg = match args.get(0) { + Some(s) => { + ensure!(s.chars().count() == 1, format!("Invalid register {s}")); + s.chars().next().unwrap() + } + None => '+', + }; + + cx.editor.registers.write(reg, diag)?; + cx.editor.set_status(format!( + "Yanked {n} diagnostic{} to register {reg}", + if n == 1 { "" } else { "s" } + )); + Ok(()) +} + pub const TYPABLE_COMMAND_LIST: &[TypableCommand] = &[ TypableCommand { name: "quit", @@ -3021,6 +3061,13 @@ pub const TYPABLE_COMMAND_LIST: &[TypableCommand] = &[ fun: move_buffer, signature: CommandSignature::positional(&[completers::filename]), }, + TypableCommand { + name: "yank-diagnostic", + aliases: &[], + doc: "Yank diagnostic(s) under primary cursor to register, or clipboard by default", + fun: yank_diagnostic, + signature: CommandSignature::none(), + }, ]; pub static TYPABLE_COMMAND_MAP: Lazy> = From b961acf74601f0ede754d595f52ed4cba300e37f Mon Sep 17 00:00:00 2001 From: Mike Trinkala Date: Fri, 15 Mar 2024 12:44:08 -0700 Subject: [PATCH 052/114] Update regex-cursor (#9891) --- Cargo.lock | 4 ++-- helix-stdx/Cargo.toml | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 8628d002f..7b73b1b1a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1950,9 +1950,9 @@ dependencies = [ [[package]] name = "regex-cursor" -version = "0.1.3" +version = "0.1.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a43718aa0040434d45728c43f56bd53bda75a91c46954cdf0f2ff4dbc8aabbe7" +checksum = "ae4327b5fde3ae6fda0152128d3d59b95a5aad7be91c405869300091720f7169" dependencies = [ "log", "memchr", diff --git a/helix-stdx/Cargo.toml b/helix-stdx/Cargo.toml index 5ac7c011f..ed23f4e4f 100644 --- a/helix-stdx/Cargo.toml +++ b/helix-stdx/Cargo.toml @@ -16,7 +16,7 @@ dunce = "1.0" etcetera = "0.8" ropey = { version = "1.6.1", default-features = false } which = "6.0" -regex-cursor = "0.1.3" +regex-cursor = "0.1.4" [dev-dependencies] tempfile = "3.10" From 9282f1b8e546583d9e461cd78bed7d2f21dd1770 Mon Sep 17 00:00:00 2001 From: Michael Davis Date: Fri, 15 Mar 2024 19:52:57 -0400 Subject: [PATCH 053/114] Handle starting and continuing the count separately (#9887) --- helix-term/src/ui/editor.rs | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/helix-term/src/ui/editor.rs b/helix-term/src/ui/editor.rs index f3bba5d1c..c1e36bbdd 100644 --- a/helix-term/src/ui/editor.rs +++ b/helix-term/src/ui/editor.rs @@ -916,13 +916,15 @@ impl EditorView { fn command_mode(&mut self, mode: Mode, cxt: &mut commands::Context, event: KeyEvent) { match (event, cxt.editor.count) { - // count handling - (key!(i @ '0'), Some(_)) | (key!(i @ '1'..='9'), _) - if !self.keymaps.contains_key(mode, event) => - { + // If the count is already started and the input is a number, always continue the count. + (key!(i @ '0'..='9'), Some(count)) => { + let i = i.to_digit(10).unwrap() as usize; + cxt.editor.count = NonZeroUsize::new(count.get() * 10 + i); + } + // A non-zero digit will start the count if that number isn't used by a keymap. + (key!(i @ '1'..='9'), None) if !self.keymaps.contains_key(mode, event) => { let i = i.to_digit(10).unwrap() as usize; - cxt.editor.count = - std::num::NonZeroUsize::new(cxt.editor.count.map_or(i, |c| c.get() * 10 + i)); + cxt.editor.count = NonZeroUsize::new(i); } // special handling for repeat operator (key!('.'), _) if self.keymaps.pending().is_empty() => { From 6fea7876a47df8627a4b40361a6fc0f692c6601f Mon Sep 17 00:00:00 2001 From: Nick Date: Sat, 16 Mar 2024 18:20:47 +0530 Subject: [PATCH 054/114] Fix comment key bind behaviour in OCaml (#9894) --- languages.toml | 1 - 1 file changed, 1 deletion(-) diff --git a/languages.toml b/languages.toml index bf726e349..8fbb98e88 100644 --- a/languages.toml +++ b/languages.toml @@ -1083,7 +1083,6 @@ injection-regex = "ocaml" file-types = ["ml"] shebangs = ["ocaml", "ocamlrun", "ocamlscript"] block-comment-tokens = { start = "(*", end = "*)" } -comment-token = "(**)" language-servers = [ "ocamllsp" ] indent = { tab-width = 2, unit = " " } From 761df60077bf33cb1077eb4cb019885ea3dd6ae7 Mon Sep 17 00:00:00 2001 From: Emi <95967983+EmiOnGit@users.noreply.github.com> Date: Sun, 17 Mar 2024 23:06:24 +0100 Subject: [PATCH 055/114] Keybind for Extend/shrink selection up and down (#9080) * implement another selection modifying command * Selection feels more ergonomic in case of swapping the direction. This also fixes a problem when starting at an empty line. * rename select_line_up/down to select_line_above/below * apply clippy suggestion of using cmp instead of if-chain * revert `Extent` implementing `Clone/Copy` * move select_line functions below extend_line implementations * implement help add function, which saturates at the number of text lines --------- Co-authored-by: Emi --- helix-term/src/commands.rs | 57 +++++++++++++++++++++++++++++++++++++- 1 file changed, 56 insertions(+), 1 deletion(-) diff --git a/helix-term/src/commands.rs b/helix-term/src/commands.rs index 4ac2496eb..133f2d540 100644 --- a/helix-term/src/commands.rs +++ b/helix-term/src/commands.rs @@ -57,6 +57,7 @@ use crate::{ use crate::job::{self, Jobs}; use std::{ + cmp::Ordering, collections::{HashMap, HashSet}, fmt, future::Future, @@ -300,6 +301,8 @@ impl MappableCommand { extend_line, "Select current line, if already selected, extend to another line based on the anchor", extend_line_below, "Select current line, if already selected, extend to next line", extend_line_above, "Select current line, if already selected, extend to previous line", + select_line_above, "Select current line, if already selected, extend or shrink line above based on the anchor", + select_line_below, "Select current line, if already selected, extend or shrink line below based on the anchor", extend_to_line_bounds, "Extend selection to line bounds", shrink_to_line_bounds, "Shrink selection to line bounds", delete_selection, "Delete selection", @@ -2435,7 +2438,6 @@ fn extend_line_below(cx: &mut Context) { fn extend_line_above(cx: &mut Context) { extend_line_impl(cx, Extend::Above); } - fn extend_line_impl(cx: &mut Context, extend: Extend) { let count = cx.count(); let (view, doc) = current!(cx.editor); @@ -2474,6 +2476,59 @@ fn extend_line_impl(cx: &mut Context, extend: Extend) { doc.set_selection(view.id, selection); } +fn select_line_below(cx: &mut Context) { + select_line_impl(cx, Extend::Below); +} +fn select_line_above(cx: &mut Context) { + select_line_impl(cx, Extend::Above); +} +fn select_line_impl(cx: &mut Context, extend: Extend) { + let mut count = cx.count(); + let (view, doc) = current!(cx.editor); + let text = doc.text(); + let saturating_add = |a: usize, b: usize| (a + b).min(text.len_lines()); + let selection = doc.selection(view.id).clone().transform(|range| { + let (start_line, end_line) = range.line_range(text.slice(..)); + let start = text.line_to_char(start_line); + let end = text.line_to_char(saturating_add(end_line, 1)); + let direction = range.direction(); + + // Extending to line bounds is counted as one step + if range.from() != start || range.to() != end { + count = count.saturating_sub(1) + } + let (anchor_line, head_line) = match (&extend, direction) { + (Extend::Above, Direction::Forward) => (start_line, end_line.saturating_sub(count)), + (Extend::Above, Direction::Backward) => (end_line, start_line.saturating_sub(count)), + (Extend::Below, Direction::Forward) => (start_line, saturating_add(end_line, count)), + (Extend::Below, Direction::Backward) => (end_line, saturating_add(start_line, count)), + }; + let (anchor, head) = match anchor_line.cmp(&head_line) { + Ordering::Less => ( + text.line_to_char(anchor_line), + text.line_to_char(saturating_add(head_line, 1)), + ), + Ordering::Equal => match extend { + Extend::Above => ( + text.line_to_char(saturating_add(anchor_line, 1)), + text.line_to_char(head_line), + ), + Extend::Below => ( + text.line_to_char(head_line), + text.line_to_char(saturating_add(anchor_line, 1)), + ), + }, + + Ordering::Greater => ( + text.line_to_char(saturating_add(anchor_line, 1)), + text.line_to_char(head_line), + ), + }; + Range::new(anchor, head) + }); + + doc.set_selection(view.id, selection); +} fn extend_to_line_bounds(cx: &mut Context) { let (view, doc) = current!(cx.editor); From 61f7d9ce2f2d20f4b0bd2f21036eac1f11cb2c5c Mon Sep 17 00:00:00 2001 From: Arthur Deierlein <110528300+c0rydoras@users.noreply.github.com> Date: Sun, 17 Mar 2024 23:36:54 +0100 Subject: [PATCH 056/114] fix typo "braket" in jsx highlights (#9910) --- runtime/queries/_jsx/highlights.scm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/runtime/queries/_jsx/highlights.scm b/runtime/queries/_jsx/highlights.scm index 853254e5b..2a696641c 100644 --- a/runtime/queries/_jsx/highlights.scm +++ b/runtime/queries/_jsx/highlights.scm @@ -40,4 +40,4 @@ (jsx_closing_element [""] @punctuation.bracket) ; -(jsx_self_closing_element ["<" "/>"] @punctuation.braket) +(jsx_self_closing_element ["<" "/>"] @punctuation.bracket) From 9ec0271873ed484f96342489b4117391e88abcd3 Mon Sep 17 00:00:00 2001 From: Arthur Deierlein <110528300+c0rydoras@users.noreply.github.com> Date: Sun, 17 Mar 2024 23:53:30 +0100 Subject: [PATCH 057/114] Add support for hyprland config (#9899) * feat: add hyprland config language * adjust indents to helix * adjust highlights to helix --- book/src/generated/lang-support.md | 1 + languages.toml | 12 +++++ runtime/queries/hyprlang/highlights.scm | 58 +++++++++++++++++++++++++ runtime/queries/hyprlang/indents.scm | 6 +++ runtime/queries/hyprlang/injections.scm | 3 ++ 5 files changed, 80 insertions(+) create mode 100644 runtime/queries/hyprlang/highlights.scm create mode 100644 runtime/queries/hyprlang/indents.scm create mode 100644 runtime/queries/hyprlang/injections.scm diff --git a/book/src/generated/lang-support.md b/book/src/generated/lang-support.md index 7792bf594..2cb1e926c 100644 --- a/book/src/generated/lang-support.md +++ b/book/src/generated/lang-support.md @@ -77,6 +77,7 @@ | hosts | ✓ | | | | | html | ✓ | | | `vscode-html-language-server` | | hurl | ✓ | | ✓ | | +| hyprlang | ✓ | | ✓ | | | idris | | | | `idris2-lsp` | | iex | ✓ | | | | | ini | ✓ | | | | diff --git a/languages.toml b/languages.toml index 8fbb98e88..b01da144d 100644 --- a/languages.toml +++ b/languages.toml @@ -3284,3 +3284,15 @@ indent = { tab-width = 2, unit = " " } [[grammar]] name = "ld" source = { git = "https://github.com/mtoohey31/tree-sitter-ld", rev = "81978cde3844bfc199851e39c80a20ec6444d35e" } + +[[language]] +name = "hyprlang" +scope = "source.hyprlang" +roots = ["hyprland.conf"] +file-types = [ { glob = "hyprland.conf"} ] +comment-token = "#" +grammar = "hyprlang" + +[[grammar]] +name = "hyprlang" +source = { git = "https://github.com/tree-sitter-grammars/tree-sitter-hyprlang", rev = "27af9b74acf89fa6bed4fb8cb8631994fcb2e6f3"} diff --git a/runtime/queries/hyprlang/highlights.scm b/runtime/queries/hyprlang/highlights.scm new file mode 100644 index 000000000..bf898c9cd --- /dev/null +++ b/runtime/queries/hyprlang/highlights.scm @@ -0,0 +1,58 @@ +(comment) @comment + +[ + "source" + "exec" + "exec-once" +] @function.builtin + +(keyword + (name) @keyword) + +(assignment + (name) @variable.other.member) + +(section + (name) @namespace) + +(section + device: (device_name) @type) + +(variable) @variable + +"$" @punctuation.special + +(boolean) @constant.builtin.boolean + +(string) @string + +(mod) @constant + +[ + "rgb" + "rgba" +] @function.builtin + +[ + (number) + (legacy_hex) + (angle) + (hex) +] @constant.numeric + +"deg" @type + +"," @punctuation.delimiter + +[ + "(" + ")" + "{" + "}" +] @punctuation.bracket + +[ + "=" + "-" + "+" +] @operator diff --git a/runtime/queries/hyprlang/indents.scm b/runtime/queries/hyprlang/indents.scm new file mode 100644 index 000000000..88bfe7434 --- /dev/null +++ b/runtime/queries/hyprlang/indents.scm @@ -0,0 +1,6 @@ +(section) @indent + +(section + "}" @outdent) + +"}" @extend diff --git a/runtime/queries/hyprlang/injections.scm b/runtime/queries/hyprlang/injections.scm new file mode 100644 index 000000000..1f0199ed8 --- /dev/null +++ b/runtime/queries/hyprlang/injections.scm @@ -0,0 +1,3 @@ +(exec + (string) @injection.content + (#set! injection.language "bash")) From e36774c2c8f967c16ce2e10f2ba074838b324ec6 Mon Sep 17 00:00:00 2001 From: "George \"Riye\" Hollister" Date: Sun, 17 Mar 2024 22:54:05 +0000 Subject: [PATCH 058/114] Add Support for JSONC (#9906) * Added `jsonc` language with support for comments The `vscode-json-language-server` accepts `jsonc` as a language id. Allowing the use of comments within JSON files. * fix: Update `injdection-rejex` to be unique * fix: use includes to remove redundant queries * ci: Generate language-support docs --- book/src/generated/lang-support.md | 1 + languages.toml | 10 +++++++++- runtime/queries/jsonc/highlights.scm | 2 ++ runtime/queries/jsonc/indents.scm | 1 + 4 files changed, 13 insertions(+), 1 deletion(-) create mode 100644 runtime/queries/jsonc/highlights.scm create mode 100644 runtime/queries/jsonc/indents.scm diff --git a/book/src/generated/lang-support.md b/book/src/generated/lang-support.md index 2cb1e926c..40029657f 100644 --- a/book/src/generated/lang-support.md +++ b/book/src/generated/lang-support.md @@ -88,6 +88,7 @@ | jsdoc | ✓ | | | | | json | ✓ | | ✓ | `vscode-json-language-server` | | json5 | ✓ | | | | +| jsonc | ✓ | | ✓ | `vscode-json-language-server` | | jsonnet | ✓ | | | `jsonnet-language-server` | | jsx | ✓ | ✓ | ✓ | `typescript-language-server` | | julia | ✓ | ✓ | ✓ | `julia` | diff --git a/languages.toml b/languages.toml index b01da144d..4018fbe0e 100644 --- a/languages.toml +++ b/languages.toml @@ -367,7 +367,6 @@ scope = "source.json" injection-regex = "json" file-types = [ "json", - "jsonc", "arb", "ipynb", "geojson", @@ -396,6 +395,15 @@ indent = { tab-width = 2, unit = " " } name = "json" source = { git = "https://github.com/tree-sitter/tree-sitter-json", rev = "73076754005a460947cafe8e03a8cf5fa4fa2938" } +[[language]] +name = "jsonc" +scope = "source.json" +injection-regex = "jsonc" +file-types = ["jsonc"] +grammar = "json" +language-servers = [ "vscode-json-language-server" ] +auto-format = true +indent = { tab-width = 2, unit = " " } [[language]] name = "json5" diff --git a/runtime/queries/jsonc/highlights.scm b/runtime/queries/jsonc/highlights.scm new file mode 100644 index 000000000..0164321b6 --- /dev/null +++ b/runtime/queries/jsonc/highlights.scm @@ -0,0 +1,2 @@ +; inherits: json +(comment) @comment diff --git a/runtime/queries/jsonc/indents.scm b/runtime/queries/jsonc/indents.scm new file mode 100644 index 000000000..41269219e --- /dev/null +++ b/runtime/queries/jsonc/indents.scm @@ -0,0 +1 @@ +; inherits: json From 3890376a23e84d5bcdac31cb9d0f6913abe0fc7f Mon Sep 17 00:00:00 2001 From: Dan Cardamore Date: Sun, 17 Mar 2024 18:55:49 -0400 Subject: [PATCH 059/114] add 'file-absolute-path' to statusline (#4535) * feat: add 'file-abs-path' to statusline (#4434) * cleanup implementation * rename to be non-abbreviated names --------- Co-authored-by: Michael Davis --- book/src/configuration.md | 1 + helix-term/src/ui/statusline.rs | 17 +++++++++++++++++ helix-view/src/editor.rs | 3 +++ 3 files changed, 21 insertions(+) diff --git a/book/src/configuration.md b/book/src/configuration.md index d87936457..8857af82a 100644 --- a/book/src/configuration.md +++ b/book/src/configuration.md @@ -108,6 +108,7 @@ The following statusline elements can be configured: | `mode` | The current editor mode (`mode.normal`/`mode.insert`/`mode.select`) | | `spinner` | A progress spinner indicating LSP activity | | `file-name` | The path/name of the opened file | +| `file-absolute-path` | The absolute path/name of the opened file | | `file-base-name` | The basename of the opened file | | `file-modification-indicator` | The indicator to show whether the file is modified (a `[+]` appears when there are unsaved changes) | | `file-encoding` | The encoding of the opened file if it differs from UTF-8 | diff --git a/helix-term/src/ui/statusline.rs b/helix-term/src/ui/statusline.rs index 9871828ee..c3464067f 100644 --- a/helix-term/src/ui/statusline.rs +++ b/helix-term/src/ui/statusline.rs @@ -142,6 +142,7 @@ where helix_view::editor::StatusLineElement::Spinner => render_lsp_spinner, helix_view::editor::StatusLineElement::FileBaseName => render_file_base_name, helix_view::editor::StatusLineElement::FileName => render_file_name, + helix_view::editor::StatusLineElement::FileAbsolutePath => render_file_absolute_path, helix_view::editor::StatusLineElement::FileModificationIndicator => { render_file_modification_indicator } @@ -430,6 +431,22 @@ where write(context, title, None); } +fn render_file_absolute_path(context: &mut RenderContext, write: F) +where + F: Fn(&mut RenderContext, String, Option