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
+27 -2
View File
@@ -1006,7 +1006,8 @@ mod tests {
r#"
Vamp.configure do |c|
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
"#,
);
@@ -1069,12 +1070,18 @@ end
for assignment in [
format!("c.tab_spaces = {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(
"config.rb",
&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 [
@@ -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]
fn actual_ruby_dsl_context_queued_effects_and_output_isolation() {
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
attr_reader :lsp
# @return [Hash{String => Integer, nil}] LSP-style language IDs to Tab widths
attr_reader :language_tab_spaces
# @return [Vamp::BarConfig]
attr_reader :bar
@@ -265,14 +268,7 @@ module Vamp
# @param languages [Hash{String => Integer, nil}] LSP-style language IDs to Tab widths
# @return [Hash{String => Integer, nil}]
def language_tab_spaces=(languages)
raise TypeError, "language_tab_spaces must be a Hash" unless languages.is_a?(Hash)
@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
@language_tab_spaces = language_tab_spaces!(languages)
end
# @param lines [Integer] nonnegative context lines around each diff change
@@ -350,7 +346,7 @@ module Vamp
"highlight_trailing_whitespace" => @highlight_trailing_whitespace,
"whitespace_characters" => @whitespace_characters,
"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,
"popup" => { "command" => @popup.command, "search" => @popup.search },
"diff_context_lines" => @diff_context_lines, "diff_expand_lines" => @diff_expand_lines,
@@ -369,6 +365,19 @@ module Vamp
spaces
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 label [String]
# @param minimum [Integer]