Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LSP: Allow for an LSP extension match on any suffix, not just filename and ext #11322

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions crates/extension/src/extension_store_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,7 @@ async fn test_extension_store(cx: &mut TestAppContext) {
matcher: LanguageMatcher {
path_suffixes: vec!["erb".into()],
first_line_pattern: None,
path_regex: None,
},
},
),
Expand All @@ -210,6 +211,7 @@ async fn test_extension_store(cx: &mut TestAppContext) {
matcher: LanguageMatcher {
path_suffixes: vec!["rb".into()],
first_line_pattern: None,
path_regex: None,
},
},
),
Expand Down
8 changes: 8 additions & 0 deletions crates/language/src/language.rs
Original file line number Diff line number Diff line change
Expand Up @@ -608,6 +608,14 @@ pub struct LanguageMatcher {
/// Given a list of `LanguageConfig`'s, the language of a file can be determined based on the path extension matching any of the `path_suffixes`.
#[serde(default)]
pub path_suffixes: Vec<String>,
/// A Regex pattern that determines whether the language should be assigned to a file based on the name of the file.
#[serde(
default,
serialize_with = "serialize_regex",
deserialize_with = "deserialize_regex"
)]
#[schemars(schema_with = "regex_json_schema")]
pub path_regex: Option<Regex>,
/// A regex pattern that determines whether the language should be assigned to a file or not.
#[serde(
default,
Expand Down
6 changes: 5 additions & 1 deletion crates/language/src/language_registry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -516,6 +516,10 @@ impl LanguageRegistry {
.path_suffixes
.iter()
.any(|suffix| path_suffixes.contains(&Some(suffix.as_str())));
let path_matches_regex = config
.path_regex
.as_ref()
.map_or(false, |regex| filename.map_or(false, |p| regex.is_match(p)));
let path_matches_custom_suffix = user_file_types
.and_then(|types| types.get(language_name))
.unwrap_or(&empty)
Expand All @@ -532,7 +536,7 @@ impl LanguageRegistry {
);
if path_matches_custom_suffix {
2
} else if path_matches_default_suffix || content_matches {
} else if path_matches_default_suffix || content_matches || path_matches_regex {
1
} else {
0
Expand Down