LSP feature gates

This commit is contained in:
Blaž Hrastnik 2022-04-05 16:05:57 +09:00
parent 842a5fc979
commit afcb78a538
No known key found for this signature in database
GPG Key ID: 1238B9C4AD889640
2 changed files with 40 additions and 25 deletions

View File

@ -205,23 +205,31 @@ fn write_impl(
if doc.path().is_none() { if doc.path().is_none() {
bail!("cannot write a buffer without a filename"); bail!("cannot write a buffer without a filename");
} }
let fmt = doc.auto_format().map(|fmt| {
let shared = fmt.shared(); #[cfg(feature = "lsp")]
let callback = make_format_callback( let future = {
doc.id(), let fmt = doc.auto_format().map(|fmt| {
doc.version(), let shared = fmt.shared();
Modified::SetUnmodified, let callback = make_format_callback(
shared.clone(), doc.id(),
); doc.version(),
jobs.callback(callback); Modified::SetUnmodified,
shared shared.clone(),
}); );
let future = doc.format_and_save(fmt, force); jobs.callback(callback);
shared
});
doc.format_and_save(fmt, force)
};
#[cfg(not(feature = "lsp"))]
let future = doc.save(force);
cx.jobs.add(Job::new(future).wait_before_exiting()); cx.jobs.add(Job::new(future).wait_before_exiting());
if path.is_some() { if path.is_some() {
let id = doc.id(); let id = doc.id();
doc.detect_language(cx.editor.syn_loader.clone()); doc.detect_language(cx.editor.syn_loader.clone());
#[cfg(feature = "lsp")]
let _ = cx.editor.refresh_language_server(id); let _ = cx.editor.refresh_language_server(id);
} }
Ok(()) Ok(())
@ -259,6 +267,7 @@ fn format(
_event: PromptEvent, _event: PromptEvent,
) -> anyhow::Result<()> { ) -> anyhow::Result<()> {
let doc = doc!(cx.editor); let doc = doc!(cx.editor);
#[cfg(feature = "lsp")]
if let Some(format) = doc.format() { if let Some(format) = doc.format() {
let callback = let callback =
make_format_callback(doc.id(), doc.version(), Modified::LeaveModified, format); make_format_callback(doc.id(), doc.version(), Modified::LeaveModified, format);
@ -466,18 +475,24 @@ fn write_all_impl(
continue; continue;
} }
let fmt = doc.auto_format().map(|fmt| { #[cfg(feature = "lsp")]
let shared = fmt.shared(); let future = {
let callback = make_format_callback( let fmt = doc.auto_format().map(|fmt| {
doc.id(), let shared = fmt.shared();
doc.version(), let callback = make_format_callback(
Modified::SetUnmodified, doc.id(),
shared.clone(), doc.version(),
); Modified::SetUnmodified,
jobs.callback(callback); shared.clone(),
shared );
}); jobs.callback(callback);
let future = doc.format_and_save(fmt, force); shared
});
doc.format_and_save(fmt, force)
};
#[cfg(not(feature = "lsp"))]
let future = doc.save(force);
jobs.add(Job::new(future).wait_before_exiting()); jobs.add(Job::new(future).wait_before_exiting());
} }
@ -1000,6 +1015,7 @@ fn language(
doc.set_language_by_language_id(&args[0], cx.editor.syn_loader.clone()); doc.set_language_by_language_id(&args[0], cx.editor.syn_loader.clone());
let id = doc.id(); let id = doc.id();
#[cfg(feature = "lsp")]
cx.editor.refresh_language_server(id); cx.editor.refresh_language_server(id);
Ok(()) Ok(())
} }

View File

@ -624,7 +624,6 @@ pub fn set_language2(&mut self, scope: &str, config_loader: Arc<syntax::Loader>)
self.set_language(language_config, Some(config_loader)); self.set_language(language_config, Some(config_loader));
} }
#[cfg(feature = "lsp")]
/// Set the programming language for the file if you know the language but don't have the /// Set the programming language for the file if you know the language but don't have the
/// [`syntax::LanguageConfiguration`] for it. /// [`syntax::LanguageConfiguration`] for it.
pub fn set_language_by_language_id( pub fn set_language_by_language_id(