Introduce a LanguageServerId wrapper type
Clarify the meaning of all the usizes in use in all of these struct fields an method signatures.
This commit is contained in:
parent
c5f86bc6af
commit
4dd917c123
16 changed files with 166 additions and 117 deletions
|
@ -17,6 +17,7 @@ use collections::HashMap;
|
|||
use fs::LineEnding;
|
||||
use futures::FutureExt as _;
|
||||
use gpui::{fonts::HighlightStyle, AppContext, Entity, ModelContext, Task};
|
||||
use lsp::LanguageServerId;
|
||||
use parking_lot::Mutex;
|
||||
use settings::Settings;
|
||||
use similar::{ChangeTag, TextDiff};
|
||||
|
@ -72,7 +73,7 @@ pub struct Buffer {
|
|||
syntax_map: Mutex<SyntaxMap>,
|
||||
parsing_in_background: bool,
|
||||
parse_count: usize,
|
||||
diagnostics: HashMap<usize, DiagnosticSet>, // server_id -> diagnostic set
|
||||
diagnostics: HashMap<LanguageServerId, DiagnosticSet>,
|
||||
remote_selections: TreeMap<ReplicaId, SelectionSet>,
|
||||
selections_update_count: usize,
|
||||
diagnostics_update_count: usize,
|
||||
|
@ -89,7 +90,7 @@ pub struct BufferSnapshot {
|
|||
pub git_diff: git::diff::BufferDiff,
|
||||
pub(crate) syntax: SyntaxSnapshot,
|
||||
file: Option<Arc<dyn File>>,
|
||||
diagnostics: HashMap<usize, DiagnosticSet>, // server_id -> diagnostic set
|
||||
diagnostics: HashMap<LanguageServerId, DiagnosticSet>,
|
||||
diagnostics_update_count: usize,
|
||||
file_update_count: usize,
|
||||
git_diff_update_count: usize,
|
||||
|
@ -157,7 +158,7 @@ pub struct Completion {
|
|||
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct CodeAction {
|
||||
pub server_id: usize,
|
||||
pub server_id: LanguageServerId,
|
||||
pub range: Range<Anchor>,
|
||||
pub lsp_action: lsp::CodeAction,
|
||||
}
|
||||
|
@ -167,7 +168,7 @@ pub enum Operation {
|
|||
Buffer(text::Operation),
|
||||
|
||||
UpdateDiagnostics {
|
||||
server_id: usize,
|
||||
server_id: LanguageServerId,
|
||||
diagnostics: Arc<[DiagnosticEntry<Anchor>]>,
|
||||
lamport_timestamp: clock::Lamport,
|
||||
},
|
||||
|
@ -879,7 +880,7 @@ impl Buffer {
|
|||
|
||||
pub fn update_diagnostics(
|
||||
&mut self,
|
||||
server_id: usize,
|
||||
server_id: LanguageServerId,
|
||||
diagnostics: DiagnosticSet,
|
||||
cx: &mut ModelContext<Self>,
|
||||
) {
|
||||
|
@ -1645,7 +1646,7 @@ impl Buffer {
|
|||
|
||||
fn apply_diagnostic_update(
|
||||
&mut self,
|
||||
server_id: usize,
|
||||
server_id: LanguageServerId,
|
||||
diagnostics: DiagnosticSet,
|
||||
lamport_timestamp: clock::Lamport,
|
||||
cx: &mut ModelContext<Self>,
|
||||
|
|
|
@ -1866,7 +1866,7 @@ fn test_random_collaboration(cx: &mut AppContext, mut rng: StdRng) {
|
|||
buffer,
|
||||
);
|
||||
log::info!("peer {} setting diagnostics: {:?}", replica_id, diagnostics);
|
||||
buffer.update_diagnostics(0, diagnostics, cx);
|
||||
buffer.update_diagnostics(LanguageServerId(0), diagnostics, cx);
|
||||
});
|
||||
mutation_count -= 1;
|
||||
}
|
||||
|
|
|
@ -54,6 +54,7 @@ use futures::channel::mpsc;
|
|||
pub use buffer::Operation;
|
||||
pub use buffer::*;
|
||||
pub use diagnostic_set::DiagnosticEntry;
|
||||
pub use lsp::LanguageServerId;
|
||||
pub use outline::{Outline, OutlineItem};
|
||||
pub use tree_sitter::{Parser, Tree};
|
||||
|
||||
|
@ -524,7 +525,7 @@ struct LanguageRegistryState {
|
|||
}
|
||||
|
||||
pub struct PendingLanguageServer {
|
||||
pub server_id: usize,
|
||||
pub server_id: LanguageServerId,
|
||||
pub task: Task<Result<lsp::LanguageServer>>,
|
||||
}
|
||||
|
||||
|
@ -819,7 +820,7 @@ impl LanguageRegistry {
|
|||
Ok(server)
|
||||
});
|
||||
|
||||
let server_id = post_inc(&mut self.state.write().next_language_server_id);
|
||||
let server_id = self.state.write().next_language_server_id();
|
||||
return Some(PendingLanguageServer { server_id, task });
|
||||
}
|
||||
|
||||
|
@ -837,7 +838,7 @@ impl LanguageRegistry {
|
|||
let adapter = adapter.clone();
|
||||
let lsp_binary_statuses = self.lsp_binary_statuses_tx.clone();
|
||||
let login_shell_env_loaded = self.login_shell_env_loaded.clone();
|
||||
let server_id = post_inc(&mut self.state.write().next_language_server_id);
|
||||
let server_id = self.state.write().next_language_server_id();
|
||||
|
||||
let task = cx.spawn(|cx| async move {
|
||||
login_shell_env_loaded.await;
|
||||
|
@ -884,6 +885,10 @@ impl LanguageRegistry {
|
|||
}
|
||||
|
||||
impl LanguageRegistryState {
|
||||
fn next_language_server_id(&mut self) -> LanguageServerId {
|
||||
LanguageServerId(post_inc(&mut self.next_language_server_id))
|
||||
}
|
||||
|
||||
fn add(&mut self, language: Arc<Language>) {
|
||||
if let Some(theme) = self.theme.as_ref() {
|
||||
language.set_theme(&theme.editor.syntax);
|
||||
|
|
|
@ -4,7 +4,7 @@ use crate::{
|
|||
};
|
||||
use anyhow::{anyhow, Result};
|
||||
use clock::ReplicaId;
|
||||
use lsp::DiagnosticSeverity;
|
||||
use lsp::{DiagnosticSeverity, LanguageServerId};
|
||||
use rpc::proto;
|
||||
use std::{ops::Range, sync::Arc};
|
||||
use text::*;
|
||||
|
@ -80,7 +80,7 @@ pub fn serialize_operation(operation: &crate::Operation) -> proto::Operation {
|
|||
} => proto::operation::Variant::UpdateDiagnostics(proto::UpdateDiagnostics {
|
||||
replica_id: lamport_timestamp.replica_id as u32,
|
||||
lamport_timestamp: lamport_timestamp.value,
|
||||
server_id: *server_id as u64,
|
||||
server_id: server_id.0 as u64,
|
||||
diagnostics: serialize_diagnostics(diagnostics.iter()),
|
||||
}),
|
||||
|
||||
|
@ -277,7 +277,7 @@ pub fn deserialize_operation(message: proto::Operation) -> Result<crate::Operati
|
|||
replica_id: message.replica_id as ReplicaId,
|
||||
value: message.lamport_timestamp,
|
||||
},
|
||||
server_id: message.server_id as usize,
|
||||
server_id: LanguageServerId(message.server_id as usize),
|
||||
diagnostics: deserialize_diagnostics(message.diagnostics),
|
||||
}
|
||||
}
|
||||
|
@ -469,7 +469,7 @@ pub async fn deserialize_completion(
|
|||
|
||||
pub fn serialize_code_action(action: &CodeAction) -> proto::CodeAction {
|
||||
proto::CodeAction {
|
||||
server_id: action.server_id as u64,
|
||||
server_id: action.server_id.0 as u64,
|
||||
start: Some(serialize_anchor(&action.range.start)),
|
||||
end: Some(serialize_anchor(&action.range.end)),
|
||||
lsp_action: serde_json::to_vec(&action.lsp_action).unwrap(),
|
||||
|
@ -487,7 +487,7 @@ pub fn deserialize_code_action(action: proto::CodeAction) -> Result<CodeAction>
|
|||
.ok_or_else(|| anyhow!("invalid end"))?;
|
||||
let lsp_action = serde_json::from_slice(&action.lsp_action)?;
|
||||
Ok(CodeAction {
|
||||
server_id: action.server_id as usize,
|
||||
server_id: LanguageServerId(action.server_id as usize),
|
||||
range: start..end,
|
||||
lsp_action,
|
||||
})
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue