Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions crates/codebook-config/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ pub trait CodebookConfig: Sync + Send + Debug {
fn should_flag_word(&self, word: &str) -> bool;
fn get_ignore_patterns(&self) -> Vec<Regex>;
fn get_min_word_length(&self) -> usize;
fn use_local(&self) -> bool;
fn should_check_tag(&self, tag: &str) -> bool;
fn cache_dir(&self) -> &Path;

Expand Down Expand Up @@ -285,6 +286,17 @@ impl CodebookConfigFile {
.cloned()
.unwrap_or_else(ConfigSettings::default);

if !project.use_local {
return if project.use_global {
global_config
.content()
.cloned()
Comment on lines +289 to +293
Comment on lines +289 to +293
.unwrap_or_else(ConfigSettings::default)
} else {
ConfigSettings::default()
};
}

if project.use_global {
if let Some(global) = global_config.content() {
let mut effective = global.clone();
Expand Down Expand Up @@ -543,6 +555,10 @@ impl CodebookConfig for CodebookConfigFile {
self.snapshot().min_word_length()
}

fn use_local(&self) -> bool {
self.snapshot().use_local
}

fn should_check_tag(&self, tag: &str) -> bool {
self.snapshot().should_check_tag(tag)
}
Expand Down Expand Up @@ -652,6 +668,10 @@ impl CodebookConfig for CodebookConfigMemory {
self.snapshot().min_word_length()
}

fn use_local(&self) -> bool {
self.snapshot().use_local
}

fn should_check_tag(&self, tag: &str) -> bool {
self.snapshot().should_check_tag(tag)
}
Expand Down
16 changes: 16 additions & 0 deletions crates/codebook-config/src/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,13 @@ pub struct ConfigSettings {
)]
pub ignore_patterns: Vec<Regex>,

/// Whether to use local (project) configuration
#[serde(
default = "default_use_local",
skip_serializing_if = "is_default_use_local"
)]
pub use_local: bool,

/// Whether to use global configuration
#[serde(
default = "default_use_global",
Expand Down Expand Up @@ -305,6 +312,14 @@ fn is_default_use_global(value: &bool) -> bool {
*value == default_use_global()
}

fn default_use_local() -> bool {
true
}

fn is_default_use_local(value: &bool) -> bool {
*value == default_use_local()
}

fn default_min_word_length() -> usize {
3
}
Expand All @@ -319,6 +334,7 @@ impl Default for ConfigSettings {
ignore_paths: Vec::new(),
ignore_patterns: Vec::new(),
use_global: true,
use_local: true,
min_word_length: None,
include_tags: Vec::new(),
exclude_tags: Vec::new(),
Expand Down
31 changes: 17 additions & 14 deletions crates/codebook-lsp/src/lsp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,7 @@ impl LanguageServer for Backend {
None => return Ok(None),
};

let use_local = self.config_handle().use_local();
let mut has_codebook_diagnostic = false;
for diag in params.context.diagnostics {
// Only process our own diagnostics
Expand Down Expand Up @@ -277,20 +278,22 @@ impl LanguageServer for Backend {
&params.text_document.uri,
)));
});
actions.push(CodeActionOrCommand::CodeAction(CodeAction {
title: format!("Add '{word}' to dictionary"),
kind: Some(CodeActionKind::QUICKFIX),
diagnostics: None,
edit: None,
command: Some(Command {
if use_local {
actions.push(CodeActionOrCommand::CodeAction(CodeAction {
title: format!("Add '{word}' to dictionary"),
command: CodebookCommand::AddWord.into(),
arguments: Some(vec![word.to_string().into()]),
}),
is_preferred: None,
disabled: None,
data: None,
}));
kind: Some(CodeActionKind::QUICKFIX),
diagnostics: None,
edit: None,
command: Some(Command {
title: format!("Add '{word}' to dictionary"),
command: CodebookCommand::AddWord.into(),
arguments: Some(vec![word.to_string().into()]),
}),
is_preferred: None,
disabled: None,
data: None,
}));
}
actions.push(CodeActionOrCommand::CodeAction(CodeAction {
title: format!("Add '{word}' to global dictionary"),
kind: Some(CodeActionKind::QUICKFIX),
Expand All @@ -306,7 +309,7 @@ impl LanguageServer for Backend {
data: None,
}));
}
if has_codebook_diagnostic {
if has_codebook_diagnostic && use_local {
actions.push(CodeActionOrCommand::CodeAction(CodeAction {
title: "Add current file to ignore list".to_string(),
kind: Some(CodeActionKind::QUICKFIX),
Expand Down