use super::*;
mod breadcrumbs;
mod capabilities;
mod code_actions;
mod code_lens;
mod decorations;
mod format;
mod go_to_symbol;
mod hierarchy;
mod hover_text;
mod inlay_hints;
mod messages;
mod navigation;
mod outline;
mod peek;
mod rename;
mod rust_analyzer;
mod selection;
mod semantic;
mod sync;
mod typing;
mod workspace_edits;
mod workspace_symbols;
#[cfg(test)]
pub(super) use breadcrumbs::breadcrumb_symbol_chain;
#[cfg(test)]
pub(super) use breadcrumbs::sibling_symbols;
pub(super) use hover_text::compose_hover;
pub(super) use hover_text::format_diagnostics;
pub(super) use outline::syntax_kind_of;
#[cfg(test)]
pub(super) use peek::peek_excerpt;
#[cfg(test)]
pub(super) use semantic::semantic_reply_is_current;
pub(super) use sync::just_installed_covers_path;
pub(super) use sync::store_diagnostics_update;
pub(super) use sync::tool_on_path;
use sync::*;
pub(super) use typing::is_signature_help_trigger;
pub(super) use typing::snippet_completion_item;
pub(super) struct LspState {
pub(super) manager: Option<crate::lsp::LspManager>,
pub(super) last_seen: std::collections::HashMap<PathBuf, u64>,
pub(super) synced: Option<LspSynced>,
pub(super) semantic_generation_seen: std::collections::HashMap<PathBuf, u64>,
pub(super) diagnostics: std::collections::HashMap<
PathBuf,
std::collections::HashMap<String, Vec<crate::lsp::manager::Diagnostic>>,
>,
pub(super) progress: std::collections::HashMap<String, String>,
pub(super) questions: std::collections::VecDeque<LspQuestion>,
pub(super) question: Option<LspQuestion>,
pub(super) paused_for_build: bool,
}
pub(super) struct LspSynced {
pub(super) docs: Vec<(PathBuf, u64, bool)>,
pub(super) held: Option<(PathBuf, Option<u64>)>,
pub(super) seen: usize,
pub(super) buffers: Vec<PathBuf>,
}
impl LspState {
pub(super) fn new(manager: Option<crate::lsp::LspManager>) -> Self {
Self {
manager,
last_seen: std::collections::HashMap::new(),
synced: None,
semantic_generation_seen: std::collections::HashMap::new(),
diagnostics: std::collections::HashMap::new(),
progress: std::collections::HashMap::new(),
questions: std::collections::VecDeque::new(),
question: None,
paused_for_build: false,
}
}
pub(super) fn rebind(&mut self, root: &Path) -> Option<String> {
if let Some(old) = self.manager.take() {
fs_watch::offload_drop(old);
}
let paused_for_build = self.paused_for_build;
let (manager, error) = if paused_for_build {
(None, None)
} else {
match crate::lsp::LspManager::new(root.to_path_buf()) {
Ok(m) => (Some(m), None),
Err(e) => (
None,
Some(format!("Language servers could not restart: {e}")),
),
}
};
*self = Self {
paused_for_build,
..Self::new(manager)
};
error
}
}
#[derive(Clone, Debug, PartialEq, Eq)]
pub(super) struct CaretSpot {
pub(super) path: PathBuf,
pub(super) row: usize,
pub(super) col: usize,
pub(super) seq: u64,
}
impl CaretSpot {
pub(super) fn of(ed: &crate::widgets::editor::Editor) -> Option<Self> {
Some(Self {
path: ed.path.clone()?,
row: ed.cursor_row,
col: ed.cursor_col,
seq: ed.edit_seq,
})
}
pub(super) fn is_caret_of(&self, ed: &crate::widgets::editor::Editor) -> bool {
ed.path.as_deref() == Some(self.path.as_path())
&& ed.cursor_row == self.row
&& ed.cursor_col == self.col
&& ed.edit_seq == self.seq
}
}
#[derive(Clone, Debug, PartialEq, Eq)]
pub(super) struct FileRequest {
pub(super) id: u64,
pub(super) path: PathBuf,
pub(super) seq: u64,
}
#[derive(Clone, Debug, PartialEq, Eq)]
pub(super) struct CaretRequest {
pub(super) id: u64,
pub(super) at: CaretSpot,
}
pub(super) fn take_reply<T>(
pending: &mut Option<u64>,
mut next: impl FnMut() -> Option<T>,
id: impl Fn(&T) -> u64,
) -> Option<T> {
let mut reply = None;
while let Some(candidate) = next() {
if Some(id(&candidate)) == *pending {
reply = Some(candidate);
}
}
if reply.is_some() {
*pending = None;
}
reply
}
#[derive(Clone, Copy, PartialEq, Eq, Debug)]
pub(super) enum OnTypeReply {
NotOurs,
Stale,
Apply,
}
#[derive(Clone, Debug, PartialEq, Eq)]
pub(super) enum CrumbTarget {
Folder(PathBuf),
File(PathBuf),
Symbol(usize),
}
pub(super) type OutlineKey = (PathBuf, Option<u64>);
pub(super) type OutlineParse = crate::jobs::Job<Vec<crate::lsp::manager::OutlineSymbol>>;
pub(super) type PeekLocation = (PathBuf, u32, u32);
pub(super) const CODE_LENS_SETTLE: std::time::Duration = std::time::Duration::from_millis(600);
pub(super) const STICKY_SCROLL_MAX: usize = 5;
pub(super) const BASH_SERVER: &str = "bash-language-server";
pub(super) const SHFMT_MISSING: &str =
"Not formatted: bash-language-server formats shell scripts with shfmt, which is not on PATH";
pub(super) const SHELLCHECK_MISSING: &str = "Shell scripts are not linted: bash-language-server lints with shellcheck, which is not on PATH";
pub(super) const LSP_PAUSED_FOR_BUILD: &str =
"Language servers are stopped while croft builds its update; they restart when it finishes";
pub(super) const OUTLINE_INLINE_MAX_BYTES: usize = 64 * 1024;
pub(super) const HOVER_DIVIDER: &str = "────────";
pub(super) const NO_HOVER_AT_CARET: &str = "No hover information at the caret";