More work on transitioning to async, need to figure out when to stop
This commit is contained in:
parent
feb6cf6789
commit
f4b4212932
8 changed files with 109 additions and 113 deletions
|
@ -66,15 +66,11 @@ impl PluginBuilder {
|
||||||
/// Create a new [`PluginBuilder`] with the given WASI context.
|
/// Create a new [`PluginBuilder`] with the given WASI context.
|
||||||
/// Using the default context is a safe bet, see [`new_with_default_context`].
|
/// Using the default context is a safe bet, see [`new_with_default_context`].
|
||||||
pub fn new(wasi_ctx: WasiCtx) -> Result<Self, Error> {
|
pub fn new(wasi_ctx: WasiCtx) -> Result<Self, Error> {
|
||||||
dbg!("new plugin");
|
|
||||||
let mut config = Config::default();
|
let mut config = Config::default();
|
||||||
config.async_support(true);
|
config.async_support(true);
|
||||||
dbg!("Creating engine");
|
config.epoch_interruption(true);
|
||||||
let start = std::time::Instant::now();
|
|
||||||
let engine = Engine::new(&config)?;
|
let engine = Engine::new(&config)?;
|
||||||
dbg!(start.elapsed());
|
|
||||||
let linker = Linker::new(&engine);
|
let linker = Linker::new(&engine);
|
||||||
dbg!(start.elapsed());
|
|
||||||
|
|
||||||
Ok(PluginBuilder {
|
Ok(PluginBuilder {
|
||||||
// host_functions: HashMap::new(),
|
// host_functions: HashMap::new(),
|
||||||
|
@ -317,6 +313,7 @@ impl Plugin {
|
||||||
alloc: None,
|
alloc: None,
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
// store.epoch_deadline_async_yield_and_update(todo!());
|
||||||
let module = Module::new(&engine, module)?;
|
let module = Module::new(&engine, module)?;
|
||||||
|
|
||||||
// load the provided module into the asynchronous runtime
|
// load the provided module into the asynchronous runtime
|
||||||
|
|
|
@ -31,8 +31,8 @@ use language::{
|
||||||
Transaction,
|
Transaction,
|
||||||
};
|
};
|
||||||
use lsp::{
|
use lsp::{
|
||||||
DiagnosticSeverity, DiagnosticTag, DocumentHighlightKind, LanguageServer, LanguageString,
|
CompletionList, DiagnosticSeverity, DiagnosticTag, DocumentHighlightKind, LanguageServer,
|
||||||
MarkedString,
|
LanguageString, MarkedString,
|
||||||
};
|
};
|
||||||
use lsp_command::*;
|
use lsp_command::*;
|
||||||
use parking_lot::Mutex;
|
use parking_lot::Mutex;
|
||||||
|
@ -708,7 +708,7 @@ impl Project {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn on_settings_changed(&mut self, cx: &mut ModelContext<'_, Self>) {
|
fn on_settings_changed(&mut self, cx: &mut ModelContext<'_, Self>) {
|
||||||
let settings = cx.global::<Settings>();
|
let settings = cx.global::<Settings>();
|
||||||
|
|
||||||
let mut language_servers_to_start = Vec::new();
|
let mut language_servers_to_start = Vec::new();
|
||||||
|
@ -3302,15 +3302,15 @@ impl Project {
|
||||||
path = relativize_path(&worktree_abs_path, &abs_path);
|
path = relativize_path(&worktree_abs_path, &abs_path);
|
||||||
}
|
}
|
||||||
|
|
||||||
let label = this
|
let label = match this.languages.select_language(&path) {
|
||||||
.languages
|
Some(language) => {
|
||||||
.select_language(&path)
|
|
||||||
.and_then(|language| {
|
|
||||||
language
|
language
|
||||||
.label_for_symbol(&lsp_symbol.name, lsp_symbol.kind)
|
.label_for_symbol(&lsp_symbol.name, lsp_symbol.kind)
|
||||||
.await
|
.await
|
||||||
})
|
}
|
||||||
.unwrap_or_else(|| CodeLabel::plain(lsp_symbol.name.clone(), None));
|
None => None,
|
||||||
|
}
|
||||||
|
.unwrap_or_else(|| CodeLabel::plain(lsp_symbol.name.clone(), None));
|
||||||
let signature = this.symbol_signature(worktree_id, &path);
|
let signature = this.symbol_signature(worktree_id, &path);
|
||||||
|
|
||||||
Some(Symbol {
|
Some(Symbol {
|
||||||
|
@ -3550,15 +3550,18 @@ impl Project {
|
||||||
Some(Completion {
|
Some(Completion {
|
||||||
old_range,
|
old_range,
|
||||||
new_text,
|
new_text,
|
||||||
label: language
|
label: {
|
||||||
.as_ref()
|
match language.as_ref() {
|
||||||
.and_then(|l| l.label_for_completion(&lsp_completion).await)
|
Some(l) => l.label_for_completion(&lsp_completion).await,
|
||||||
|
None => None,
|
||||||
|
}
|
||||||
.unwrap_or_else(|| {
|
.unwrap_or_else(|| {
|
||||||
CodeLabel::plain(
|
CodeLabel::plain(
|
||||||
lsp_completion.label.clone(),
|
lsp_completion.label.clone(),
|
||||||
lsp_completion.filter_text.as_deref(),
|
lsp_completion.filter_text.as_deref(),
|
||||||
)
|
)
|
||||||
}),
|
})
|
||||||
|
},
|
||||||
lsp_completion,
|
lsp_completion,
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
@ -3582,13 +3585,14 @@ impl Project {
|
||||||
})
|
})
|
||||||
.await;
|
.await;
|
||||||
|
|
||||||
response
|
let completions = Vec::new();
|
||||||
.completions
|
for completion in response.completions.into_iter() {
|
||||||
.into_iter()
|
completions.push(
|
||||||
.map(|completion| {
|
language::proto::deserialize_completion(completion, language.as_ref())
|
||||||
language::proto::deserialize_completion(completion, language.as_ref()).await
|
.await,
|
||||||
})
|
);
|
||||||
.collect()
|
}
|
||||||
|
completions.into_iter().collect()
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
Task::ready(Ok(Default::default()))
|
Task::ready(Ok(Default::default()))
|
||||||
|
@ -5189,7 +5193,7 @@ impl Project {
|
||||||
_: Arc<Client>,
|
_: Arc<Client>,
|
||||||
mut cx: AsyncAppContext,
|
mut cx: AsyncAppContext,
|
||||||
) -> Result<proto::ApplyCompletionAdditionalEditsResponse> {
|
) -> Result<proto::ApplyCompletionAdditionalEditsResponse> {
|
||||||
let apply_additional_edits = this.update(&mut cx, |this, cx| {
|
let (buffer, completion) = this.update(&mut cx, |this, cx| {
|
||||||
let buffer = this
|
let buffer = this
|
||||||
.opened_buffers
|
.opened_buffers
|
||||||
.get(&envelope.payload.buffer_id)
|
.get(&envelope.payload.buffer_id)
|
||||||
|
@ -5202,13 +5206,16 @@ impl Project {
|
||||||
.completion
|
.completion
|
||||||
.ok_or_else(|| anyhow!("invalid completion"))?,
|
.ok_or_else(|| anyhow!("invalid completion"))?,
|
||||||
language,
|
language,
|
||||||
)
|
);
|
||||||
.await?;
|
Ok::<_, anyhow::Error>((buffer, completion))
|
||||||
Ok::<_, anyhow::Error>(
|
|
||||||
this.apply_additional_edits_for_completion(buffer, completion, false, cx),
|
|
||||||
)
|
|
||||||
})?;
|
})?;
|
||||||
|
|
||||||
|
let completion = completion.await?;
|
||||||
|
|
||||||
|
let apply_additional_edits = this.update(&mut cx, |this, cx| {
|
||||||
|
this.apply_additional_edits_for_completion(buffer, completion, false, cx)
|
||||||
|
});
|
||||||
|
|
||||||
Ok(proto::ApplyCompletionAdditionalEditsResponse {
|
Ok(proto::ApplyCompletionAdditionalEditsResponse {
|
||||||
transaction: apply_additional_edits
|
transaction: apply_additional_edits
|
||||||
.await?
|
.await?
|
||||||
|
@ -5390,8 +5397,10 @@ impl Project {
|
||||||
.payload
|
.payload
|
||||||
.symbol
|
.symbol
|
||||||
.ok_or_else(|| anyhow!("invalid symbol"))?;
|
.ok_or_else(|| anyhow!("invalid symbol"))?;
|
||||||
|
let symbol = this
|
||||||
|
.read_with(&cx, |this, _| this.deserialize_symbol(symbol))
|
||||||
|
.await?;
|
||||||
let symbol = this.read_with(&cx, |this, _| {
|
let symbol = this.read_with(&cx, |this, _| {
|
||||||
let symbol = this.deserialize_symbol(symbol).await?;
|
|
||||||
let signature = this.symbol_signature(symbol.worktree_id, &symbol.path);
|
let signature = this.symbol_signature(symbol.worktree_id, &symbol.path);
|
||||||
if signature == symbol.signature {
|
if signature == symbol.signature {
|
||||||
Ok(symbol)
|
Ok(symbol)
|
||||||
|
|
|
@ -13,15 +13,16 @@ use util::{ResultExt, TryFutureExt};
|
||||||
|
|
||||||
pub struct CLspAdapter;
|
pub struct CLspAdapter;
|
||||||
|
|
||||||
|
#[async_trait]
|
||||||
impl super::LspAdapter for CLspAdapter {
|
impl super::LspAdapter for CLspAdapter {
|
||||||
fn name(&self) -> LanguageServerName {
|
async fn name(&self) -> LanguageServerName {
|
||||||
LanguageServerName("clangd".into())
|
LanguageServerName("clangd".into())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn fetch_latest_server_version(
|
async fn fetch_latest_server_version(
|
||||||
&self,
|
&self,
|
||||||
http: Arc<dyn HttpClient>,
|
http: Arc<dyn HttpClient>,
|
||||||
) -> BoxFuture<'static, Result<Box<dyn 'static + Send + Any>>> {
|
) -> Result<Box<dyn 'static + Send + Any>> {
|
||||||
async move {
|
async move {
|
||||||
let release = latest_github_release("clangd/clangd", http).await?;
|
let release = latest_github_release("clangd/clangd", http).await?;
|
||||||
let asset_name = format!("clangd-mac-{}.zip", release.name);
|
let asset_name = format!("clangd-mac-{}.zip", release.name);
|
||||||
|
@ -39,12 +40,12 @@ impl super::LspAdapter for CLspAdapter {
|
||||||
.boxed()
|
.boxed()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn fetch_server_binary(
|
async fn fetch_server_binary(
|
||||||
&self,
|
&self,
|
||||||
version: Box<dyn 'static + Send + Any>,
|
version: Box<dyn 'static + Send + Any>,
|
||||||
http: Arc<dyn HttpClient>,
|
http: Arc<dyn HttpClient>,
|
||||||
container_dir: Arc<Path>,
|
container_dir: PathBuf,
|
||||||
) -> BoxFuture<'static, Result<PathBuf>> {
|
) -> Result<PathBuf> {
|
||||||
let version = version.downcast::<GitHubLspBinaryVersion>().unwrap();
|
let version = version.downcast::<GitHubLspBinaryVersion>().unwrap();
|
||||||
async move {
|
async move {
|
||||||
let zip_path = container_dir.join(format!("clangd_{}.zip", version.name));
|
let zip_path = container_dir.join(format!("clangd_{}.zip", version.name));
|
||||||
|
@ -92,10 +93,7 @@ impl super::LspAdapter for CLspAdapter {
|
||||||
.boxed()
|
.boxed()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn cached_server_binary(
|
async fn cached_server_binary(&self, container_dir: PathBuf) -> Option<PathBuf> {
|
||||||
&self,
|
|
||||||
container_dir: Arc<Path>,
|
|
||||||
) -> BoxFuture<'static, Option<PathBuf>> {
|
|
||||||
async move {
|
async move {
|
||||||
let mut last_clangd_dir = None;
|
let mut last_clangd_dir = None;
|
||||||
let mut entries = fs::read_dir(&container_dir).await?;
|
let mut entries = fs::read_dir(&container_dir).await?;
|
||||||
|
@ -120,7 +118,7 @@ impl super::LspAdapter for CLspAdapter {
|
||||||
.boxed()
|
.boxed()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn label_for_completion(
|
async fn label_for_completion(
|
||||||
&self,
|
&self,
|
||||||
completion: &lsp::CompletionItem,
|
completion: &lsp::CompletionItem,
|
||||||
language: &Language,
|
language: &Language,
|
||||||
|
@ -197,7 +195,7 @@ impl super::LspAdapter for CLspAdapter {
|
||||||
Some(CodeLabel::plain(label.to_string(), None))
|
Some(CodeLabel::plain(label.to_string(), None))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn label_for_symbol(
|
async fn label_for_symbol(
|
||||||
&self,
|
&self,
|
||||||
name: &str,
|
name: &str,
|
||||||
kind: lsp::SymbolKind,
|
kind: lsp::SymbolKind,
|
||||||
|
|
|
@ -22,19 +22,20 @@ lazy_static! {
|
||||||
static ref GOPLS_VERSION_REGEX: Regex = Regex::new(r"\d+\.\d+\.\d+").unwrap();
|
static ref GOPLS_VERSION_REGEX: Regex = Regex::new(r"\d+\.\d+\.\d+").unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[async_trait]
|
||||||
impl super::LspAdapter for GoLspAdapter {
|
impl super::LspAdapter for GoLspAdapter {
|
||||||
fn name(&self) -> LanguageServerName {
|
async fn name(&self) -> LanguageServerName {
|
||||||
LanguageServerName("gopls".into())
|
LanguageServerName("gopls".into())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn server_args(&self) -> &[&str] {
|
async fn server_args(&self) -> Vec<String> {
|
||||||
&["-mode=stdio"]
|
vec!["-mode=stdio".into()]
|
||||||
}
|
}
|
||||||
|
|
||||||
fn fetch_latest_server_version(
|
async fn fetch_latest_server_version(
|
||||||
&self,
|
&self,
|
||||||
http: Arc<dyn HttpClient>,
|
http: Arc<dyn HttpClient>,
|
||||||
) -> BoxFuture<'static, Result<Box<dyn 'static + Send + Any>>> {
|
) -> Result<Box<dyn 'static + Send + Any>> {
|
||||||
async move {
|
async move {
|
||||||
let release = latest_github_release("golang/tools", http).await?;
|
let release = latest_github_release("golang/tools", http).await?;
|
||||||
let version: Option<String> = release.name.strip_prefix("gopls/v").map(str::to_string);
|
let version: Option<String> = release.name.strip_prefix("gopls/v").map(str::to_string);
|
||||||
|
@ -49,12 +50,12 @@ impl super::LspAdapter for GoLspAdapter {
|
||||||
.boxed()
|
.boxed()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn fetch_server_binary(
|
async fn fetch_server_binary(
|
||||||
&self,
|
&self,
|
||||||
version: Box<dyn 'static + Send + Any>,
|
version: Box<dyn 'static + Send + Any>,
|
||||||
_: Arc<dyn HttpClient>,
|
_: Arc<dyn HttpClient>,
|
||||||
container_dir: Arc<Path>,
|
container_dir: PathBuf,
|
||||||
) -> BoxFuture<'static, Result<PathBuf>> {
|
) -> Result<PathBuf> {
|
||||||
let version = version.downcast::<Option<String>>().unwrap();
|
let version = version.downcast::<Option<String>>().unwrap();
|
||||||
let this = *self;
|
let this = *self;
|
||||||
|
|
||||||
|
@ -115,10 +116,7 @@ impl super::LspAdapter for GoLspAdapter {
|
||||||
.boxed()
|
.boxed()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn cached_server_binary(
|
async fn cached_server_binary(&self, container_dir: PathBuf) -> Option<PathBuf> {
|
||||||
&self,
|
|
||||||
container_dir: Arc<Path>,
|
|
||||||
) -> BoxFuture<'static, Option<PathBuf>> {
|
|
||||||
async move {
|
async move {
|
||||||
let mut last_binary_path = None;
|
let mut last_binary_path = None;
|
||||||
let mut entries = fs::read_dir(&container_dir).await?;
|
let mut entries = fs::read_dir(&container_dir).await?;
|
||||||
|
@ -144,7 +142,7 @@ impl super::LspAdapter for GoLspAdapter {
|
||||||
.boxed()
|
.boxed()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn label_for_completion(
|
async fn label_for_completion(
|
||||||
&self,
|
&self,
|
||||||
completion: &lsp::CompletionItem,
|
completion: &lsp::CompletionItem,
|
||||||
language: &Language,
|
language: &Language,
|
||||||
|
@ -244,7 +242,7 @@ impl super::LspAdapter for GoLspAdapter {
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
|
|
||||||
fn label_for_symbol(
|
async fn label_for_symbol(
|
||||||
&self,
|
&self,
|
||||||
name: &str,
|
name: &str,
|
||||||
kind: lsp::SymbolKind,
|
kind: lsp::SymbolKind,
|
||||||
|
|
|
@ -19,31 +19,32 @@ impl JsonLspAdapter {
|
||||||
"node_modules/vscode-json-languageserver/bin/vscode-json-languageserver";
|
"node_modules/vscode-json-languageserver/bin/vscode-json-languageserver";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[async_trait]
|
||||||
impl LspAdapter for JsonLspAdapter {
|
impl LspAdapter for JsonLspAdapter {
|
||||||
fn name(&self) -> LanguageServerName {
|
async fn name(&self) -> LanguageServerName {
|
||||||
LanguageServerName("vscode-json-languageserver".into())
|
LanguageServerName("vscode-json-languageserver".into())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn server_args(&self) -> Vec<String> {
|
async fn server_args(&self) -> Vec<String> {
|
||||||
vec!["--stdio".into()]
|
vec!["--stdio".into()]
|
||||||
}
|
}
|
||||||
|
|
||||||
fn fetch_latest_server_version(
|
async fn fetch_latest_server_version(
|
||||||
&self,
|
&self,
|
||||||
_: Arc<dyn HttpClient>,
|
_: Arc<dyn HttpClient>,
|
||||||
) -> BoxFuture<'static, Result<Box<dyn 'static + Any + Send>>> {
|
) -> Result<Box<dyn 'static + Any + Send>> {
|
||||||
async move {
|
async move {
|
||||||
Ok(Box::new(npm_package_latest_version("vscode-json-languageserver").await?) as Box<_>)
|
Ok(Box::new(npm_package_latest_version("vscode-json-languageserver").await?) as Box<_>)
|
||||||
}
|
}
|
||||||
.boxed()
|
.boxed()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn fetch_server_binary(
|
async fn fetch_server_binary(
|
||||||
&self,
|
&self,
|
||||||
version: Box<dyn 'static + Send + Any>,
|
version: Box<dyn 'static + Send + Any>,
|
||||||
_: Arc<dyn HttpClient>,
|
_: Arc<dyn HttpClient>,
|
||||||
container_dir: Arc<Path>,
|
container_dir: PathBuf,
|
||||||
) -> BoxFuture<'static, Result<PathBuf>> {
|
) -> Result<PathBuf> {
|
||||||
let version = version.downcast::<String>().unwrap();
|
let version = version.downcast::<String>().unwrap();
|
||||||
async move {
|
async move {
|
||||||
let version_dir = container_dir.join(version.as_str());
|
let version_dir = container_dir.join(version.as_str());
|
||||||
|
@ -76,10 +77,7 @@ impl LspAdapter for JsonLspAdapter {
|
||||||
.boxed()
|
.boxed()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn cached_server_binary(
|
async fn cached_server_binary(&self, container_dir: PathBuf) -> Option<PathBuf> {
|
||||||
&self,
|
|
||||||
container_dir: Arc<Path>,
|
|
||||||
) -> BoxFuture<'static, Option<PathBuf>> {
|
|
||||||
async move {
|
async move {
|
||||||
let mut last_version_dir = None;
|
let mut last_version_dir = None;
|
||||||
let mut entries = fs::read_dir(&container_dir).await?;
|
let mut entries = fs::read_dir(&container_dir).await?;
|
||||||
|
@ -104,13 +102,13 @@ impl LspAdapter for JsonLspAdapter {
|
||||||
.boxed()
|
.boxed()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn initialization_options(&self) -> Option<serde_json::Value> {
|
async fn initialization_options(&self) -> Option<serde_json::Value> {
|
||||||
Some(json!({
|
Some(json!({
|
||||||
"provideFormatter": true
|
"provideFormatter": true
|
||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn id_for_language(&self, name: &str) -> Option<String> {
|
async fn id_for_language(&self, name: &str) -> Option<String> {
|
||||||
if name == "JSON" {
|
if name == "JSON" {
|
||||||
Some("jsonc".into())
|
Some("jsonc".into())
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -17,28 +17,29 @@ impl PythonLspAdapter {
|
||||||
const BIN_PATH: &'static str = "node_modules/pyright/langserver.index.js";
|
const BIN_PATH: &'static str = "node_modules/pyright/langserver.index.js";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[async_trait]
|
||||||
impl LspAdapter for PythonLspAdapter {
|
impl LspAdapter for PythonLspAdapter {
|
||||||
fn name(&self) -> LanguageServerName {
|
async fn name(&self) -> LanguageServerName {
|
||||||
LanguageServerName("pyright".into())
|
LanguageServerName("pyright".into())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn server_args(&self) -> &[&str] {
|
async fn server_args(&self) -> Vec<String> {
|
||||||
&["--stdio"]
|
vec!["--stdio".into()]
|
||||||
}
|
}
|
||||||
|
|
||||||
fn fetch_latest_server_version(
|
async fn fetch_latest_server_version(
|
||||||
&self,
|
&self,
|
||||||
_: Arc<dyn HttpClient>,
|
_: Arc<dyn HttpClient>,
|
||||||
) -> BoxFuture<'static, Result<Box<dyn 'static + Any + Send>>> {
|
) -> Result<Box<dyn 'static + Any + Send>> {
|
||||||
async move { Ok(Box::new(npm_package_latest_version("pyright").await?) as Box<_>) }.boxed()
|
async move { Ok(Box::new(npm_package_latest_version("pyright").await?) as Box<_>) }.boxed()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn fetch_server_binary(
|
async fn fetch_server_binary(
|
||||||
&self,
|
&self,
|
||||||
version: Box<dyn 'static + Send + Any>,
|
version: Box<dyn 'static + Send + Any>,
|
||||||
_: Arc<dyn HttpClient>,
|
_: Arc<dyn HttpClient>,
|
||||||
container_dir: Arc<Path>,
|
container_dir: PathBuf,
|
||||||
) -> BoxFuture<'static, Result<PathBuf>> {
|
) -> Result<PathBuf> {
|
||||||
let version = version.downcast::<String>().unwrap();
|
let version = version.downcast::<String>().unwrap();
|
||||||
async move {
|
async move {
|
||||||
let version_dir = container_dir.join(version.as_str());
|
let version_dir = container_dir.join(version.as_str());
|
||||||
|
@ -67,10 +68,7 @@ impl LspAdapter for PythonLspAdapter {
|
||||||
.boxed()
|
.boxed()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn cached_server_binary(
|
async fn cached_server_binary(&self, container_dir: PathBuf) -> Option<PathBuf> {
|
||||||
&self,
|
|
||||||
container_dir: Arc<Path>,
|
|
||||||
) -> BoxFuture<'static, Option<PathBuf>> {
|
|
||||||
async move {
|
async move {
|
||||||
let mut last_version_dir = None;
|
let mut last_version_dir = None;
|
||||||
let mut entries = fs::read_dir(&container_dir).await?;
|
let mut entries = fs::read_dir(&container_dir).await?;
|
||||||
|
@ -95,7 +93,7 @@ impl LspAdapter for PythonLspAdapter {
|
||||||
.boxed()
|
.boxed()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn label_for_completion(
|
async fn label_for_completion(
|
||||||
&self,
|
&self,
|
||||||
item: &lsp::CompletionItem,
|
item: &lsp::CompletionItem,
|
||||||
language: &language::Language,
|
language: &language::Language,
|
||||||
|
@ -116,7 +114,7 @@ impl LspAdapter for PythonLspAdapter {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
fn label_for_symbol(
|
async fn label_for_symbol(
|
||||||
&self,
|
&self,
|
||||||
name: &str,
|
name: &str,
|
||||||
kind: lsp::SymbolKind,
|
kind: lsp::SymbolKind,
|
||||||
|
|
|
@ -20,14 +20,14 @@ use util::{ResultExt, TryFutureExt};
|
||||||
pub struct RustLspAdapter;
|
pub struct RustLspAdapter;
|
||||||
|
|
||||||
impl LspAdapter for RustLspAdapter {
|
impl LspAdapter for RustLspAdapter {
|
||||||
fn name(&self) -> LanguageServerName {
|
async fn name(&self) -> LanguageServerName {
|
||||||
LanguageServerName("rust-analyzer".into())
|
LanguageServerName("rust-analyzer".into())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn fetch_latest_server_version(
|
async fn fetch_latest_server_version(
|
||||||
&self,
|
&self,
|
||||||
http: Arc<dyn HttpClient>,
|
http: Arc<dyn HttpClient>,
|
||||||
) -> BoxFuture<'static, Result<Box<dyn 'static + Send + Any>>> {
|
) -> Result<Box<dyn 'static + Send + Any>> {
|
||||||
async move {
|
async move {
|
||||||
let release = latest_github_release("rust-analyzer/rust-analyzer", http).await?;
|
let release = latest_github_release("rust-analyzer/rust-analyzer", http).await?;
|
||||||
let asset_name = format!("rust-analyzer-{}-apple-darwin.gz", consts::ARCH);
|
let asset_name = format!("rust-analyzer-{}-apple-darwin.gz", consts::ARCH);
|
||||||
|
@ -45,12 +45,12 @@ impl LspAdapter for RustLspAdapter {
|
||||||
.boxed()
|
.boxed()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn fetch_server_binary(
|
async fn fetch_server_binary(
|
||||||
&self,
|
&self,
|
||||||
version: Box<dyn 'static + Send + Any>,
|
version: Box<dyn 'static + Send + Any>,
|
||||||
http: Arc<dyn HttpClient>,
|
http: Arc<dyn HttpClient>,
|
||||||
container_dir: Arc<Path>,
|
container_dir: PathBuf,
|
||||||
) -> BoxFuture<'static, Result<PathBuf>> {
|
) -> Result<PathBuf> {
|
||||||
async move {
|
async move {
|
||||||
let version = version.downcast::<GitHubLspBinaryVersion>().unwrap();
|
let version = version.downcast::<GitHubLspBinaryVersion>().unwrap();
|
||||||
let destination_path = container_dir.join(format!("rust-analyzer-{}", version.name));
|
let destination_path = container_dir.join(format!("rust-analyzer-{}", version.name));
|
||||||
|
@ -86,9 +86,9 @@ impl LspAdapter for RustLspAdapter {
|
||||||
.boxed()
|
.boxed()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn cached_server_binary(
|
async fn cached_server_binary(
|
||||||
&self,
|
&self,
|
||||||
container_dir: Arc<Path>,
|
container_dir: PathBuf,
|
||||||
) -> BoxFuture<'static, Option<PathBuf>> {
|
) -> BoxFuture<'static, Option<PathBuf>> {
|
||||||
async move {
|
async move {
|
||||||
let mut last = None;
|
let mut last = None;
|
||||||
|
@ -102,15 +102,15 @@ impl LspAdapter for RustLspAdapter {
|
||||||
.boxed()
|
.boxed()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn disk_based_diagnostic_sources(&self) -> &'static [&'static str] {
|
async fn disk_based_diagnostic_sources(&self) -> Vec<String> {
|
||||||
&["rustc"]
|
vec!["rustc".into()]
|
||||||
}
|
}
|
||||||
|
|
||||||
fn disk_based_diagnostics_progress_token(&self) -> Option<&'static str> {
|
async fn disk_based_diagnostics_progress_token(&self) -> Option<String> {
|
||||||
Some("rustAnalyzer/cargo check")
|
Some("rustAnalyzer/cargo check".into())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn process_diagnostics(&self, params: &mut lsp::PublishDiagnosticsParams) {
|
async 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();
|
||||||
}
|
}
|
||||||
|
@ -130,7 +130,7 @@ impl LspAdapter for RustLspAdapter {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn label_for_completion(
|
async fn label_for_completion(
|
||||||
&self,
|
&self,
|
||||||
completion: &lsp::CompletionItem,
|
completion: &lsp::CompletionItem,
|
||||||
language: &Language,
|
language: &Language,
|
||||||
|
@ -206,7 +206,7 @@ impl LspAdapter for RustLspAdapter {
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
|
|
||||||
fn label_for_symbol(
|
async fn label_for_symbol(
|
||||||
&self,
|
&self,
|
||||||
name: &str,
|
name: &str,
|
||||||
kind: lsp::SymbolKind,
|
kind: lsp::SymbolKind,
|
||||||
|
|
|
@ -23,22 +23,23 @@ struct Versions {
|
||||||
server_version: String,
|
server_version: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[async_trait]
|
||||||
impl LspAdapter for TypeScriptLspAdapter {
|
impl LspAdapter for TypeScriptLspAdapter {
|
||||||
fn name(&self) -> LanguageServerName {
|
async fn name(&self) -> LanguageServerName {
|
||||||
LanguageServerName("typescript-language-server".into())
|
LanguageServerName("typescript-language-server".into())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn server_args(&self) -> Vec<String> {
|
async fn server_args(&self) -> Vec<String> {
|
||||||
["--stdio", "--tsserver-path", "node_modules/typescript/lib"]
|
["--stdio", "--tsserver-path", "node_modules/typescript/lib"]
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.map(str::to_string)
|
.map(str::to_string)
|
||||||
.collect()
|
.collect()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn fetch_latest_server_version(
|
async fn fetch_latest_server_version(
|
||||||
&self,
|
&self,
|
||||||
_: Arc<dyn HttpClient>,
|
_: Arc<dyn HttpClient>,
|
||||||
) -> BoxFuture<'static, Result<Box<dyn 'static + Send + Any>>> {
|
) -> Result<Box<dyn 'static + Send + Any>> {
|
||||||
async move {
|
async move {
|
||||||
Ok(Box::new(Versions {
|
Ok(Box::new(Versions {
|
||||||
typescript_version: npm_package_latest_version("typescript").await?,
|
typescript_version: npm_package_latest_version("typescript").await?,
|
||||||
|
@ -48,12 +49,12 @@ impl LspAdapter for TypeScriptLspAdapter {
|
||||||
.boxed()
|
.boxed()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn fetch_server_binary(
|
async fn fetch_server_binary(
|
||||||
&self,
|
&self,
|
||||||
versions: Box<dyn 'static + Send + Any>,
|
versions: Box<dyn 'static + Send + Any>,
|
||||||
_: Arc<dyn HttpClient>,
|
_: Arc<dyn HttpClient>,
|
||||||
container_dir: Arc<Path>,
|
container_dir: PathBuf,
|
||||||
) -> BoxFuture<'static, Result<PathBuf>> {
|
) -> Result<PathBuf> {
|
||||||
let versions = versions.downcast::<Versions>().unwrap();
|
let versions = versions.downcast::<Versions>().unwrap();
|
||||||
async move {
|
async move {
|
||||||
let version_dir = container_dir.join(&format!(
|
let version_dir = container_dir.join(&format!(
|
||||||
|
@ -95,10 +96,7 @@ impl LspAdapter for TypeScriptLspAdapter {
|
||||||
.boxed()
|
.boxed()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn cached_server_binary(
|
async fn cached_server_binary(&self, container_dir: PathBuf) -> Option<PathBuf> {
|
||||||
&self,
|
|
||||||
container_dir: Arc<Path>,
|
|
||||||
) -> BoxFuture<'static, Option<PathBuf>> {
|
|
||||||
async move {
|
async move {
|
||||||
let mut last_version_dir = None;
|
let mut last_version_dir = None;
|
||||||
let mut entries = fs::read_dir(&container_dir).await?;
|
let mut entries = fs::read_dir(&container_dir).await?;
|
||||||
|
@ -123,7 +121,7 @@ impl LspAdapter for TypeScriptLspAdapter {
|
||||||
.boxed()
|
.boxed()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn label_for_completion(
|
async fn label_for_completion(
|
||||||
&self,
|
&self,
|
||||||
item: &lsp::CompletionItem,
|
item: &lsp::CompletionItem,
|
||||||
language: &language::Language,
|
language: &language::Language,
|
||||||
|
@ -146,7 +144,7 @@ impl LspAdapter for TypeScriptLspAdapter {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
fn initialization_options(&self) -> Option<serde_json::Value> {
|
async fn initialization_options(&self) -> Option<serde_json::Value> {
|
||||||
Some(json!({
|
Some(json!({
|
||||||
"provideFormatter": true
|
"provideFormatter": true
|
||||||
}))
|
}))
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue