fix: support mutable language tab configuration

This commit is contained in:
Valdemar Lorenzen
2026-10-14 12:31:44 +02:00
parent c5f80f27a6
commit 8a1e98819c
4 changed files with 58 additions and 13 deletions
+12 -1
View File
@@ -20,7 +20,7 @@ Vamp.configure do |config|
config.whitespace_characters = {} # opt in: { " " => "·", "\t" => "→", "\n" => "↵" } config.whitespace_characters = {} # opt in: { " " => "·", "\t" => "→", "\n" => "↵" }
config.whitespace_scope = "all" # or "leading" for indentation only config.whitespace_scope = "all" # or "leading" for indentation only
config.tab_spaces = nil # opt in with a fixed number of spaces per Tab, e.g. 4 config.tab_spaces = nil # opt in with a fixed number of spaces per Tab, e.g. 4
config.language_tab_spaces = {} # overrides: { "ruby" => 2, "makefile" => nil } # config.language_tab_spaces.merge!("ruby" => 2, "makefile" => nil)
config.file_explorer_side = "right" config.file_explorer_side = "right"
config.file_explorer_view = "tree" config.file_explorer_view = "tree"
config.file_picker_view = "tree" config.file_picker_view = "tree"
@@ -73,6 +73,17 @@ Markers appear in ordinary and historical buffers and both sides of split/unifie
`config.language_tab_spaces` defaults to `{}`. It overrides the global setting using the same case-sensitive language IDs as `config.lsp`, for example `{ "rust" => 4, "ruby" => 2, "python" => 4, "makefile" => nil }`. Syntax detection and built-in LSP presets share canonical IDs rather than maintaining separate naming conventions; other bundled IDs include `shellscript`, `cpp`, and `typescriptreact` for Bash, C++, and TSX. Display labels such as “Ruby” remain presentation-only. A `nil` override preserves literal tabs for that language, even when the global setting uses spaces. Unlisted or unknown languages and unnamed buffers without a recognized shebang use `tab_spaces`. Detection reuses syntax highlighting's filename, extension, and shebang rules, independently of whether an LSP is enabled. `config.language_tab_spaces` defaults to `{}`. It overrides the global setting using the same case-sensitive language IDs as `config.lsp`, for example `{ "rust" => 4, "ruby" => 2, "python" => 4, "makefile" => nil }`. Syntax detection and built-in LSP presets share canonical IDs rather than maintaining separate naming conventions; other bundled IDs include `shellscript`, `cpp`, and `typescriptreact` for Bash, C++, and TSX. Display labels such as “Ruby” remain presentation-only. A `nil` override preserves literal tabs for that language, even when the global setting uses spaces. Unlisted or unknown languages and unnamed buffers without a recognized shebang use `tab_spaces`. Detection reuses syntax highlighting's filename, extension, and shebang rules, independently of whether an LSP is enabled.
Like `config.lsp`, `config.language_tab_spaces` exposes a mutable hash: use `merge!` to add or override entries, or `config.language_tab_spaces["ruby"] = 2` to change one entry. Whole-hash assignment with `=` remains supported. Both assignment and the final hash contents are validated; invalid keys or widths inserted through hash mutation reject startup configuration rather than bypassing validation.
```ruby
config.tab_spaces = 4
config.language_tab_spaces.merge!(
"rust" => 4,
"ruby" => 2,
"makefile" => nil,
)
```
Active snippets retain Tab/Shift+Tab argument navigation; after the final stop, Tab uses the configured insertion setting. Explicit Tab bindings still take precedence, and Ctrl+i remains a Tab alias. Bracketed paste, clipboard paste, completion payloads, and plugin text retain literal tab characters. Insert undo/redo and dot repeat preserve the resolved spaces or tab. Widths other than `nil` or integers in `1..255`, non-hash language overrides, and empty, non-string, or control-containing language keys reject the configuration. Active snippets retain Tab/Shift+Tab argument navigation; after the final stop, Tab uses the configured insertion setting. Explicit Tab bindings still take precedence, and Ctrl+i remains a Tab alias. Bracketed paste, clipboard paste, completion payloads, and plugin text retain literal tab characters. Insert undo/redo and dot repeat preserve the resolved spaces or tab. Widths other than `nil` or integers in `1..255`, non-hash language overrides, and empty, non-string, or control-containing language keys reject the configuration.
`config.git_blame` defaults to `true`; set it to `false` to disable current-line inline Git blame and its background worker. Only literal Ruby booleans are accepted; other values reject the configuration. Toggle it for the running session with `:git_blame.toggle`, its palette action, or a custom binding such as `config.bind "leader b", config.core.git_blame.toggle`. There is no default shortcut. `config.git_blame` defaults to `true`; set it to `false` to disable current-line inline Git blame and its background worker. Only literal Ruby booleans are accepted; other values reject the configuration. Toggle it for the running session with `:git_blame.toggle`, its palette action, or a custom binding such as `config.bind "leader b", config.core.git_blame.toggle`. There is no default shortcut.
+1 -1
View File
@@ -10,7 +10,7 @@ Vamp.configure do |config|
config.whitespace_characters = {} # opt in: { " " => "·", "\t" => "→", "\n" => "↵" } config.whitespace_characters = {} # opt in: { " " => "·", "\t" => "→", "\n" => "↵" }
config.whitespace_scope = "all" # or "leading" for indentation only; newline markers remain independent config.whitespace_scope = "all" # or "leading" for indentation only; newline markers remain independent
config.tab_spaces = nil # opt in: 4 inserts four spaces per Tab config.tab_spaces = nil # opt in: 4 inserts four spaces per Tab
config.language_tab_spaces = {} # overrides: { "ruby" => 2, "makefile" => nil } # config.language_tab_spaces.merge!("ruby" => 2, "makefile" => nil)
config.file_explorer_side = "right" config.file_explorer_side = "right"
config.file_explorer_view = "tree" config.file_explorer_view = "tree"
config.file_picker_view = "tree" config.file_picker_view = "tree"
+27 -2
View File
@@ -1006,7 +1006,8 @@ mod tests {
r#" r#"
Vamp.configure do |c| Vamp.configure do |c|
c.tab_spaces = 4 c.tab_spaces = 4
c.language_tab_spaces = { "ruby" => 2, "makefile" => nil, "json" => 1, "yaml" => 255, "cpp" => 3, "typescriptreact" => 5 } c.language_tab_spaces.merge!("ruby" => 2, "makefile" => nil, "json" => 1, "yaml" => 255, "typescriptreact" => 5)
c.language_tab_spaces["cpp"] = 3
end end
"#, "#,
); );
@@ -1069,12 +1070,18 @@ end
for assignment in [ for assignment in [
format!("c.tab_spaces = {value}"), format!("c.tab_spaces = {value}"),
format!(r#"c.language_tab_spaces = {{ "ruby" => {value} }}"#), format!(r#"c.language_tab_spaces = {{ "ruby" => {value} }}"#),
format!(r#"c.language_tab_spaces.merge!("ruby" => {value})"#),
format!(r#"c.language_tab_spaces["ruby"] = {value}"#),
] { ] {
let config = fixture.file( let config = fixture.file(
"config.rb", "config.rb",
&format!("Vamp.configure {{ |c| {assignment} }}"), &format!("Vamp.configure {{ |c| {assignment} }}"),
); );
assert!(load_config(&config).is_err(), "{assignment}"); let error = load_config(&config).unwrap_err();
assert!(
error.contains("tab_spaces must be nil or an Integer"),
"{assignment}: {error}"
);
} }
} }
for value in [ for value in [
@@ -1092,6 +1099,24 @@ end
} }
} }
#[test]
fn language_tab_space_mutations_reject_invalid_keys_before_serialization() {
let fixture = Fixture::new();
for key in [r#""""#, ":ruby", r#""\n""#, "7"] {
for assignment in [
format!("c.language_tab_spaces.merge!({key} => 2)"),
format!("c.language_tab_spaces[{key}] = 2"),
] {
let config = fixture.file(
"config.rb",
&format!("Vamp.configure {{ |c| {assignment} }}"),
);
let error = load_config(&config).unwrap_err();
assert!(error.contains("Tab language"), "{assignment}: {error}");
}
}
}
#[test] #[test]
fn actual_ruby_dsl_context_queued_effects_and_output_isolation() { fn actual_ruby_dsl_context_queued_effects_and_output_isolation() {
let fixture = Fixture::new(); let fixture = Fixture::new();
+18 -9
View File
@@ -120,6 +120,9 @@ module Vamp
# @return [Hash{String => Boolean, Hash{String, Symbol => Object}}] language presets/options # @return [Hash{String => Boolean, Hash{String, Symbol => Object}}] language presets/options
attr_reader :lsp attr_reader :lsp
# @return [Hash{String => Integer, nil}] LSP-style language IDs to Tab widths
attr_reader :language_tab_spaces
# @return [Vamp::BarConfig] # @return [Vamp::BarConfig]
attr_reader :bar attr_reader :bar
@@ -265,14 +268,7 @@ module Vamp
# @param languages [Hash{String => Integer, nil}] LSP-style language IDs to Tab widths # @param languages [Hash{String => Integer, nil}] LSP-style language IDs to Tab widths
# @return [Hash{String => Integer, nil}] # @return [Hash{String => Integer, nil}]
def language_tab_spaces=(languages) def language_tab_spaces=(languages)
raise TypeError, "language_tab_spaces must be a Hash" unless languages.is_a?(Hash) @language_tab_spaces = language_tab_spaces!(languages)
@language_tab_spaces = languages.to_h do |language, spaces|
language = nonempty_string!(language, "Tab language")
raise ArgumentError, "Tab language must not contain control characters" if language.match?(/[[:cntrl:]]/)
[language, tab_spaces!(spaces)]
end
end end
# @param lines [Integer] nonnegative context lines around each diff change # @param lines [Integer] nonnegative context lines around each diff change
@@ -350,7 +346,7 @@ module Vamp
"highlight_trailing_whitespace" => @highlight_trailing_whitespace, "highlight_trailing_whitespace" => @highlight_trailing_whitespace,
"whitespace_characters" => @whitespace_characters, "whitespace_characters" => @whitespace_characters,
"whitespace_scope" => @whitespace_scope, "whitespace_scope" => @whitespace_scope,
"tab_spaces" => @tab_spaces, "language_tab_spaces" => @language_tab_spaces, "tab_spaces" => @tab_spaces, "language_tab_spaces" => language_tab_spaces!(@language_tab_spaces),
"top_bar" => @bar.top, "bottom_bar" => @bar.bottom, "labels" => @labels, "top_bar" => @bar.top, "bottom_bar" => @bar.bottom, "labels" => @labels,
"popup" => { "command" => @popup.command, "search" => @popup.search }, "popup" => { "command" => @popup.command, "search" => @popup.search },
"diff_context_lines" => @diff_context_lines, "diff_expand_lines" => @diff_expand_lines, "diff_context_lines" => @diff_context_lines, "diff_expand_lines" => @diff_expand_lines,
@@ -369,6 +365,19 @@ module Vamp
spaces spaces
end end
# @param languages [Hash{String => Integer, nil}]
# @return [Hash{String => Integer, nil}]
def language_tab_spaces!(languages)
raise TypeError, "language_tab_spaces must be a Hash" unless languages.is_a?(Hash)
languages.to_h do |language, spaces|
language = nonempty_string!(language, "Tab language")
raise ArgumentError, "Tab language must not contain control characters" if language.match?(/[[:cntrl:]]/)
[language, tab_spaces!(spaces)]
end
end
# @param value [Integer] # @param value [Integer]
# @param label [String] # @param label [String]
# @param minimum [Integer] # @param minimum [Integer]