Introduce LspPostProcessor::download_language_server

This commit is contained in:
Antonio Scandurra 2022-02-21 09:46:18 +01:00
parent 1ca50d0134
commit fafe521e9f
2 changed files with 31 additions and 8 deletions

View file

@ -8,12 +8,20 @@ mod tests;
use anyhow::{anyhow, Result}; use anyhow::{anyhow, Result};
use collections::HashSet; use collections::HashSet;
use futures::future::BoxFuture;
use gpui::{AppContext, Task}; use gpui::{AppContext, Task};
use highlight_map::HighlightMap; use highlight_map::HighlightMap;
use lazy_static::lazy_static; use lazy_static::lazy_static;
use parking_lot::Mutex; use parking_lot::Mutex;
use serde::Deserialize; use serde::Deserialize;
use std::{cell::RefCell, ops::Range, path::Path, str, sync::Arc}; use std::{
cell::RefCell,
future::Future,
ops::Range,
path::{Path, PathBuf},
str,
sync::Arc,
};
use theme::SyntaxTheme; use theme::SyntaxTheme;
use tree_sitter::{self, Query}; use tree_sitter::{self, Query};
@ -48,6 +56,7 @@ pub trait ToLspPosition {
} }
pub trait LspPostProcessor: 'static + Send + Sync { pub trait LspPostProcessor: 'static + Send + Sync {
fn download_language_server(&self) -> BoxFuture<'static, Result<PathBuf>>;
fn process_diagnostics(&self, diagnostics: &mut lsp::PublishDiagnosticsParams); fn process_diagnostics(&self, diagnostics: &mut lsp::PublishDiagnosticsParams);
fn label_for_completion( fn label_for_completion(
&self, &self,
@ -259,13 +268,14 @@ impl Language {
} }
let background = cx.background().clone(); let background = cx.background().clone();
let server = lsp::LanguageServer::new( let server_binary_path = self
Path::new(&config.binary), .download_language_server()
&root_path, .ok_or_else(|| anyhow!("cannot download language server"));
cx.background().clone(), cx.background().spawn(async move {
) let server_binary_path = server_binary_path?.await?;
.map(Some); let server = lsp::LanguageServer::new(&server_binary_path, &root_path, background)?;
cx.background().spawn(async move { server }) Ok(Some(server))
})
} else { } else {
Task::ready(Ok(None)) Task::ready(Ok(None))
} }
@ -321,6 +331,12 @@ impl Language {
result result
} }
fn download_language_server(&self) -> Option<impl Future<Output = Result<PathBuf>>> {
self.lsp_post_processor
.as_ref()
.map(|processor| processor.download_language_server())
}
pub fn brackets(&self) -> &[BracketPair] { pub fn brackets(&self) -> &[BracketPair] {
&self.config.brackets &self.config.brackets
} }

View file

@ -1,8 +1,11 @@
use anyhow::Result;
use futures::future::BoxFuture;
pub use language::*; pub use language::*;
use lazy_static::lazy_static; use lazy_static::lazy_static;
use regex::Regex; use regex::Regex;
use rust_embed::RustEmbed; use rust_embed::RustEmbed;
use std::borrow::Cow; use std::borrow::Cow;
use std::path::PathBuf;
use std::{str, sync::Arc}; use std::{str, sync::Arc};
#[derive(RustEmbed)] #[derive(RustEmbed)]
@ -12,6 +15,10 @@ struct LanguageDir;
struct RustPostProcessor; struct RustPostProcessor;
impl LspPostProcessor for RustPostProcessor { impl LspPostProcessor for RustPostProcessor {
fn download_language_server(&self) -> BoxFuture<'static, Result<PathBuf>> {
todo!()
}
fn process_diagnostics(&self, params: &mut lsp::PublishDiagnosticsParams) { fn process_diagnostics(&self, params: &mut lsp::PublishDiagnosticsParams) {
lazy_static! { lazy_static! {
static ref REGEX: Regex = Regex::new("(?m)`([^`]+)\n`$").unwrap(); static ref REGEX: Regex = Regex::new("(?m)`([^`]+)\n`$").unwrap();