Embed a plain text grammar and override settings for that too

This commit is contained in:
Antonio Scandurra 2021-11-29 18:01:51 +01:00
parent 2c17ae9aa6
commit 9d7039ed51
4 changed files with 25 additions and 1 deletions

View File

@ -518,7 +518,9 @@ impl Editor {
_: &workspace::OpenNew,
cx: &mut ViewContext<Workspace>,
) {
let buffer = cx.add_model(|cx| Buffer::new(0, "", cx));
let buffer = cx.add_model(|cx| {
Buffer::new(0, "", cx).with_language(Some(language::PLAIN_TEXT.clone()), None, cx)
});
workspace.add_item(BufferItemHandle(buffer), cx);
}

View File

@ -1,6 +1,7 @@
use crate::HighlightMap;
use anyhow::{anyhow, Result};
use gpui::{executor::Background, AppContext};
use lazy_static::lazy_static;
use lsp::LanguageServer;
use parking_lot::Mutex;
use serde::Deserialize;
@ -9,6 +10,19 @@ use theme::SyntaxTheme;
use tree_sitter::{self, Query};
pub use tree_sitter::{Parser, Tree};
lazy_static! {
pub static ref PLAIN_TEXT: Arc<Language> = Arc::new(Language::new(
LanguageConfig {
name: "Plain Text".to_string(),
path_suffixes: Default::default(),
brackets: Default::default(),
line_comment: None,
language_server: None,
},
None,
));
}
#[derive(Default, Deserialize)]
pub struct LanguageConfig {
pub name: String,

View File

@ -8,6 +8,7 @@ pub use self::{
highlight_map::{HighlightId, HighlightMap},
language::{
BracketPair, Grammar, Language, LanguageConfig, LanguageRegistry, LanguageServerConfig,
PLAIN_TEXT,
},
};
use anyhow::{anyhow, Result};

View File

@ -27,6 +27,13 @@ fn main() {
let theme = themes.get(DEFAULT_THEME_NAME).unwrap();
let settings = Settings::new("Inconsolata", &app.font_cache(), theme)
.unwrap()
.with_overrides(
language::PLAIN_TEXT.name(),
settings::Override {
soft_wrap: Some(settings::SoftWrap::PreferredLineLength),
..Default::default()
},
)
.with_overrides(
"Markdown",
settings::Override {