diff options
author | kjeremy <[email protected]> | 2020-07-21 19:07:42 +0100 |
---|---|---|
committer | kjeremy <[email protected]> | 2020-07-21 19:07:42 +0100 |
commit | 97927146dbdcd17a1569f0bb8a4b56fcf347f03c (patch) | |
tree | 0a19d63338165d23b4aa9a994b2feebbf020bb76 /crates/rust-analyzer/src/global_state.rs | |
parent | 65b89b5471879a80fb6003c9fa0f8f93e2eb38e6 (diff) |
Store document version and pass back to the client
Diffstat (limited to 'crates/rust-analyzer/src/global_state.rs')
-rw-r--r-- | crates/rust-analyzer/src/global_state.rs | 13 |
1 files changed, 10 insertions, 3 deletions
diff --git a/crates/rust-analyzer/src/global_state.rs b/crates/rust-analyzer/src/global_state.rs index 94973b90a..80937dbc4 100644 --- a/crates/rust-analyzer/src/global_state.rs +++ b/crates/rust-analyzer/src/global_state.rs | |||
@@ -12,7 +12,7 @@ use parking_lot::RwLock; | |||
12 | use ra_db::{CrateId, VfsPath}; | 12 | use ra_db::{CrateId, VfsPath}; |
13 | use ra_ide::{Analysis, AnalysisChange, AnalysisHost, FileId}; | 13 | use ra_ide::{Analysis, AnalysisChange, AnalysisHost, FileId}; |
14 | use ra_project_model::{CargoWorkspace, ProcMacroClient, ProjectWorkspace, Target}; | 14 | use ra_project_model::{CargoWorkspace, ProcMacroClient, ProjectWorkspace, Target}; |
15 | use rustc_hash::{FxHashMap, FxHashSet}; | 15 | use rustc_hash::FxHashMap; |
16 | 16 | ||
17 | use crate::{ | 17 | use crate::{ |
18 | config::Config, | 18 | config::Config, |
@@ -69,7 +69,7 @@ pub(crate) struct GlobalState { | |||
69 | pub(crate) config: Config, | 69 | pub(crate) config: Config, |
70 | pub(crate) analysis_host: AnalysisHost, | 70 | pub(crate) analysis_host: AnalysisHost, |
71 | pub(crate) diagnostics: DiagnosticCollection, | 71 | pub(crate) diagnostics: DiagnosticCollection, |
72 | pub(crate) mem_docs: FxHashSet<VfsPath>, | 72 | pub(crate) mem_docs: FxHashMap<VfsPath, Option<i64>>, |
73 | pub(crate) vfs: Arc<RwLock<(vfs::Vfs, FxHashMap<FileId, LineEndings>)>>, | 73 | pub(crate) vfs: Arc<RwLock<(vfs::Vfs, FxHashMap<FileId, LineEndings>)>>, |
74 | pub(crate) status: Status, | 74 | pub(crate) status: Status, |
75 | pub(crate) source_root_config: SourceRootConfig, | 75 | pub(crate) source_root_config: SourceRootConfig, |
@@ -84,6 +84,7 @@ pub(crate) struct GlobalStateSnapshot { | |||
84 | pub(crate) analysis: Analysis, | 84 | pub(crate) analysis: Analysis, |
85 | pub(crate) check_fixes: CheckFixes, | 85 | pub(crate) check_fixes: CheckFixes, |
86 | pub(crate) latest_requests: Arc<RwLock<LatestRequests>>, | 86 | pub(crate) latest_requests: Arc<RwLock<LatestRequests>>, |
87 | mem_docs: FxHashMap<VfsPath, Option<i64>>, | ||
87 | vfs: Arc<RwLock<(vfs::Vfs, FxHashMap<FileId, LineEndings>)>>, | 88 | vfs: Arc<RwLock<(vfs::Vfs, FxHashMap<FileId, LineEndings>)>>, |
88 | pub(crate) workspaces: Arc<Vec<ProjectWorkspace>>, | 89 | pub(crate) workspaces: Arc<Vec<ProjectWorkspace>>, |
89 | } | 90 | } |
@@ -117,7 +118,7 @@ impl GlobalState { | |||
117 | config, | 118 | config, |
118 | analysis_host, | 119 | analysis_host, |
119 | diagnostics: Default::default(), | 120 | diagnostics: Default::default(), |
120 | mem_docs: FxHashSet::default(), | 121 | mem_docs: FxHashMap::default(), |
121 | vfs: Arc::new(RwLock::new((vfs::Vfs::default(), FxHashMap::default()))), | 122 | vfs: Arc::new(RwLock::new((vfs::Vfs::default(), FxHashMap::default()))), |
122 | status: Status::default(), | 123 | status: Status::default(), |
123 | source_root_config: SourceRootConfig::default(), | 124 | source_root_config: SourceRootConfig::default(), |
@@ -183,6 +184,7 @@ impl GlobalState { | |||
183 | vfs: Arc::clone(&self.vfs), | 184 | vfs: Arc::clone(&self.vfs), |
184 | latest_requests: Arc::clone(&self.latest_requests), | 185 | latest_requests: Arc::clone(&self.latest_requests), |
185 | check_fixes: Arc::clone(&self.diagnostics.check_fixes), | 186 | check_fixes: Arc::clone(&self.diagnostics.check_fixes), |
187 | mem_docs: self.mem_docs.clone(), | ||
186 | } | 188 | } |
187 | } | 189 | } |
188 | 190 | ||
@@ -255,6 +257,11 @@ impl GlobalStateSnapshot { | |||
255 | self.vfs.read().1[&id] | 257 | self.vfs.read().1[&id] |
256 | } | 258 | } |
257 | 259 | ||
260 | pub(crate) fn url_file_version(&self, url: &Url) -> Option<i64> { | ||
261 | let path = from_proto::vfs_path(&url).ok()?; | ||
262 | self.mem_docs.get(&path).copied()? | ||
263 | } | ||
264 | |||
258 | pub(crate) fn anchored_path(&self, file_id: FileId, path: &str) -> Url { | 265 | pub(crate) fn anchored_path(&self, file_id: FileId, path: &str) -> Url { |
259 | let mut base = self.vfs.read().0.file_path(file_id); | 266 | let mut base = self.vfs.read().0.file_path(file_id); |
260 | base.pop(); | 267 | base.pop(); |