Start work on language config overrides
Co-authored-by: Julia Risley <julia@zed.dev>
This commit is contained in:
parent
86371d9f5e
commit
1851e2e77c
8 changed files with 189 additions and 23 deletions
|
@ -9,7 +9,7 @@ use crate::{
|
|||
syntax_map::{
|
||||
SyntaxMap, SyntaxMapCapture, SyntaxMapCaptures, SyntaxSnapshot, ToTreeSitterPoint,
|
||||
},
|
||||
CodeLabel, Outline,
|
||||
CodeLabel, LanguageConfigYeet, Outline,
|
||||
};
|
||||
use anyhow::{anyhow, Result};
|
||||
use clock::ReplicaId;
|
||||
|
@ -2015,6 +2015,27 @@ impl BufferSnapshot {
|
|||
.or(self.language.as_ref())
|
||||
}
|
||||
|
||||
pub fn language_config_at<D: ToOffset>(&self, position: D) -> Option<LanguageConfigYeet> {
|
||||
let offset = position.to_offset(self);
|
||||
|
||||
if let Some(layer_info) = self
|
||||
.syntax
|
||||
.layers_for_range(offset..offset, &self.text)
|
||||
.filter(|l| l.node.end_byte() > offset)
|
||||
.last()
|
||||
{
|
||||
Some(LanguageConfigYeet {
|
||||
language: layer_info.language.clone(),
|
||||
override_id: layer_info.override_id(offset, &self.text),
|
||||
})
|
||||
} else {
|
||||
self.language.clone().map(|language| LanguageConfigYeet {
|
||||
language,
|
||||
override_id: None,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
pub fn surrounding_word<T: ToOffset>(&self, start: T) -> (Range<usize>, Option<CharKind>) {
|
||||
let mut start = start.to_offset(self);
|
||||
let mut end = start;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue