|
|
@ -19,7 +19,7 @@ use helix_core::{
|
|
|
|
};
|
|
|
|
};
|
|
|
|
use helix_lsp::util::LspFormatting;
|
|
|
|
use helix_lsp::util::LspFormatting;
|
|
|
|
|
|
|
|
|
|
|
|
use crate::{DocumentId, Theme, ViewId};
|
|
|
|
use crate::{DocumentId, ViewId};
|
|
|
|
|
|
|
|
|
|
|
|
/// 8kB of buffer space for encoding and decoding `Rope`s.
|
|
|
|
/// 8kB of buffer space for encoding and decoding `Rope`s.
|
|
|
|
const BUF_SIZE: usize = 8192;
|
|
|
|
const BUF_SIZE: usize = 8192;
|
|
|
@ -358,7 +358,6 @@ impl Document {
|
|
|
|
pub fn open(
|
|
|
|
pub fn open(
|
|
|
|
path: &Path,
|
|
|
|
path: &Path,
|
|
|
|
encoding: Option<&'static encoding::Encoding>,
|
|
|
|
encoding: Option<&'static encoding::Encoding>,
|
|
|
|
theme: Option<&Theme>,
|
|
|
|
|
|
|
|
config_loader: Option<Arc<syntax::Loader>>,
|
|
|
|
config_loader: Option<Arc<syntax::Loader>>,
|
|
|
|
) -> Result<Self, Error> {
|
|
|
|
) -> Result<Self, Error> {
|
|
|
|
// Open the file if it exists, otherwise assume it is a new file (and thus empty).
|
|
|
|
// Open the file if it exists, otherwise assume it is a new file (and thus empty).
|
|
|
@ -376,7 +375,7 @@ impl Document {
|
|
|
|
// set the path and try detecting the language
|
|
|
|
// set the path and try detecting the language
|
|
|
|
doc.set_path(Some(path))?;
|
|
|
|
doc.set_path(Some(path))?;
|
|
|
|
if let Some(loader) = config_loader {
|
|
|
|
if let Some(loader) = config_loader {
|
|
|
|
doc.detect_language(theme, loader);
|
|
|
|
doc.detect_language(loader);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
doc.detect_indent_and_line_ending();
|
|
|
|
doc.detect_indent_and_line_ending();
|
|
|
@ -498,12 +497,12 @@ impl Document {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// Detect the programming language based on the file type.
|
|
|
|
/// Detect the programming language based on the file type.
|
|
|
|
pub fn detect_language(&mut self, theme: Option<&Theme>, config_loader: Arc<syntax::Loader>) {
|
|
|
|
pub fn detect_language(&mut self, config_loader: Arc<syntax::Loader>) {
|
|
|
|
if let Some(path) = &self.path {
|
|
|
|
if let Some(path) = &self.path {
|
|
|
|
let language_config = config_loader
|
|
|
|
let language_config = config_loader
|
|
|
|
.language_config_for_file_name(path)
|
|
|
|
.language_config_for_file_name(path)
|
|
|
|
.or_else(|| config_loader.language_config_for_shebang(self.text()));
|
|
|
|
.or_else(|| config_loader.language_config_for_shebang(self.text()));
|
|
|
|
self.set_language(theme, language_config, Some(config_loader));
|
|
|
|
self.set_language(language_config, Some(config_loader));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -577,16 +576,13 @@ impl Document {
|
|
|
|
/// if it exists.
|
|
|
|
/// if it exists.
|
|
|
|
pub fn set_language(
|
|
|
|
pub fn set_language(
|
|
|
|
&mut self,
|
|
|
|
&mut self,
|
|
|
|
theme: Option<&Theme>,
|
|
|
|
|
|
|
|
language_config: Option<Arc<helix_core::syntax::LanguageConfiguration>>,
|
|
|
|
language_config: Option<Arc<helix_core::syntax::LanguageConfiguration>>,
|
|
|
|
loader: Option<Arc<helix_core::syntax::Loader>>,
|
|
|
|
loader: Option<Arc<helix_core::syntax::Loader>>,
|
|
|
|
) {
|
|
|
|
) {
|
|
|
|
if let (Some(language_config), Some(loader)) = (language_config, loader) {
|
|
|
|
if let (Some(language_config), Some(loader)) = (language_config, loader) {
|
|
|
|
let scopes = theme.map(|theme| theme.scopes()).unwrap_or(&[]);
|
|
|
|
if let Some(highlight_config) = language_config.highlight_config(&loader.scopes()) {
|
|
|
|
if let Some(highlight_config) = language_config.highlight_config(scopes) {
|
|
|
|
|
|
|
|
let syntax = Syntax::new(&self.text, highlight_config, loader);
|
|
|
|
let syntax = Syntax::new(&self.text, highlight_config, loader);
|
|
|
|
self.syntax = Some(syntax);
|
|
|
|
self.syntax = Some(syntax);
|
|
|
|
// TODO: config.configure(scopes) is now delayed, is that ok?
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
self.language = Some(language_config);
|
|
|
|
self.language = Some(language_config);
|
|
|
@ -601,12 +597,11 @@ impl Document {
|
|
|
|
pub fn set_language2(
|
|
|
|
pub fn set_language2(
|
|
|
|
&mut self,
|
|
|
|
&mut self,
|
|
|
|
scope: &str,
|
|
|
|
scope: &str,
|
|
|
|
theme: Option<&Theme>,
|
|
|
|
|
|
|
|
config_loader: Arc<syntax::Loader>,
|
|
|
|
config_loader: Arc<syntax::Loader>,
|
|
|
|
) {
|
|
|
|
) {
|
|
|
|
let language_config = config_loader.language_config_for_scope(scope);
|
|
|
|
let language_config = config_loader.language_config_for_scope(scope);
|
|
|
|
|
|
|
|
|
|
|
|
self.set_language(theme, language_config, Some(config_loader));
|
|
|
|
self.set_language(language_config, Some(config_loader));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// Set the LSP.
|
|
|
|
/// Set the LSP.
|
|
|
|