Checkpoint

This commit is contained in:
Antonio Scandurra 2023-10-23 10:59:29 +02:00
parent a0b667a2ca
commit 56462ef793
23 changed files with 4833 additions and 2536 deletions

View file

@ -20,7 +20,7 @@ use futures::{
use gpui2::{AppContext, AsyncAppContext, Executor, Task};
pub use highlight_map::HighlightMap;
use lazy_static::lazy_static;
use lsp::{CodeActionKind, LanguageServerBinary};
use lsp2::{CodeActionKind, LanguageServerBinary};
use parking_lot::{Mutex, RwLock};
use postage::watch;
use regex::Regex;
@ -42,7 +42,7 @@ use std::{
},
};
use syntax_map::SyntaxSnapshot;
use theme::{SyntaxTheme, Theme};
use theme2::{SyntaxTheme, Theme};
use tree_sitter::{self, Query};
use unicase::UniCase;
use util::{http::HttpClient, paths::PathExt};
@ -51,7 +51,7 @@ use util::{post_inc, ResultExt, TryFutureExt as _, UnwrapFuture};
pub use buffer::Operation;
pub use buffer::*;
pub use diagnostic_set::DiagnosticEntry;
pub use lsp::LanguageServerId;
pub use lsp2::LanguageServerId;
pub use outline::{Outline, OutlineItem};
pub use syntax_map::{OwnedSyntaxLayerInfo, SyntaxLayerInfo};
pub use text::LineEnding;
@ -98,7 +98,7 @@ lazy_static! {
}
pub trait ToLspPosition {
fn to_lsp_position(self) -> lsp::Position;
fn to_lsp_position(self) -> lsp2::Position;
}
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
@ -201,17 +201,17 @@ impl CachedLspAdapter {
self.adapter.workspace_configuration(cx)
}
pub fn process_diagnostics(&self, params: &mut lsp::PublishDiagnosticsParams) {
pub fn process_diagnostics(&self, params: &mut lsp2::PublishDiagnosticsParams) {
self.adapter.process_diagnostics(params)
}
pub async fn process_completion(&self, completion_item: &mut lsp::CompletionItem) {
pub async fn process_completion(&self, completion_item: &mut lsp2::CompletionItem) {
self.adapter.process_completion(completion_item).await
}
pub async fn label_for_completion(
&self,
completion_item: &lsp::CompletionItem,
completion_item: &lsp2::CompletionItem,
language: &Arc<Language>,
) -> Option<CodeLabel> {
self.adapter
@ -222,7 +222,7 @@ impl CachedLspAdapter {
pub async fn label_for_symbol(
&self,
name: &str,
kind: lsp::SymbolKind,
kind: lsp2::SymbolKind,
language: &Arc<Language>,
) -> Option<CodeLabel> {
self.adapter.label_for_symbol(name, kind, language).await
@ -287,13 +287,13 @@ pub trait LspAdapter: 'static + Send + Sync {
container_dir: PathBuf,
) -> Option<LanguageServerBinary>;
fn process_diagnostics(&self, _: &mut lsp::PublishDiagnosticsParams) {}
fn process_diagnostics(&self, _: &mut lsp2::PublishDiagnosticsParams) {}
async fn process_completion(&self, _: &mut lsp::CompletionItem) {}
async fn process_completion(&self, _: &mut lsp2::CompletionItem) {}
async fn label_for_completion(
&self,
_: &lsp::CompletionItem,
_: &lsp2::CompletionItem,
_: &Arc<Language>,
) -> Option<CodeLabel> {
None
@ -302,7 +302,7 @@ pub trait LspAdapter: 'static + Send + Sync {
async fn label_for_symbol(
&self,
_: &str,
_: lsp::SymbolKind,
_: lsp2::SymbolKind,
_: &Arc<Language>,
) -> Option<CodeLabel> {
None
@ -494,8 +494,8 @@ fn deserialize_regex<'de, D: Deserializer<'de>>(d: D) -> Result<Option<Regex>, D
pub struct FakeLspAdapter {
pub name: &'static str,
pub initialization_options: Option<Value>,
pub capabilities: lsp::ServerCapabilities,
pub initializer: Option<Box<dyn 'static + Send + Sync + Fn(&mut lsp::FakeLanguageServer)>>,
pub capabilities: lsp2::ServerCapabilities,
pub initializer: Option<Box<dyn 'static + Send + Sync + Fn(&mut lsp2::FakeLanguageServer)>>,
pub disk_based_diagnostics_progress_token: Option<String>,
pub disk_based_diagnostics_sources: Vec<String>,
pub enabled_formatters: Vec<BundledFormatter>,
@ -550,7 +550,7 @@ pub struct Language {
#[cfg(any(test, feature = "test-support"))]
fake_adapter: Option<(
mpsc::UnboundedSender<lsp::FakeLanguageServer>,
mpsc::UnboundedSender<lsp2::FakeLanguageServer>,
Arc<FakeLspAdapter>,
)>,
}
@ -667,7 +667,7 @@ struct LanguageRegistryState {
pub struct PendingLanguageServer {
pub server_id: LanguageServerId,
pub task: Task<Result<Option<lsp::LanguageServer>>>,
pub task: Task<Result<Option<lsp2::LanguageServer>>>,
pub container_dir: Option<Arc<Path>>,
}
@ -922,7 +922,7 @@ impl LanguageRegistry {
if language.fake_adapter.is_some() {
let task = cx.spawn(|cx| async move {
let (servers_tx, fake_adapter) = language.fake_adapter.as_ref().unwrap();
let (server, mut fake_server) = lsp::LanguageServer::fake(
let (server, mut fake_server) = lsp2::LanguageServer::fake(
fake_adapter.name.to_string(),
fake_adapter.capabilities.clone(),
cx.clone(),
@ -933,10 +933,10 @@ impl LanguageRegistry {
}
let servers_tx = servers_tx.clone();
cx.background()
cx.executor()
.spawn(async move {
if fake_server
.try_receive_notification::<lsp::notification::Initialized>()
.try_receive_notification::<lsp2::notification::Initialized>()
.await
.is_some()
{
@ -970,18 +970,22 @@ impl LanguageRegistry {
let task = {
let container_dir = container_dir.clone();
cx.spawn(|mut cx| async move {
cx.spawn(move |mut cx| async move {
login_shell_env_loaded.await;
let mut lock = this.lsp_binary_paths.lock();
let entry = lock
let entry = this
.lsp_binary_paths
.lock()
.entry(adapter.name.clone())
.or_insert_with(|| {
let adapter = adapter.clone();
let language = language.clone();
let delegate = delegate.clone();
cx.spawn(|cx| {
get_binary(
adapter.clone(),
language.clone(),
delegate.clone(),
adapter,
language,
delegate,
container_dir,
lsp_binary_statuses,
cx,
@ -991,9 +995,8 @@ impl LanguageRegistry {
.shared()
})
.clone();
drop(lock);
let binary = match entry.clone().await.log_err() {
let binary = match entry.await.log_err() {
Some(binary) => binary,
None => return Ok(None),
};
@ -1004,7 +1007,7 @@ impl LanguageRegistry {
}
}
Ok(Some(lsp::LanguageServer::new(
Ok(Some(lsp2::LanguageServer::new(
server_id,
binary,
&root_path,
@ -1486,7 +1489,7 @@ impl Language {
pub async fn set_fake_lsp_adapter(
&mut self,
fake_lsp_adapter: Arc<FakeLspAdapter>,
) -> mpsc::UnboundedReceiver<lsp::FakeLanguageServer> {
) -> mpsc::UnboundedReceiver<lsp2::FakeLanguageServer> {
let (servers_tx, servers_rx) = mpsc::unbounded();
self.fake_adapter = Some((servers_tx, fake_lsp_adapter.clone()));
let adapter = CachedLspAdapter::new(Arc::new(fake_lsp_adapter)).await;
@ -1516,7 +1519,7 @@ impl Language {
None
}
pub async fn process_completion(self: &Arc<Self>, completion: &mut lsp::CompletionItem) {
pub async fn process_completion(self: &Arc<Self>, completion: &mut lsp2::CompletionItem) {
for adapter in &self.adapters {
adapter.process_completion(completion).await;
}
@ -1524,7 +1527,7 @@ impl Language {
pub async fn label_for_completion(
self: &Arc<Self>,
completion: &lsp::CompletionItem,
completion: &lsp2::CompletionItem,
) -> Option<CodeLabel> {
self.adapters
.first()
@ -1536,7 +1539,7 @@ impl Language {
pub async fn label_for_symbol(
self: &Arc<Self>,
name: &str,
kind: lsp::SymbolKind,
kind: lsp2::SymbolKind,
) -> Option<CodeLabel> {
self.adapters
.first()
@ -1756,7 +1759,7 @@ impl Default for FakeLspAdapter {
fn default() -> Self {
Self {
name: "the-fake-language-server",
capabilities: lsp::LanguageServer::full_capabilities(),
capabilities: lsp2::LanguageServer::full_capabilities(),
initializer: None,
disk_based_diagnostics_progress_token: None,
initialization_options: None,
@ -1805,7 +1808,7 @@ impl LspAdapter for Arc<FakeLspAdapter> {
unreachable!();
}
fn process_diagnostics(&self, _: &mut lsp::PublishDiagnosticsParams) {}
fn process_diagnostics(&self, _: &mut lsp2::PublishDiagnosticsParams) {}
async fn disk_based_diagnostic_sources(&self) -> Vec<String> {
self.disk_based_diagnostics_sources.clone()
@ -1835,22 +1838,22 @@ fn get_capture_indices(query: &Query, captures: &mut [(&str, &mut Option<u32>)])
}
}
pub fn point_to_lsp(point: PointUtf16) -> lsp::Position {
lsp::Position::new(point.row, point.column)
pub fn point_to_lsp(point: PointUtf16) -> lsp2::Position {
lsp2::Position::new(point.row, point.column)
}
pub fn point_from_lsp(point: lsp::Position) -> Unclipped<PointUtf16> {
pub fn point_from_lsp(point: lsp2::Position) -> Unclipped<PointUtf16> {
Unclipped(PointUtf16::new(point.line, point.character))
}
pub fn range_to_lsp(range: Range<PointUtf16>) -> lsp::Range {
lsp::Range {
pub fn range_to_lsp(range: Range<PointUtf16>) -> lsp2::Range {
lsp2::Range {
start: point_to_lsp(range.start),
end: point_to_lsp(range.end),
}
}
pub fn range_from_lsp(range: lsp::Range) -> Range<Unclipped<PointUtf16>> {
pub fn range_from_lsp(range: lsp2::Range) -> Range<Unclipped<PointUtf16>> {
let mut start = point_from_lsp(range.start);
let mut end = point_from_lsp(range.end);
if start > end {