Attempt to assign a language when a new buffer is saved
This commit is contained in:
@@ -4,6 +4,7 @@ mod element;
|
|||||||
pub mod movement;
|
pub mod movement;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
|
language::Language,
|
||||||
settings::Settings,
|
settings::Settings,
|
||||||
theme::Theme,
|
theme::Theme,
|
||||||
time::ReplicaId,
|
time::ReplicaId,
|
||||||
@@ -449,6 +450,10 @@ impl Editor {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn language<'a>(&self, cx: &'a AppContext) -> Option<&'a Arc<Language>> {
|
||||||
|
self.buffer.read(cx).language()
|
||||||
|
}
|
||||||
|
|
||||||
pub fn set_placeholder_text(
|
pub fn set_placeholder_text(
|
||||||
&mut self,
|
&mut self,
|
||||||
placeholder_text: impl Into<Arc<str>>,
|
placeholder_text: impl Into<Arc<str>>,
|
||||||
|
|||||||
@@ -714,9 +714,16 @@ impl Buffer {
|
|||||||
path: impl Into<Arc<Path>>,
|
path: impl Into<Arc<Path>>,
|
||||||
cx: &mut ModelContext<Self>,
|
cx: &mut ModelContext<Self>,
|
||||||
) -> Task<Result<()>> {
|
) -> Task<Result<()>> {
|
||||||
|
let path = path.into();
|
||||||
let handle = cx.handle();
|
let handle = cx.handle();
|
||||||
let text = self.visible_text.clone();
|
let text = self.visible_text.clone();
|
||||||
let version = self.version.clone();
|
let version = self.version.clone();
|
||||||
|
|
||||||
|
if let Some(language) = worktree.read(cx).languages().select_language(&path).cloned() {
|
||||||
|
self.language = Some(language);
|
||||||
|
self.reparse(cx);
|
||||||
|
}
|
||||||
|
|
||||||
let save_as = worktree.update(cx, |worktree, cx| {
|
let save_as = worktree.update(cx, |worktree, cx| {
|
||||||
worktree
|
worktree
|
||||||
.as_local_mut()
|
.as_local_mut()
|
||||||
@@ -871,7 +878,11 @@ impl Buffer {
|
|||||||
cx.spawn(move |this, mut cx| async move {
|
cx.spawn(move |this, mut cx| async move {
|
||||||
let new_tree = parse_task.await;
|
let new_tree = parse_task.await;
|
||||||
this.update(&mut cx, move |this, cx| {
|
this.update(&mut cx, move |this, cx| {
|
||||||
let parse_again = this.version > parsed_version;
|
let language_changed =
|
||||||
|
this.language.as_ref().map_or(true, |curr_language| {
|
||||||
|
!Arc::ptr_eq(curr_language, &language)
|
||||||
|
});
|
||||||
|
let parse_again = this.version > parsed_version || language_changed;
|
||||||
*this.syntax_tree.lock() = Some(SyntaxTree {
|
*this.syntax_tree.lock() = Some(SyntaxTree {
|
||||||
tree: new_tree,
|
tree: new_tree,
|
||||||
dirty: false,
|
dirty: false,
|
||||||
|
|||||||
@@ -268,6 +268,13 @@ impl Worktree {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn languages(&self) -> &Arc<LanguageRegistry> {
|
||||||
|
match self {
|
||||||
|
Worktree::Local(worktree) => &worktree.languages,
|
||||||
|
Worktree::Remote(worktree) => &worktree.languages,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub fn snapshot(&self) -> Snapshot {
|
pub fn snapshot(&self) -> Snapshot {
|
||||||
match self {
|
match self {
|
||||||
Worktree::Local(worktree) => worktree.snapshot(),
|
Worktree::Local(worktree) => worktree.snapshot(),
|
||||||
|
|||||||
Reference in New Issue
Block a user