aboutsummaryrefslogtreecommitdiff
path: root/helix-core/src/syntax.rs
diff options
context:
space:
mode:
authorontley2024-02-12 01:35:25 +0000
committerGitHub2024-02-12 01:35:25 +0000
commit6a90166d0a3d8fd0e2e96e4ac8e196b2b2989760 (patch)
treee722b996e123813e2fb0f9972136fa6002ca1839 /helix-core/src/syntax.rs
parentac8d1f62a126781fbac087aa374aad540dd659b1 (diff)
Add required-root-patterns for situational lsp activation (#8696)
* Added required-root-patterns for situational lsp activation using globbing * Replaced filter_map with flatten * updated book to include required-root-patterns option * fixed wrong function name for path * Added globset to helix-core. Moved globset building to config parsing. * Normalize implements AsRef * cargo fmt * Revert "cargo fmt" This reverts commit ca8ce123e8d77d2ae8ed84d5273a9b554101b0db.
Diffstat (limited to 'helix-core/src/syntax.rs')
-rw-r--r--helix-core/src/syntax.rs23
1 files changed, 23 insertions, 0 deletions
diff --git a/helix-core/src/syntax.rs b/helix-core/src/syntax.rs
index 99b5a3d1..5d45deaf 100644
--- a/helix-core/src/syntax.rs
+++ b/helix-core/src/syntax.rs
@@ -10,6 +10,7 @@ use crate::{
use ahash::RandomState;
use arc_swap::{ArcSwap, Guard};
use bitflags::bitflags;
+use globset::GlobSet;
use hashbrown::raw::RawTable;
use slotmap::{DefaultKey as LayerId, HopSlotMap};
@@ -365,6 +366,22 @@ where
serializer.end()
}
+fn deserialize_required_root_patterns<'de, D>(deserializer: D) -> Result<Option<GlobSet>, D::Error>
+where
+ D: serde::Deserializer<'de>,
+{
+ let patterns = Vec::<String>::deserialize(deserializer)?;
+ if patterns.is_empty() {
+ return Ok(None);
+ }
+ let mut builder = globset::GlobSetBuilder::new();
+ for pattern in patterns {
+ let glob = globset::Glob::new(&pattern).map_err(serde::de::Error::custom)?;
+ builder.add(glob);
+ }
+ builder.build().map(Some).map_err(serde::de::Error::custom)
+}
+
#[derive(Debug, Serialize, Deserialize)]
#[serde(rename_all = "kebab-case")]
pub struct LanguageServerConfiguration {
@@ -378,6 +395,12 @@ pub struct LanguageServerConfiguration {
pub config: Option<serde_json::Value>,
#[serde(default = "default_timeout")]
pub timeout: u64,
+ #[serde(
+ default,
+ skip_serializing,
+ deserialize_with = "deserialize_required_root_patterns"
+ )]
+ pub required_root_patterns: Option<GlobSet>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]