aboutsummaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2020-08-25 10:27:22 +0100
committerAleksey Kladov <[email protected]>2020-08-25 10:43:21 +0100
commit3a72afed8cca3288fb955e66521f62f57aceace2 (patch)
tree5dcc5e12e667ab5972e37b0df313db2f6e9044f3 /crates
parentb4bc34649857cfcf7fcb39b9af02342fb7b8c89e (diff)
Improve logging
Diffstat (limited to 'crates')
-rw-r--r--crates/project_model/src/lib.rs16
-rw-r--r--crates/rust-analyzer/src/bin/main.rs13
-rw-r--r--crates/rust-analyzer/src/main_loop.rs10
-rw-r--r--crates/rust-analyzer/src/reload.rs5
4 files changed, 30 insertions, 14 deletions
diff --git a/crates/project_model/src/lib.rs b/crates/project_model/src/lib.rs
index 84d1303db..b601d7dc3 100644
--- a/crates/project_model/src/lib.rs
+++ b/crates/project_model/src/lib.rs
@@ -6,6 +6,7 @@ mod sysroot;
6mod cfg_flag; 6mod cfg_flag;
7 7
8use std::{ 8use std::{
9 fmt,
9 fs::{self, read_dir, ReadDir}, 10 fs::{self, read_dir, ReadDir},
10 io, 11 io,
11 process::Command, 12 process::Command,
@@ -27,7 +28,7 @@ pub use crate::{
27 28
28pub use proc_macro_api::ProcMacroClient; 29pub use proc_macro_api::ProcMacroClient;
29 30
30#[derive(Debug, Clone, Eq, PartialEq)] 31#[derive(Clone, Eq, PartialEq)]
31pub enum ProjectWorkspace { 32pub enum ProjectWorkspace {
32 /// Project workspace was discovered by running `cargo metadata` and `rustc --print sysroot`. 33 /// Project workspace was discovered by running `cargo metadata` and `rustc --print sysroot`.
33 Cargo { cargo: CargoWorkspace, sysroot: Sysroot }, 34 Cargo { cargo: CargoWorkspace, sysroot: Sysroot },
@@ -35,6 +36,19 @@ pub enum ProjectWorkspace {
35 Json { project: ProjectJson }, 36 Json { project: ProjectJson },
36} 37}
37 38
39impl fmt::Debug for ProjectWorkspace {
40 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
41 match self {
42 ProjectWorkspace::Cargo { cargo, .. } => {
43 f.debug_struct("Cargo").field("n_packages", &cargo.packages().len()).finish()
44 }
45 ProjectWorkspace::Json { project } => {
46 f.debug_struct("Json").field("n_crates", &project.crates.len()).finish()
47 }
48 }
49 }
50}
51
38/// `PackageRoot` describes a package root folder. 52/// `PackageRoot` describes a package root folder.
39/// Which may be an external dependency, or a member of 53/// Which may be an external dependency, or a member of
40/// the current workspace. 54/// the current workspace.
diff --git a/crates/rust-analyzer/src/bin/main.rs b/crates/rust-analyzer/src/bin/main.rs
index bade31ca2..0e03a0ca8 100644
--- a/crates/rust-analyzer/src/bin/main.rs
+++ b/crates/rust-analyzer/src/bin/main.rs
@@ -60,11 +60,12 @@ fn setup_logging() -> Result<()> {
60} 60}
61 61
62fn run_server() -> Result<()> { 62fn run_server() -> Result<()> {
63 log::info!("lifecycle: server started"); 63 log::info!("server will start");
64 64
65 let (connection, io_threads) = Connection::stdio(); 65 let (connection, io_threads) = Connection::stdio();
66 66
67 let (initialize_id, initialize_params) = connection.initialize_start()?; 67 let (initialize_id, initialize_params) = connection.initialize_start()?;
68 log::info!("InitializeParams: {}", initialize_params);
68 let initialize_params = 69 let initialize_params =
69 from_json::<lsp_types::InitializeParams>("InitializeParams", initialize_params)?; 70 from_json::<lsp_types::InitializeParams>("InitializeParams", initialize_params)?;
70 71
@@ -118,10 +119,9 @@ fn run_server() -> Result<()> {
118 .filter(|workspaces| !workspaces.is_empty()) 119 .filter(|workspaces| !workspaces.is_empty())
119 .unwrap_or_else(|| vec![config.root_path.clone()]); 120 .unwrap_or_else(|| vec![config.root_path.clone()]);
120 121
121 config.linked_projects = ProjectManifest::discover_all(&workspace_roots) 122 let discovered = ProjectManifest::discover_all(&workspace_roots);
122 .into_iter() 123 log::info!("discovered projects: {:?}", discovered);
123 .map(LinkedProject::from) 124 config.linked_projects = discovered.into_iter().map(LinkedProject::from).collect();
124 .collect();
125 } 125 }
126 126
127 config 127 config
@@ -129,8 +129,7 @@ fn run_server() -> Result<()> {
129 129
130 rust_analyzer::main_loop(config, connection)?; 130 rust_analyzer::main_loop(config, connection)?;
131 131
132 log::info!("shutting down IO...");
133 io_threads.join()?; 132 io_threads.join()?;
134 log::info!("... IO is down"); 133 log::info!("server did shut down");
135 Ok(()) 134 Ok(())
136} 135}
diff --git a/crates/rust-analyzer/src/main_loop.rs b/crates/rust-analyzer/src/main_loop.rs
index f039cdc31..355caaee2 100644
--- a/crates/rust-analyzer/src/main_loop.rs
+++ b/crates/rust-analyzer/src/main_loop.rs
@@ -10,6 +10,8 @@ use crossbeam_channel::{select, Receiver};
10use ide::{Canceled, FileId}; 10use ide::{Canceled, FileId};
11use lsp_server::{Connection, Notification, Request, Response}; 11use lsp_server::{Connection, Notification, Request, Response};
12use lsp_types::notification::Notification as _; 12use lsp_types::notification::Notification as _;
13use project_model::ProjectWorkspace;
14use vfs::ChangeKind;
13 15
14use crate::{ 16use crate::{
15 config::Config, 17 config::Config,
@@ -21,8 +23,6 @@ use crate::{
21 lsp_utils::{apply_document_changes, is_canceled, notification_is, Progress}, 23 lsp_utils::{apply_document_changes, is_canceled, notification_is, Progress},
22 Result, 24 Result,
23}; 25};
24use project_model::ProjectWorkspace;
25use vfs::ChangeKind;
26 26
27pub fn main_loop(config: Config, connection: Connection) -> Result<()> { 27pub fn main_loop(config: Config, connection: Connection) -> Result<()> {
28 log::info!("initial config: {:#?}", config); 28 log::info!("initial config: {:#?}", config);
@@ -175,9 +175,9 @@ impl GlobalState {
175 let _p = profile::span("GlobalState::handle_event"); 175 let _p = profile::span("GlobalState::handle_event");
176 176
177 log::info!("handle_event({:?})", event); 177 log::info!("handle_event({:?})", event);
178 let queue_count = self.task_pool.handle.len(); 178 let task_queue_len = self.task_pool.handle.len();
179 if queue_count > 0 { 179 if task_queue_len > 0 {
180 log::info!("queued count = {}", queue_count); 180 log::info!("task queue len: {}", task_queue_len);
181 } 181 }
182 182
183 let prev_status = self.status; 183 let prev_status = self.status;
diff --git a/crates/rust-analyzer/src/reload.rs b/crates/rust-analyzer/src/reload.rs
index 505505a77..20019b944 100644
--- a/crates/rust-analyzer/src/reload.rs
+++ b/crates/rust-analyzer/src/reload.rs
@@ -92,6 +92,7 @@ impl GlobalState {
92 } 92 }
93 } 93 }
94 pub(crate) fn fetch_workspaces(&mut self) { 94 pub(crate) fn fetch_workspaces(&mut self) {
95 log::info!("will fetch workspaces");
95 self.task_pool.handle.spawn({ 96 self.task_pool.handle.spawn({
96 let linked_projects = self.config.linked_projects.clone(); 97 let linked_projects = self.config.linked_projects.clone();
97 let cargo_config = self.config.cargo.clone(); 98 let cargo_config = self.config.cargo.clone();
@@ -112,13 +113,14 @@ impl GlobalState {
112 } 113 }
113 }) 114 })
114 .collect::<Vec<_>>(); 115 .collect::<Vec<_>>();
116 log::info!("did fetch workspaces {:?}", workspaces);
115 Task::Workspaces(workspaces) 117 Task::Workspaces(workspaces)
116 } 118 }
117 }); 119 });
118 } 120 }
119 pub(crate) fn switch_workspaces(&mut self, workspaces: Vec<anyhow::Result<ProjectWorkspace>>) { 121 pub(crate) fn switch_workspaces(&mut self, workspaces: Vec<anyhow::Result<ProjectWorkspace>>) {
120 let _p = profile::span("GlobalState::switch_workspaces"); 122 let _p = profile::span("GlobalState::switch_workspaces");
121 log::info!("reloading projects: {:?}", self.config.linked_projects); 123 log::info!("will switch workspaces: {:?}", workspaces);
122 124
123 let mut has_errors = false; 125 let mut has_errors = false;
124 let workspaces = workspaces 126 let workspaces = workspaces
@@ -223,6 +225,7 @@ impl GlobalState {
223 self.analysis_host.apply_change(change); 225 self.analysis_host.apply_change(change);
224 self.process_changes(); 226 self.process_changes();
225 self.reload_flycheck(); 227 self.reload_flycheck();
228 log::info!("did switch workspaces");
226 } 229 }
227 230
228 fn reload_flycheck(&mut self) { 231 fn reload_flycheck(&mut self) {