internal: prepare to track changes to mem_docs
This commit is contained in:
parent
f0db648cb6
commit
410679285b
@ -1,16 +0,0 @@
|
||||
//! In-memory document information.
|
||||
|
||||
/// Information about a document that the Language Client
|
||||
/// knows about.
|
||||
/// Its lifetime is driven by the textDocument/didOpen and textDocument/didClose
|
||||
/// client notifications.
|
||||
#[derive(Debug, Clone)]
|
||||
pub(crate) struct DocumentData {
|
||||
pub(crate) version: i32,
|
||||
}
|
||||
|
||||
impl DocumentData {
|
||||
pub(crate) fn new(version: i32) -> Self {
|
||||
DocumentData { version }
|
||||
}
|
||||
}
|
@ -8,7 +8,7 @@
|
||||
use crossbeam_channel::{unbounded, Receiver, Sender};
|
||||
use flycheck::FlycheckHandle;
|
||||
use ide::{Analysis, AnalysisHost, Cancellable, Change, FileId};
|
||||
use ide_db::base_db::{CrateId, VfsPath};
|
||||
use ide_db::base_db::CrateId;
|
||||
use lsp_types::{SemanticTokens, Url};
|
||||
use parking_lot::{Mutex, RwLock};
|
||||
use project_model::{
|
||||
@ -20,11 +20,11 @@
|
||||
use crate::{
|
||||
config::Config,
|
||||
diagnostics::{CheckFixes, DiagnosticCollection},
|
||||
document::DocumentData,
|
||||
from_proto,
|
||||
line_index::{LineEndings, LineIndex},
|
||||
lsp_ext,
|
||||
main_loop::Task,
|
||||
mem_docs::MemDocs,
|
||||
op_queue::OpQueue,
|
||||
reload::SourceRootConfig,
|
||||
request_metrics::{LatestRequests, RequestMetrics},
|
||||
@ -57,7 +57,7 @@ pub(crate) struct GlobalState {
|
||||
pub(crate) config: Arc<Config>,
|
||||
pub(crate) analysis_host: AnalysisHost,
|
||||
pub(crate) diagnostics: DiagnosticCollection,
|
||||
pub(crate) mem_docs: FxHashMap<VfsPath, DocumentData>,
|
||||
pub(crate) mem_docs: MemDocs,
|
||||
pub(crate) semantic_tokens_cache: Arc<Mutex<FxHashMap<Url, SemanticTokens>>>,
|
||||
pub(crate) shutdown_requested: bool,
|
||||
pub(crate) last_reported_status: Option<lsp_ext::ServerStatusParams>,
|
||||
@ -115,7 +115,7 @@ pub(crate) struct GlobalStateSnapshot {
|
||||
pub(crate) analysis: Analysis,
|
||||
pub(crate) check_fixes: CheckFixes,
|
||||
pub(crate) latest_requests: Arc<RwLock<LatestRequests>>,
|
||||
mem_docs: FxHashMap<VfsPath, DocumentData>,
|
||||
mem_docs: MemDocs,
|
||||
pub(crate) semantic_tokens_cache: Arc<Mutex<FxHashMap<Url, SemanticTokens>>>,
|
||||
vfs: Arc<RwLock<(vfs::Vfs, FxHashMap<FileId, LineEndings>)>>,
|
||||
pub(crate) workspaces: Arc<Vec<ProjectWorkspace>>,
|
||||
@ -147,7 +147,7 @@ pub(crate) fn new(sender: Sender<lsp_server::Message>, config: Config) -> Global
|
||||
config: Arc::new(config.clone()),
|
||||
analysis_host,
|
||||
diagnostics: Default::default(),
|
||||
mem_docs: FxHashMap::default(),
|
||||
mem_docs: MemDocs::default(),
|
||||
semantic_tokens_cache: Arc::new(Default::default()),
|
||||
shutdown_requested: false,
|
||||
last_reported_status: None,
|
||||
|
@ -33,7 +33,7 @@ macro_rules! eprintln {
|
||||
mod request_metrics;
|
||||
mod lsp_utils;
|
||||
mod thread_pool;
|
||||
mod document;
|
||||
mod mem_docs;
|
||||
mod diff;
|
||||
mod op_queue;
|
||||
pub mod lsp_ext;
|
||||
|
@ -17,11 +17,11 @@
|
||||
use crate::{
|
||||
config::Config,
|
||||
dispatch::{NotificationDispatcher, RequestDispatcher},
|
||||
document::DocumentData,
|
||||
from_proto,
|
||||
global_state::{file_id_to_url, url_to_file_id, GlobalState},
|
||||
handlers, lsp_ext,
|
||||
lsp_utils::{apply_document_changes, is_cancelled, notification_is, Progress},
|
||||
mem_docs::DocumentData,
|
||||
reload::{BuildDataProgress, ProjectWorkspaceProgress},
|
||||
Result,
|
||||
};
|
||||
@ -305,7 +305,7 @@ fn handle_event(&mut self, event: Event) -> Result<()> {
|
||||
let vfs = &mut self.vfs.write().0;
|
||||
for (path, contents) in files {
|
||||
let path = VfsPath::from(path);
|
||||
if !self.mem_docs.contains_key(&path) {
|
||||
if !self.mem_docs.contains(&path) {
|
||||
vfs.set_file_contents(path, contents);
|
||||
}
|
||||
}
|
||||
@ -582,7 +582,7 @@ fn on_notification(&mut self, not: Notification) -> Result<()> {
|
||||
if this
|
||||
.mem_docs
|
||||
.insert(path.clone(), DocumentData::new(params.text_document.version))
|
||||
.is_some()
|
||||
.is_err()
|
||||
{
|
||||
log::error!("duplicate DidOpenTextDocument: {}", path)
|
||||
}
|
||||
@ -628,7 +628,7 @@ fn on_notification(&mut self, not: Notification) -> Result<()> {
|
||||
})?
|
||||
.on::<lsp_types::notification::DidCloseTextDocument>(|this, params| {
|
||||
if let Ok(path) = from_proto::vfs_path(¶ms.text_document.uri) {
|
||||
if this.mem_docs.remove(&path).is_none() {
|
||||
if this.mem_docs.remove(&path).is_err() {
|
||||
log::error!("orphan DidCloseTextDocument: {}", path);
|
||||
}
|
||||
|
||||
@ -719,7 +719,7 @@ fn update_file_notifications_on_threadpool(&mut self) {
|
||||
fn maybe_update_diagnostics(&mut self) {
|
||||
let subscriptions = self
|
||||
.mem_docs
|
||||
.keys()
|
||||
.iter()
|
||||
.map(|path| self.vfs.read().0.file_id(path).unwrap())
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
|
56
crates/rust-analyzer/src/mem_docs.rs
Normal file
56
crates/rust-analyzer/src/mem_docs.rs
Normal file
@ -0,0 +1,56 @@
|
||||
//! In-memory document information.
|
||||
|
||||
use rustc_hash::FxHashMap;
|
||||
use vfs::VfsPath;
|
||||
|
||||
/// Holds the set of in-memory documents.
|
||||
///
|
||||
/// For these document, there true contents is maintained by the client. It
|
||||
/// might be different from what's on disk.
|
||||
#[derive(Default, Clone)]
|
||||
pub(crate) struct MemDocs {
|
||||
mem_docs: FxHashMap<VfsPath, DocumentData>,
|
||||
}
|
||||
|
||||
impl MemDocs {
|
||||
pub(crate) fn contains(&self, path: &VfsPath) -> bool {
|
||||
self.mem_docs.contains_key(path)
|
||||
}
|
||||
pub(crate) fn insert(&mut self, path: VfsPath, data: DocumentData) -> Result<(), ()> {
|
||||
match self.mem_docs.insert(path, data) {
|
||||
Some(_) => Err(()),
|
||||
None => Ok(()),
|
||||
}
|
||||
}
|
||||
pub(crate) fn remove(&mut self, path: &VfsPath) -> Result<(), ()> {
|
||||
match self.mem_docs.remove(path) {
|
||||
Some(_) => Ok(()),
|
||||
None => Err(()),
|
||||
}
|
||||
}
|
||||
pub(crate) fn get(&self, path: &VfsPath) -> Option<&DocumentData> {
|
||||
self.mem_docs.get(path)
|
||||
}
|
||||
pub(crate) fn get_mut(&mut self, path: &VfsPath) -> Option<&mut DocumentData> {
|
||||
self.mem_docs.get_mut(path)
|
||||
}
|
||||
|
||||
pub(crate) fn iter(&self) -> impl Iterator<Item = &VfsPath> {
|
||||
self.mem_docs.keys()
|
||||
}
|
||||
}
|
||||
|
||||
/// Information about a document that the Language Client
|
||||
/// knows about.
|
||||
/// Its lifetime is driven by the textDocument/didOpen and textDocument/didClose
|
||||
/// client notifications.
|
||||
#[derive(Debug, Clone)]
|
||||
pub(crate) struct DocumentData {
|
||||
pub(crate) version: i32,
|
||||
}
|
||||
|
||||
impl DocumentData {
|
||||
pub(crate) fn new(version: i32) -> Self {
|
||||
DocumentData { version }
|
||||
}
|
||||
}
|
@ -403,7 +403,7 @@ fn eq_ignore_build_data<'a>(
|
||||
let mut load = |path: &AbsPath| {
|
||||
let _p = profile::span("GlobalState::load");
|
||||
let vfs_path = vfs::VfsPath::from(path.to_path_buf());
|
||||
if !mem_docs.contains_key(&vfs_path) {
|
||||
if !mem_docs.contains(&vfs_path) {
|
||||
let contents = loader.handle.load_sync(path);
|
||||
vfs.set_file_contents(vfs_path.clone(), contents);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user