Detailed changes
@@ -66,20 +66,20 @@ pub trait ToLspPosition {
pub struct LanguageServerName(pub Arc<str>);
/// Represents a Language Server, with certain cached sync properties.
-/// Uses [`LspAdapterTrait`] under the hood, but calls all 'static' methods
+/// Uses [`LspAdapter`] under the hood, but calls all 'static' methods
/// once at startup, and caches the results.
-pub struct LspAdapter {
+pub struct CachedLspAdapter {
pub name: LanguageServerName,
pub server_args: Vec<String>,
pub initialization_options: Option<Value>,
pub disk_based_diagnostic_sources: Vec<String>,
pub disk_based_diagnostics_progress_token: Option<String>,
pub id_for_language: Option<String>,
- pub adapter: Box<dyn LspAdapterTrait>,
+ pub adapter: Box<dyn LspAdapter>,
}
-impl LspAdapter {
- pub async fn new<T: LspAdapterTrait>(adapter: T) -> Arc<Self> {
+impl CachedLspAdapter {
+ pub async fn new<T: LspAdapter>(adapter: T) -> Arc<Self> {
let adapter = Box::new(adapter);
let name = adapter.name().await;
let server_args = adapter.server_args().await;
@@ -89,7 +89,7 @@ impl LspAdapter {
adapter.disk_based_diagnostics_progress_token().await;
let id_for_language = adapter.id_for_language(name.0.as_ref()).await;
- Arc::new(LspAdapter {
+ Arc::new(CachedLspAdapter {
name,
server_args,
initialization_options,
@@ -147,7 +147,7 @@ impl LspAdapter {
}
#[async_trait]
-pub trait LspAdapterTrait: 'static + Send + Sync {
+pub trait LspAdapter: 'static + Send + Sync {
async fn name(&self) -> LanguageServerName;
async fn fetch_latest_server_version(
@@ -275,7 +275,7 @@ pub struct BracketPair {
pub struct Language {
pub(crate) config: LanguageConfig,
pub(crate) grammar: Option<Arc<Grammar>>,
- pub(crate) adapter: Option<Arc<LspAdapter>>,
+ pub(crate) adapter: Option<Arc<CachedLspAdapter>>,
#[cfg(any(test, feature = "test-support"))]
fake_adapter: Option<(
@@ -490,7 +490,7 @@ impl LanguageRegistry {
}
async fn get_server_binary_path(
- adapter: Arc<LspAdapter>,
+ adapter: Arc<CachedLspAdapter>,
language: Arc<Language>,
http_client: Arc<dyn HttpClient>,
download_dir: Arc<Path>,
@@ -532,7 +532,7 @@ async fn get_server_binary_path(
}
async fn fetch_latest_server_binary_path(
- adapter: Arc<LspAdapter>,
+ adapter: Arc<CachedLspAdapter>,
language: Arc<Language>,
http_client: Arc<dyn HttpClient>,
container_dir: &Path,
@@ -581,7 +581,7 @@ impl Language {
}
}
- pub fn lsp_adapter(&self) -> Option<Arc<LspAdapter>> {
+ pub fn lsp_adapter(&self) -> Option<Arc<CachedLspAdapter>> {
self.adapter.clone()
}
@@ -613,7 +613,7 @@ impl Language {
Arc::get_mut(self.grammar.as_mut().unwrap()).unwrap()
}
- pub fn with_lsp_adapter(mut self, lsp_adapter: Arc<LspAdapter>) -> Self {
+ pub fn with_lsp_adapter(mut self, lsp_adapter: Arc<CachedLspAdapter>) -> Self {
self.adapter = Some(lsp_adapter);
self
}
@@ -625,7 +625,7 @@ impl Language {
) -> mpsc::UnboundedReceiver<lsp::FakeLanguageServer> {
let (servers_tx, servers_rx) = mpsc::unbounded();
self.fake_adapter = Some((servers_tx, fake_lsp_adapter.clone()));
- let adapter = LspAdapter::new(fake_lsp_adapter).await;
+ let adapter = CachedLspAdapter::new(fake_lsp_adapter).await;
self.adapter = Some(adapter);
servers_rx
}
@@ -789,7 +789,7 @@ impl Default for FakeLspAdapter {
#[cfg(any(test, feature = "test-support"))]
#[async_trait]
-impl LspAdapterTrait for Arc<FakeLspAdapter> {
+impl LspAdapter for Arc<FakeLspAdapter> {
async fn name(&self) -> LanguageServerName {
LanguageServerName(self.name.into())
}
@@ -24,9 +24,9 @@ use language::{
deserialize_anchor, deserialize_line_ending, deserialize_version, serialize_anchor,
serialize_version,
},
- range_from_lsp, range_to_lsp, Anchor, Bias, Buffer, CharKind, CodeAction, CodeLabel,
- Completion, Diagnostic, DiagnosticEntry, DiagnosticSet, Event as BufferEvent, File as _,
- Language, LanguageRegistry, LanguageServerName, LineEnding, LocalFile, LspAdapter,
+ range_from_lsp, range_to_lsp, Anchor, Bias, Buffer, CachedLspAdapter, CharKind, CodeAction,
+ CodeLabel, Completion, Diagnostic, DiagnosticEntry, DiagnosticSet, Event as BufferEvent,
+ File as _, Language, LanguageRegistry, LanguageServerName, LineEnding, LocalFile,
OffsetRangeExt, Operation, Patch, PointUtf16, TextBufferSnapshot, ToOffset, ToPointUtf16,
Transaction,
};
@@ -200,7 +200,7 @@ pub enum Event {
pub enum LanguageServerState {
Starting(Task<Option<Arc<LanguageServer>>>),
Running {
- adapter: Arc<LspAdapter>,
+ adapter: Arc<CachedLspAdapter>,
server: Arc<LanguageServer>,
},
}
@@ -2007,7 +2007,7 @@ impl Project {
fn language_servers_for_worktree(
&self,
worktree_id: WorktreeId,
- ) -> impl Iterator<Item = (&Arc<LspAdapter>, &Arc<LanguageServer>)> {
+ ) -> impl Iterator<Item = (&Arc<CachedLspAdapter>, &Arc<LanguageServer>)> {
self.language_server_ids
.iter()
.filter_map(move |((language_server_worktree_id, _), id)| {
@@ -2648,7 +2648,7 @@ impl Project {
this: WeakModelHandle<Self>,
params: lsp::ApplyWorkspaceEditParams,
server_id: usize,
- adapter: Arc<LspAdapter>,
+ adapter: Arc<CachedLspAdapter>,
language_server: Arc<LanguageServer>,
mut cx: AsyncAppContext,
) -> Result<lsp::ApplyWorkspaceEditResponse> {
@@ -3913,7 +3913,7 @@ impl Project {
this: ModelHandle<Self>,
edit: lsp::WorkspaceEdit,
push_to_history: bool,
- lsp_adapter: Arc<LspAdapter>,
+ lsp_adapter: Arc<CachedLspAdapter>,
language_server: Arc<LanguageServer>,
cx: &mut AsyncAppContext,
) -> Result<ProjectTransaction> {
@@ -5923,7 +5923,7 @@ impl Project {
&self,
buffer: &Buffer,
cx: &AppContext,
- ) -> Option<(&Arc<LspAdapter>, &Arc<LanguageServer>)> {
+ ) -> Option<(&Arc<CachedLspAdapter>, &Arc<LanguageServer>)> {
if let Some((file, language)) = File::from_dyn(buffer.file()).zip(buffer.language()) {
let name = language.lsp_adapter()?.name.clone();
let worktree_id = file.worktree_id(cx);
@@ -22,23 +22,23 @@ pub async fn init(languages: Arc<LanguageRegistry>, executor: Arc<Background>) {
(
"c",
tree_sitter_c::language(),
- Some(LspAdapter::new(c::CLspAdapter).await),
+ Some(CachedLspAdapter::new(c::CLspAdapter).await),
),
(
"cpp",
tree_sitter_cpp::language(),
- Some(LspAdapter::new(c::CLspAdapter).await),
+ Some(CachedLspAdapter::new(c::CLspAdapter).await),
),
(
"go",
tree_sitter_go::language(),
- Some(LspAdapter::new(go::GoLspAdapter).await),
+ Some(CachedLspAdapter::new(go::GoLspAdapter).await),
),
(
"json",
tree_sitter_json::language(),
match language_plugin::new_json(executor).await.log_err() {
- Some(lang) => Some(LspAdapter::new(lang).await),
+ Some(lang) => Some(CachedLspAdapter::new(lang).await),
None => None,
},
),
@@ -50,12 +50,12 @@ pub async fn init(languages: Arc<LanguageRegistry>, executor: Arc<Background>) {
(
"python",
tree_sitter_python::language(),
- Some(LspAdapter::new(python::PythonLspAdapter).await),
+ Some(CachedLspAdapter::new(python::PythonLspAdapter).await),
),
(
"rust",
tree_sitter_rust::language(),
- Some(LspAdapter::new(rust::RustLspAdapter).await),
+ Some(CachedLspAdapter::new(rust::RustLspAdapter).await),
),
(
"toml",
@@ -65,17 +65,17 @@ pub async fn init(languages: Arc<LanguageRegistry>, executor: Arc<Background>) {
(
"tsx",
tree_sitter_typescript::language_tsx(),
- Some(LspAdapter::new(typescript::TypeScriptLspAdapter).await),
+ Some(CachedLspAdapter::new(typescript::TypeScriptLspAdapter).await),
),
(
"typescript",
tree_sitter_typescript::language_typescript(),
- Some(LspAdapter::new(typescript::TypeScriptLspAdapter).await),
+ Some(CachedLspAdapter::new(typescript::TypeScriptLspAdapter).await),
),
(
"javascript",
tree_sitter_typescript::language_tsx(),
- Some(LspAdapter::new(typescript::TypeScriptLspAdapter).await),
+ Some(CachedLspAdapter::new(typescript::TypeScriptLspAdapter).await),
),
] {
languages.add(Arc::new(language(name, grammar, lsp_adapter)));
@@ -85,7 +85,7 @@ pub async fn init(languages: Arc<LanguageRegistry>, executor: Arc<Background>) {
pub(crate) fn language(
name: &str,
grammar: tree_sitter::Language,
- lsp_adapter: Option<Arc<LspAdapter>>,
+ lsp_adapter: Option<Arc<CachedLspAdapter>>,
) -> Language {
let config = toml::from_slice(
&LanguageDir::get(&format!("{}/config.toml", name))
@@ -11,7 +11,7 @@ use util::ResultExt;
pub struct CLspAdapter;
#[async_trait]
-impl super::LspAdapterTrait for CLspAdapter {
+impl super::LspAdapter for CLspAdapter {
async fn name(&self) -> LanguageServerName {
LanguageServerName("clangd".into())
}
@@ -18,7 +18,7 @@ lazy_static! {
}
#[async_trait]
-impl super::LspAdapterTrait for GoLspAdapter {
+impl super::LspAdapter for GoLspAdapter {
async fn name(&self) -> LanguageServerName {
LanguageServerName("gopls".into())
}
@@ -314,7 +314,7 @@ mod tests {
let language = language(
"go",
tree_sitter_go::language(),
- Some(LspAdapter::new(GoLspAdapter).await),
+ Some(CachedLspAdapter::new(GoLspAdapter).await),
);
let theme = SyntaxTheme::new(vec![
@@ -3,7 +3,7 @@ use async_trait::async_trait;
use client::http::HttpClient;
use futures::lock::Mutex;
use gpui::executor::Background;
-use language::{LanguageServerName, LspAdapterTrait};
+use language::{LanguageServerName, LspAdapter};
use plugin_runtime::{Plugin, PluginBuilder, WasiFn};
use std::{any::Any, path::PathBuf, sync::Arc};
use util::ResultExt;
@@ -55,7 +55,7 @@ impl PluginLspAdapter {
}
#[async_trait]
-impl LspAdapterTrait for PluginLspAdapter {
+impl LspAdapter for PluginLspAdapter {
async fn name(&self) -> LanguageServerName {
let name: String = self
.runtime
@@ -3,7 +3,7 @@ use anyhow::{anyhow, Context, Result};
use async_trait::async_trait;
use client::http::HttpClient;
use futures::StreamExt;
-use language::{LanguageServerName, LspAdapterTrait};
+use language::{LanguageServerName, LspAdapter};
use smol::fs;
use std::{any::Any, path::PathBuf, sync::Arc};
use util::ResultExt;
@@ -15,7 +15,7 @@ impl PythonLspAdapter {
}
#[async_trait]
-impl LspAdapterTrait for PythonLspAdapter {
+impl LspAdapter for PythonLspAdapter {
async fn name(&self) -> LanguageServerName {
LanguageServerName("pyright".into())
}
@@ -14,7 +14,7 @@ use util::ResultExt;
pub struct RustLspAdapter;
#[async_trait]
-impl LspAdapterTrait for RustLspAdapter {
+impl LspAdapter for RustLspAdapter {
async fn name(&self) -> LanguageServerName {
LanguageServerName("rust-analyzer".into())
}
@@ -255,7 +255,7 @@ impl LspAdapterTrait for RustLspAdapter {
#[cfg(test)]
mod tests {
use super::*;
- use crate::languages::{language, LspAdapter};
+ use crate::languages::{language, CachedLspAdapter};
use gpui::{color::Color, MutableAppContext};
use theme::SyntaxTheme;
@@ -305,7 +305,7 @@ mod tests {
let language = language(
"rust",
tree_sitter_rust::language(),
- Some(LspAdapter::new(RustLspAdapter).await),
+ Some(CachedLspAdapter::new(RustLspAdapter).await),
);
let grammar = language.grammar().unwrap();
let theme = SyntaxTheme::new(vec![
@@ -390,7 +390,7 @@ mod tests {
let language = language(
"rust",
tree_sitter_rust::language(),
- Some(LspAdapter::new(RustLspAdapter).await),
+ Some(CachedLspAdapter::new(RustLspAdapter).await),
);
let grammar = language.grammar().unwrap();
let theme = SyntaxTheme::new(vec![
@@ -3,7 +3,7 @@ use anyhow::{anyhow, Context, Result};
use async_trait::async_trait;
use client::http::HttpClient;
use futures::StreamExt;
-use language::{LanguageServerName, LspAdapterTrait};
+use language::{LanguageServerName, LspAdapter};
use serde_json::json;
use smol::fs;
use std::{any::Any, path::PathBuf, sync::Arc};
@@ -21,7 +21,7 @@ struct Versions {
}
#[async_trait]
-impl LspAdapterTrait for TypeScriptLspAdapter {
+impl LspAdapter for TypeScriptLspAdapter {
async fn name(&self) -> LanguageServerName {
LanguageServerName("typescript-language-server".into())
}