Merge #5520
5520: Add DocumentData to represent in-memory document with LSP info r=matklad a=kjeremy At the moment this only holds document version information but in the near-future it will hold other things like semantic token delta info. Co-authored-by: kjeremy <kjeremy@gmail.com>
This commit is contained in:
commit
a09a00a560
16
crates/rust-analyzer/src/document.rs
Normal file
16
crates/rust-analyzer/src/document.rs
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
//! 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 version: Option<i64>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl DocumentData {
|
||||||
|
pub fn new(version: i64) -> Self {
|
||||||
|
DocumentData { version: Some(version) }
|
||||||
|
}
|
||||||
|
}
|
@ -17,6 +17,7 @@ use rustc_hash::FxHashMap;
|
|||||||
use crate::{
|
use crate::{
|
||||||
config::Config,
|
config::Config,
|
||||||
diagnostics::{CheckFixes, DiagnosticCollection},
|
diagnostics::{CheckFixes, DiagnosticCollection},
|
||||||
|
document::DocumentData,
|
||||||
from_proto,
|
from_proto,
|
||||||
line_endings::LineEndings,
|
line_endings::LineEndings,
|
||||||
main_loop::Task,
|
main_loop::Task,
|
||||||
@ -69,7 +70,7 @@ pub(crate) struct GlobalState {
|
|||||||
pub(crate) config: Config,
|
pub(crate) config: Config,
|
||||||
pub(crate) analysis_host: AnalysisHost,
|
pub(crate) analysis_host: AnalysisHost,
|
||||||
pub(crate) diagnostics: DiagnosticCollection,
|
pub(crate) diagnostics: DiagnosticCollection,
|
||||||
pub(crate) mem_docs: FxHashMap<VfsPath, Option<i64>>,
|
pub(crate) mem_docs: FxHashMap<VfsPath, DocumentData>,
|
||||||
pub(crate) vfs: Arc<RwLock<(vfs::Vfs, FxHashMap<FileId, LineEndings>)>>,
|
pub(crate) vfs: Arc<RwLock<(vfs::Vfs, FxHashMap<FileId, LineEndings>)>>,
|
||||||
pub(crate) status: Status,
|
pub(crate) status: Status,
|
||||||
pub(crate) source_root_config: SourceRootConfig,
|
pub(crate) source_root_config: SourceRootConfig,
|
||||||
@ -84,7 +85,7 @@ pub(crate) struct GlobalStateSnapshot {
|
|||||||
pub(crate) analysis: Analysis,
|
pub(crate) analysis: Analysis,
|
||||||
pub(crate) check_fixes: CheckFixes,
|
pub(crate) check_fixes: CheckFixes,
|
||||||
pub(crate) latest_requests: Arc<RwLock<LatestRequests>>,
|
pub(crate) latest_requests: Arc<RwLock<LatestRequests>>,
|
||||||
mem_docs: FxHashMap<VfsPath, Option<i64>>,
|
mem_docs: FxHashMap<VfsPath, DocumentData>,
|
||||||
vfs: Arc<RwLock<(vfs::Vfs, FxHashMap<FileId, LineEndings>)>>,
|
vfs: Arc<RwLock<(vfs::Vfs, FxHashMap<FileId, LineEndings>)>>,
|
||||||
pub(crate) workspaces: Arc<Vec<ProjectWorkspace>>,
|
pub(crate) workspaces: Arc<Vec<ProjectWorkspace>>,
|
||||||
}
|
}
|
||||||
@ -259,7 +260,7 @@ impl GlobalStateSnapshot {
|
|||||||
|
|
||||||
pub(crate) fn url_file_version(&self, url: &Url) -> Option<i64> {
|
pub(crate) fn url_file_version(&self, url: &Url) -> Option<i64> {
|
||||||
let path = from_proto::vfs_path(&url).ok()?;
|
let path = from_proto::vfs_path(&url).ok()?;
|
||||||
self.mem_docs.get(&path).copied()?
|
self.mem_docs.get(&path)?.version
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn anchored_path(&self, file_id: FileId, path: &str) -> Url {
|
pub(crate) fn anchored_path(&self, file_id: FileId, path: &str) -> Url {
|
||||||
|
@ -33,6 +33,7 @@ mod line_endings;
|
|||||||
mod request_metrics;
|
mod request_metrics;
|
||||||
mod lsp_utils;
|
mod lsp_utils;
|
||||||
mod thread_pool;
|
mod thread_pool;
|
||||||
|
mod document;
|
||||||
pub mod lsp_ext;
|
pub mod lsp_ext;
|
||||||
pub mod config;
|
pub mod config;
|
||||||
|
|
||||||
|
@ -15,6 +15,7 @@ use ra_prof::profile;
|
|||||||
use crate::{
|
use crate::{
|
||||||
config::Config,
|
config::Config,
|
||||||
dispatch::{NotificationDispatcher, RequestDispatcher},
|
dispatch::{NotificationDispatcher, RequestDispatcher},
|
||||||
|
document::DocumentData,
|
||||||
from_proto,
|
from_proto,
|
||||||
global_state::{file_id_to_url, url_to_file_id, GlobalState, Status},
|
global_state::{file_id_to_url, url_to_file_id, GlobalState, Status},
|
||||||
handlers, lsp_ext,
|
handlers, lsp_ext,
|
||||||
@ -311,7 +312,7 @@ impl GlobalState {
|
|||||||
let url = file_id_to_url(&self.vfs.read().0, file_id);
|
let url = file_id_to_url(&self.vfs.read().0, file_id);
|
||||||
let diagnostics = self.diagnostics.diagnostics_for(file_id).cloned().collect();
|
let diagnostics = self.diagnostics.diagnostics_for(file_id).cloned().collect();
|
||||||
let version = from_proto::vfs_path(&url)
|
let version = from_proto::vfs_path(&url)
|
||||||
.map(|path| self.mem_docs.get(&path).copied().flatten())
|
.map(|path| self.mem_docs.get(&path)?.version)
|
||||||
.unwrap_or_default();
|
.unwrap_or_default();
|
||||||
|
|
||||||
self.send_notification::<lsp_types::notification::PublishDiagnostics>(
|
self.send_notification::<lsp_types::notification::PublishDiagnostics>(
|
||||||
@ -406,7 +407,7 @@ impl GlobalState {
|
|||||||
if let Ok(path) = from_proto::vfs_path(¶ms.text_document.uri) {
|
if let Ok(path) = from_proto::vfs_path(¶ms.text_document.uri) {
|
||||||
if this
|
if this
|
||||||
.mem_docs
|
.mem_docs
|
||||||
.insert(path.clone(), Some(params.text_document.version))
|
.insert(path.clone(), DocumentData::new(params.text_document.version))
|
||||||
.is_some()
|
.is_some()
|
||||||
{
|
{
|
||||||
log::error!("duplicate DidOpenTextDocument: {}", path)
|
log::error!("duplicate DidOpenTextDocument: {}", path)
|
||||||
@ -428,7 +429,7 @@ impl GlobalState {
|
|||||||
|
|
||||||
// The version passed in DidChangeTextDocument is the version after all edits are applied
|
// The version passed in DidChangeTextDocument is the version after all edits are applied
|
||||||
// so we should apply it before the vfs is notified.
|
// so we should apply it before the vfs is notified.
|
||||||
*doc = params.text_document.version;
|
doc.version = params.text_document.version;
|
||||||
|
|
||||||
vfs.set_file_contents(path.clone(), Some(text.into_bytes()));
|
vfs.set_file_contents(path.clone(), Some(text.into_bytes()));
|
||||||
}
|
}
|
||||||
@ -438,7 +439,7 @@ impl GlobalState {
|
|||||||
let mut version = None;
|
let mut version = None;
|
||||||
if let Ok(path) = from_proto::vfs_path(¶ms.text_document.uri) {
|
if let Ok(path) = from_proto::vfs_path(¶ms.text_document.uri) {
|
||||||
match this.mem_docs.remove(&path) {
|
match this.mem_docs.remove(&path) {
|
||||||
Some(entry) => version = entry,
|
Some(doc) => version = doc.version,
|
||||||
None => log::error!("orphan DidCloseTextDocument: {}", path),
|
None => log::error!("orphan DidCloseTextDocument: {}", path),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user