aboutsummaryrefslogtreecommitdiff
path: root/crates/server/src/server_world.rs
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2018-09-04 09:40:45 +0100
committerAleksey Kladov <[email protected]>2018-09-04 09:40:45 +0100
commit3a017aaa52fc41316b5dd2cd90b5171ca869697a (patch)
tree5017726e5ff94bfdb769bb31ff7ec5a7b8270f57 /crates/server/src/server_world.rs
parenta668f703fa5361f59a170d40be667c7e59a4a3e5 (diff)
dont change readonly files
Diffstat (limited to 'crates/server/src/server_world.rs')
-rw-r--r--crates/server/src/server_world.rs20
1 files changed, 13 insertions, 7 deletions
diff --git a/crates/server/src/server_world.rs b/crates/server/src/server_world.rs
index 729418eaa..8ceec594f 100644
--- a/crates/server/src/server_world.rs
+++ b/crates/server/src/server_world.rs
@@ -10,7 +10,7 @@ use libanalysis::{FileId, AnalysisHost, Analysis, CrateGraph, CrateId, LibraryDa
10 10
11use { 11use {
12 Result, 12 Result,
13 path_map::PathMap, 13 path_map::{PathMap, Root},
14 vfs::{FileEvent, FileEventKind}, 14 vfs::{FileEvent, FileEventKind},
15 project_model::CargoWorkspace, 15 project_model::CargoWorkspace,
16}; 16};
@@ -51,7 +51,7 @@ impl ServerWorldState {
51 (event.path, text) 51 (event.path, text)
52 }) 52 })
53 .map(|(path, text)| { 53 .map(|(path, text)| {
54 (pm.get_or_insert(path), text) 54 (pm.get_or_insert(path, Root::Workspace), text)
55 }) 55 })
56 .filter_map(|(id, text)| { 56 .filter_map(|(id, text)| {
57 if mm.contains_key(&id) { 57 if mm.contains_key(&id) {
@@ -73,7 +73,7 @@ impl ServerWorldState {
73 }; 73 };
74 (event.path, text) 74 (event.path, text)
75 }) 75 })
76 .map(|(path, text)| (pm.get_or_insert(path), text)) 76 .map(|(path, text)| (pm.get_or_insert(path, Root::Lib), text))
77 .collect() 77 .collect()
78 } 78 }
79 pub fn add_lib(&mut self, data: LibraryData) { 79 pub fn add_lib(&mut self, data: LibraryData) {
@@ -81,9 +81,11 @@ impl ServerWorldState {
81 } 81 }
82 82
83 pub fn add_mem_file(&mut self, path: PathBuf, text: String) -> FileId { 83 pub fn add_mem_file(&mut self, path: PathBuf, text: String) -> FileId {
84 let file_id = self.path_map.get_or_insert(path); 84 let file_id = self.path_map.get_or_insert(path, Root::Workspace);
85 self.mem_map.insert(file_id, None); 85 self.mem_map.insert(file_id, None);
86 self.analysis_host.change_file(file_id, Some(text)); 86 if self.path_map.get_root(file_id) != Root::Lib {
87 self.analysis_host.change_file(file_id, Some(text));
88 }
87 file_id 89 file_id
88 } 90 }
89 91
@@ -91,7 +93,9 @@ impl ServerWorldState {
91 let file_id = self.path_map.get_id(path).ok_or_else(|| { 93 let file_id = self.path_map.get_id(path).ok_or_else(|| {
92 format_err!("change to unknown file: {}", path.display()) 94 format_err!("change to unknown file: {}", path.display())
93 })?; 95 })?;
94 self.analysis_host.change_file(file_id, Some(text)); 96 if self.path_map.get_root(file_id) != Root::Lib {
97 self.analysis_host.change_file(file_id, Some(text));
98 }
95 Ok(()) 99 Ok(())
96 } 100 }
97 101
@@ -105,7 +109,9 @@ impl ServerWorldState {
105 }; 109 };
106 // Do this via file watcher ideally. 110 // Do this via file watcher ideally.
107 let text = fs::read_to_string(path).ok(); 111 let text = fs::read_to_string(path).ok();
108 self.analysis_host.change_file(file_id, text); 112 if self.path_map.get_root(file_id) != Root::Lib {
113 self.analysis_host.change_file(file_id, text);
114 }
109 Ok(file_id) 115 Ok(file_id)
110 } 116 }
111 pub fn set_workspaces(&mut self, ws: Vec<CargoWorkspace>) { 117 pub fn set_workspaces(&mut self, ws: Vec<CargoWorkspace>) {