Make Buffer::language_at fall back to Buffer::language
For languages with no grammar (plain text), there will be no layers.
This commit is contained in:
parent
2da32af340
commit
4f44375abd
3 changed files with 12 additions and 0 deletions
|
@ -648,6 +648,7 @@ impl Buffer {
|
||||||
.layers_for_range(offset..offset, &self.text)
|
.layers_for_range(offset..offset, &self.text)
|
||||||
.last()
|
.last()
|
||||||
.map(|info| info.language.clone())
|
.map(|info| info.language.clone())
|
||||||
|
.or_else(|| self.language.clone())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn parse_count(&self) -> usize {
|
pub fn parse_count(&self) -> usize {
|
||||||
|
@ -1841,6 +1842,7 @@ impl BufferSnapshot {
|
||||||
.layers_for_range(offset..offset, &self.text)
|
.layers_for_range(offset..offset, &self.text)
|
||||||
.last()
|
.last()
|
||||||
.map(|info| info.language)
|
.map(|info| info.language)
|
||||||
|
.or(self.language.as_ref())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn surrounding_word<T: ToOffset>(&self, start: T) -> (Range<usize>, Option<CharKind>) {
|
pub fn surrounding_word<T: ToOffset>(&self, start: T) -> (Range<usize>, Option<CharKind>) {
|
||||||
|
|
|
@ -26,6 +26,7 @@ use serde_json::Value;
|
||||||
use std::{
|
use std::{
|
||||||
any::Any,
|
any::Any,
|
||||||
cell::RefCell,
|
cell::RefCell,
|
||||||
|
fmt::Debug,
|
||||||
mem,
|
mem,
|
||||||
ops::Range,
|
ops::Range,
|
||||||
path::{Path, PathBuf},
|
path::{Path, PathBuf},
|
||||||
|
@ -866,6 +867,14 @@ impl Language {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl Debug for Language {
|
||||||
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||||
|
f.debug_struct("Language")
|
||||||
|
.field("name", &self.config.name)
|
||||||
|
.finish()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl Grammar {
|
impl Grammar {
|
||||||
pub fn id(&self) -> usize {
|
pub fn id(&self) -> usize {
|
||||||
self.id
|
self.id
|
||||||
|
|
|
@ -92,6 +92,7 @@ struct SyntaxLayer {
|
||||||
language: Arc<Language>,
|
language: Arc<Language>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
pub struct SyntaxLayerInfo<'a> {
|
pub struct SyntaxLayerInfo<'a> {
|
||||||
pub depth: usize,
|
pub depth: usize,
|
||||||
pub node: Node<'a>,
|
pub node: Node<'a>,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue