Skip to content

Commit

Permalink
WIP: auto-wrap; add config option (helix-editor#2274)
Browse files Browse the repository at this point in the history
  • Loading branch information
matta committed Jul 5, 2024
1 parent fc97ecc commit 65ad584
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
12 changes: 12 additions & 0 deletions helix-core/src/syntax.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ pub struct LanguageConfiguration {
pub block_comment_tokens: Option<Vec<BlockCommentToken>>,
pub text_width: Option<usize>,
pub soft_wrap: Option<SoftWrap>,
pub auto_wrap: Option<AutoWrap>,

#[serde(default)]
pub auto_format: bool,
Expand Down Expand Up @@ -856,6 +857,17 @@ pub struct SoftWrap {
pub wrap_at_text_width: Option<bool>,
}

#[derive(Debug, Clone, Default, PartialEq, Eq, Serialize, Deserialize)]
#[serde(default, rename_all = "kebab-case", deny_unknown_fields)]
pub struct AutoWrap {
/// Hard wrap lines that exceed text-width. Default to off.
// NOTE: Option on purpose because the struct is shared between language
// config and global config.
// By default the option is None so that the language config falls back to
// the global config unless explicitly set.
pub enable: Option<bool>,
}

#[derive(Debug)]
struct FileTypeGlob {
glob: globset::Glob,
Expand Down
8 changes: 7 additions & 1 deletion helix-view/src/editor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,9 @@ use anyhow::{anyhow, bail, Error};
pub use helix_core::diagnostic::Severity;
use helix_core::{
auto_pairs::AutoPairs,
syntax::{self, AutoPairConfig, IndentationHeuristic, LanguageServerFeature, SoftWrap},
syntax::{
self, AutoPairConfig, AutoWrap, IndentationHeuristic, LanguageServerFeature, SoftWrap,
},
Change, LineEnding, Position, Range, Selection, NATIVE_LINE_ENDING,
};
use helix_dap as dap;
Expand Down Expand Up @@ -324,6 +326,7 @@ pub struct Config {
/// Whether to color modes with different colors. Defaults to `false`.
pub color_modes: bool,
pub soft_wrap: SoftWrap,
pub auto_wrap: AutoWrap,
/// Workspace specific lsp ceiling dirs
pub workspace_lsp_roots: Vec<PathBuf>,
/// Which line ending to choose for new documents. Defaults to `native`. i.e. `crlf` on Windows, otherwise `lf`.
Expand Down Expand Up @@ -966,6 +969,9 @@ impl Default for Config {
enable: Some(false),
..SoftWrap::default()
},
auto_wrap: AutoWrap {
enable: Some(false),
},
text_width: 80,
completion_replace: false,
workspace_lsp_roots: Vec::new(),
Expand Down

0 comments on commit 65ad584

Please sign in to comment.