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

@ -13,7 +13,7 @@ test-support = [
"rand",
"client2/test-support",
"collections/test-support",
"lsp/test-support",
"lsp2/test-support",
"text/test-support",
"tree-sitter-rust",
"tree-sitter-typescript",
@ -24,16 +24,16 @@ test-support = [
[dependencies]
clock = { path = "../clock" }
collections = { path = "../collections" }
fuzzy = { path = "../fuzzy" }
fuzzy2 = { path = "../fuzzy2" }
fs = { path = "../fs" }
git = { path = "../git" }
gpui2 = { path = "../gpui2" }
lsp = { path = "../lsp" }
lsp2 = { path = "../lsp2" }
rpc = { path = "../rpc" }
settings2 = { path = "../settings2" }
sum_tree = { path = "../sum_tree" }
text = { path = "../text" }
# theme = { path = "../theme" }
theme2 = { path = "../theme2" }
util = { path = "../util" }
anyhow.workspace = true
@ -64,7 +64,7 @@ tree-sitter-typescript = { workspace = true, optional = true }
client2 = { path = "../client2", features = ["test-support"] }
collections = { path = "../collections", features = ["test-support"] }
gpui2 = { path = "../gpui2", features = ["test-support"] }
lsp = { path = "../lsp", features = ["test-support"] }
lsp2 = { path = "../lsp2", features = ["test-support"] }
text = { path = "../text", features = ["test-support"] }
settings = { path = "../settings", features = ["test-support"] }
util = { path = "../util", features = ["test-support"] }

View file

@ -17,7 +17,7 @@ use anyhow::{anyhow, Result};
pub use clock::ReplicaId;
use futures::FutureExt as _;
use gpui2::{AppContext, EventEmitter, HighlightStyle, ModelContext, Task};
use lsp::LanguageServerId;
use lsp2::LanguageServerId;
use parking_lot::Mutex;
use similar::{ChangeTag, TextDiff};
use smallvec::SmallVec;
@ -40,6 +40,7 @@ use std::{
use sum_tree::TreeMap;
use text::operation_queue::OperationQueue;
pub use text::{Buffer as TextBuffer, BufferSnapshot as TextBufferSnapshot, *};
use theme2::SyntaxTheme;
#[cfg(any(test, feature = "test-support"))]
use util::RandomCharIter;
use util::{RangeExt, TryFutureExt as _};
@ -47,7 +48,7 @@ use util::{RangeExt, TryFutureExt as _};
#[cfg(any(test, feature = "test-support"))]
pub use {tree_sitter_rust, tree_sitter_typescript};
pub use lsp::DiagnosticSeverity;
pub use lsp2::DiagnosticSeverity;
pub struct Buffer {
text: TextBuffer,
@ -148,14 +149,14 @@ pub struct Completion {
pub new_text: String,
pub label: CodeLabel,
pub server_id: LanguageServerId,
pub lsp_completion: lsp::CompletionItem,
pub lsp_completion: lsp2::CompletionItem,
}
#[derive(Clone, Debug)]
pub struct CodeAction {
pub server_id: LanguageServerId,
pub range: Range<Anchor>,
pub lsp_action: lsp::CodeAction,
pub lsp_action: lsp2::CodeAction,
}
#[derive(Clone, Debug, PartialEq, Eq)]
@ -3000,14 +3001,14 @@ impl IndentSize {
impl Completion {
pub fn sort_key(&self) -> (usize, &str) {
let kind_key = match self.lsp_completion.kind {
Some(lsp::CompletionItemKind::VARIABLE) => 0,
Some(lsp2::CompletionItemKind::VARIABLE) => 0,
_ => 1,
};
(kind_key, &self.label.text[self.label.filter_range.clone()])
}
pub fn is_snippet(&self) -> bool {
self.lsp_completion.insert_text_format == Some(lsp::InsertTextFormat::SNIPPET)
self.lsp_completion.insert_text_format == Some(lsp2::InsertTextFormat::SNIPPET)
}
}

File diff suppressed because it is too large Load diff

View file

@ -1,6 +1,6 @@
use crate::Diagnostic;
use collections::HashMap;
use lsp::LanguageServerId;
use lsp2::LanguageServerId;
use std::{
cmp::{Ordering, Reverse},
iter,
@ -37,14 +37,14 @@ pub struct Summary {
impl<T> DiagnosticEntry<T> {
// Used to provide diagnostic context to lsp codeAction request
pub fn to_lsp_diagnostic_stub(&self) -> lsp::Diagnostic {
pub fn to_lsp_diagnostic_stub(&self) -> lsp2::Diagnostic {
let code = self
.diagnostic
.code
.clone()
.map(lsp::NumberOrString::String);
.map(lsp2::NumberOrString::String);
lsp::Diagnostic {
lsp2::Diagnostic {
code,
severity: Some(self.diagnostic.severity),
..Default::default()

View file

@ -1,6 +1,6 @@
use gpui2::HighlightStyle;
use std::sync::Arc;
use theme::SyntaxTheme;
use theme2::SyntaxTheme;
#[derive(Clone, Debug)]
pub struct HighlightMap(Arc<[HighlightId]>);
@ -76,36 +76,36 @@ impl Default for HighlightId {
}
}
#[cfg(test)]
mod tests {
use super::*;
use gpui::color::Color;
// #[cfg(test)]
// mod tests {
// use super::*;
// use gpui2::color::Color;
#[test]
fn test_highlight_map() {
let theme = SyntaxTheme::new(
[
("function", Color::from_u32(0x100000ff)),
("function.method", Color::from_u32(0x200000ff)),
("function.async", Color::from_u32(0x300000ff)),
("variable.builtin.self.rust", Color::from_u32(0x400000ff)),
("variable.builtin", Color::from_u32(0x500000ff)),
("variable", Color::from_u32(0x600000ff)),
]
.iter()
.map(|(name, color)| (name.to_string(), (*color).into()))
.collect(),
);
// #[test]
// fn test_highlight_map() {
// let theme = SyntaxTheme::new(
// [
// ("function", Color::from_u32(0x100000ff)),
// ("function.method", Color::from_u32(0x200000ff)),
// ("function.async", Color::from_u32(0x300000ff)),
// ("variable.builtin.self.rust", Color::from_u32(0x400000ff)),
// ("variable.builtin", Color::from_u32(0x500000ff)),
// ("variable", Color::from_u32(0x600000ff)),
// ]
// .iter()
// .map(|(name, color)| (name.to_string(), (*color).into()))
// .collect(),
// );
let capture_names = &[
"function.special".to_string(),
"function.async.rust".to_string(),
"variable.builtin.self".to_string(),
];
// let capture_names = &[
// "function.special".to_string(),
// "function.async.rust".to_string(),
// "variable.builtin.self".to_string(),
// ];
let map = HighlightMap::new(capture_names, &theme);
assert_eq!(map.get(0).name(&theme), Some("function"));
assert_eq!(map.get(1).name(&theme), Some("function.async"));
assert_eq!(map.get(2).name(&theme), Some("variable.builtin"));
}
}
// let map = HighlightMap::new(capture_names, &theme);
// assert_eq!(map.get(0).name(&theme), Some("function"));
// assert_eq!(map.get(1).name(&theme), Some("function.async"));
// assert_eq!(map.get(2).name(&theme), Some("variable.builtin"));
// }
// }

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 {

View file

@ -1,6 +1,6 @@
use fuzzy::{StringMatch, StringMatchCandidate};
use fuzzy2::{StringMatch, StringMatchCandidate};
use gpui2::{Executor, HighlightStyle};
use std::{ops::Range, sync::Arc};
use std::ops::Range;
#[derive(Debug)]
pub struct Outline<T> {
@ -61,7 +61,7 @@ impl<T> Outline<T> {
let query = query.trim_start();
let is_path_query = query.contains(' ');
let smart_case = query.chars().any(|c| c.is_uppercase());
let mut matches = fuzzy::match_strings(
let mut matches = fuzzy2::match_strings(
if is_path_query {
&self.path_candidates
} else {

View file

@ -4,7 +4,7 @@ use crate::{
};
use anyhow::{anyhow, Result};
use clock::ReplicaId;
use lsp::{DiagnosticSeverity, LanguageServerId};
use lsp2::{DiagnosticSeverity, LanguageServerId};
use rpc::proto;
use std::{ops::Range, sync::Arc};
use text::*;