Introduce LspAdapterDelegate trait, passed to LspDelegates
This commit is contained in:
parent
05d69c804c
commit
360bbebbd9
13 changed files with 243 additions and 133 deletions
|
@ -38,9 +38,9 @@ use language::{
|
|||
},
|
||||
range_from_lsp, range_to_lsp, Anchor, Bias, Buffer, CachedLspAdapter, CodeAction, CodeLabel,
|
||||
Completion, Diagnostic, DiagnosticEntry, DiagnosticSet, Diff, Event as BufferEvent, File as _,
|
||||
Language, LanguageRegistry, LanguageServerName, LocalFile, OffsetRangeExt, Operation, Patch,
|
||||
PendingLanguageServer, PointUtf16, TextBufferSnapshot, ToOffset, ToPointUtf16, Transaction,
|
||||
Unclipped,
|
||||
Language, LanguageRegistry, LanguageServerName, LocalFile, LspAdapterDelegate, OffsetRangeExt,
|
||||
Operation, Patch, PendingLanguageServer, PointUtf16, TextBufferSnapshot, ToOffset,
|
||||
ToPointUtf16, Transaction, Unclipped,
|
||||
};
|
||||
use log::error;
|
||||
use lsp::{
|
||||
|
@ -75,8 +75,8 @@ use std::{
|
|||
};
|
||||
use terminals::Terminals;
|
||||
use util::{
|
||||
debug_panic, defer, merge_json_value_into, paths::LOCAL_SETTINGS_RELATIVE_PATH, post_inc,
|
||||
ResultExt, TryFutureExt as _,
|
||||
debug_panic, defer, http::HttpClient, merge_json_value_into,
|
||||
paths::LOCAL_SETTINGS_RELATIVE_PATH, post_inc, ResultExt, TryFutureExt as _,
|
||||
};
|
||||
|
||||
pub use fs::*;
|
||||
|
@ -252,6 +252,7 @@ pub enum Event {
|
|||
LanguageServerAdded(LanguageServerId),
|
||||
LanguageServerRemoved(LanguageServerId),
|
||||
LanguageServerLog(LanguageServerId, String),
|
||||
LanguageServerNotification(String),
|
||||
ActiveEntryChanged(Option<ProjectEntryId>),
|
||||
WorktreeAdded,
|
||||
WorktreeRemoved(WorktreeId),
|
||||
|
@ -435,6 +436,11 @@ pub enum FormatTrigger {
|
|||
Manual,
|
||||
}
|
||||
|
||||
struct ProjectLspAdapterDelegate {
|
||||
project: ModelHandle<Project>,
|
||||
http_client: Arc<dyn HttpClient>,
|
||||
}
|
||||
|
||||
impl FormatTrigger {
|
||||
fn from_proto(value: i32) -> FormatTrigger {
|
||||
match value {
|
||||
|
@ -2407,7 +2413,7 @@ impl Project {
|
|||
language.clone(),
|
||||
adapter.clone(),
|
||||
worktree_path.clone(),
|
||||
self.client.http_client(),
|
||||
ProjectLspAdapterDelegate::new(self, cx),
|
||||
cx,
|
||||
) {
|
||||
Some(pending_server) => pending_server,
|
||||
|
@ -7188,6 +7194,27 @@ impl<P: AsRef<Path>> From<(WorktreeId, P)> for ProjectPath {
|
|||
}
|
||||
}
|
||||
|
||||
impl ProjectLspAdapterDelegate {
|
||||
fn new(project: &Project, cx: &ModelContext<Project>) -> Arc<Self> {
|
||||
Arc::new(Self {
|
||||
project: cx.handle(),
|
||||
http_client: project.client.http_client(),
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
impl LspAdapterDelegate for ProjectLspAdapterDelegate {
|
||||
fn show_notification(&self, message: &str, cx: &mut AppContext) {
|
||||
self.project.update(cx, |_, cx| {
|
||||
cx.emit(Event::LanguageServerNotification(message.to_owned()))
|
||||
});
|
||||
}
|
||||
|
||||
fn http_client(&self) -> Arc<dyn HttpClient> {
|
||||
self.http_client.clone()
|
||||
}
|
||||
}
|
||||
|
||||
fn split_operations(
|
||||
mut operations: Vec<proto::Operation>,
|
||||
) -> impl Iterator<Item = Vec<proto::Operation>> {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue