aboutsummaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2020-02-18 11:26:10 +0000
committerGitHub <[email protected]>2020-02-18 11:26:10 +0000
commit2768476e491d985317b08230824f96e6718f338a (patch)
tree08e5d3f64f545d402b1a9f4fe65330ca56e1d741 /crates
parenta349e5d4fcda1a6b96a09491a59d1ec940a48654 (diff)
parent4d307ff8024c8d2d533bc3ab7aac1d63ca5c5977 (diff)
Merge #3214
3214: Fully document ra_lsp_server r=matklad a=matklad Co-authored-by: Aleksey Kladov <[email protected]>
Diffstat (limited to 'crates')
-rw-r--r--crates/ra_lsp_server/Cargo.toml5
-rw-r--r--crates/ra_lsp_server/src/bin/args.rs (renamed from crates/ra_lsp_server/src/args.rs)0
-rw-r--r--crates/ra_lsp_server/src/bin/main.rs (renamed from crates/ra_lsp_server/src/main.rs)4
-rw-r--r--crates/ra_lsp_server/src/cargo_target_spec.rs113
-rw-r--r--crates/ra_lsp_server/src/cli.rs2
-rw-r--r--crates/ra_lsp_server/src/cli/analysis_bench.rs2
-rw-r--r--crates/ra_lsp_server/src/cli/analysis_stats.rs3
-rw-r--r--crates/ra_lsp_server/src/cli/load_cargo.rs18
-rw-r--r--crates/ra_lsp_server/src/conv.rs3
-rw-r--r--crates/ra_lsp_server/src/diagnostics.rs4
-rw-r--r--crates/ra_lsp_server/src/lib.rs7
-rw-r--r--crates/ra_lsp_server/src/main_loop.rs4
-rw-r--r--crates/ra_lsp_server/src/main_loop/handlers.rs10
-rw-r--r--crates/ra_lsp_server/src/main_loop/pending_requests.rs2
-rw-r--r--crates/ra_lsp_server/src/main_loop/subscriptions.rs3
-rw-r--r--crates/ra_lsp_server/src/vfs_glob.rs2
-rw-r--r--crates/ra_lsp_server/src/world.rs4
17 files changed, 105 insertions, 81 deletions
diff --git a/crates/ra_lsp_server/Cargo.toml b/crates/ra_lsp_server/Cargo.toml
index da523ba8a..151ca3da5 100644
--- a/crates/ra_lsp_server/Cargo.toml
+++ b/crates/ra_lsp_server/Cargo.toml
@@ -3,10 +3,15 @@ edition = "2018"
3name = "ra_lsp_server" 3name = "ra_lsp_server"
4version = "0.1.0" 4version = "0.1.0"
5authors = ["rust-analyzer developers"] 5authors = ["rust-analyzer developers"]
6autobins = false
6 7
7[lib] 8[lib]
8doctest = false 9doctest = false
9 10
11[[bin]]
12name = "ra_lsp_server"
13path = "./src/bin/main.rs"
14
10[dependencies] 15[dependencies]
11anyhow = "1.0" 16anyhow = "1.0"
12crossbeam-channel = "0.4" 17crossbeam-channel = "0.4"
diff --git a/crates/ra_lsp_server/src/args.rs b/crates/ra_lsp_server/src/bin/args.rs
index 3890fe13a..3890fe13a 100644
--- a/crates/ra_lsp_server/src/args.rs
+++ b/crates/ra_lsp_server/src/bin/args.rs
diff --git a/crates/ra_lsp_server/src/main.rs b/crates/ra_lsp_server/src/bin/main.rs
index a549e5ff1..e25d54a0d 100644
--- a/crates/ra_lsp_server/src/main.rs
+++ b/crates/ra_lsp_server/src/bin/main.rs
@@ -1,4 +1,6 @@
1//! `ra_lsp_server` binary 1//! Driver for rust-analyzer.
2//!
3//! Based on cli flags, either spawns an LSP server, or runs a batch analysis
2mod args; 4mod args;
3 5
4use lsp_server::Connection; 6use lsp_server::Connection;
diff --git a/crates/ra_lsp_server/src/cargo_target_spec.rs b/crates/ra_lsp_server/src/cargo_target_spec.rs
index 5fd1e7b6b..53751aafb 100644
--- a/crates/ra_lsp_server/src/cargo_target_spec.rs
+++ b/crates/ra_lsp_server/src/cargo_target_spec.rs
@@ -1,69 +1,74 @@
1//! FIXME: write short doc here 1//! See `CargoTargetSpec`
2 2
3use ra_ide::{FileId, RunnableKind, TestId}; 3use ra_ide::{FileId, RunnableKind, TestId};
4use ra_project_model::{self, ProjectWorkspace, TargetKind}; 4use ra_project_model::{self, ProjectWorkspace, TargetKind};
5 5
6use crate::{world::WorldSnapshot, Result}; 6use crate::{world::WorldSnapshot, Result};
7 7
8pub(crate) fn runnable_args( 8/// Abstract representation of Cargo target.
9 world: &WorldSnapshot, 9///
10 file_id: FileId, 10/// We use it to cook up the set of cli args we need to pass to Cargo to
11 kind: &RunnableKind, 11/// build/test/run the target.
12) -> Result<Vec<String>> { 12pub(crate) struct CargoTargetSpec {
13 let spec = CargoTargetSpec::for_file(world, file_id)?; 13 pub(crate) package: String,
14 let mut res = Vec::new(); 14 pub(crate) target: String,
15 match kind { 15 pub(crate) target_kind: TargetKind,
16 RunnableKind::Test { test_id } => { 16}
17 res.push("test".to_string()); 17
18 if let Some(spec) = spec { 18impl CargoTargetSpec {
19 spec.push_to(&mut res); 19 pub(crate) fn runnable_args(
20 spec: Option<CargoTargetSpec>,
21 kind: &RunnableKind,
22 ) -> Result<Vec<String>> {
23 let mut res = Vec::new();
24 match kind {
25 RunnableKind::Test { test_id } => {
26 res.push("test".to_string());
27 if let Some(spec) = spec {
28 spec.push_to(&mut res);
29 }
30 res.push("--".to_string());
31 res.push(test_id.to_string());
32 if let TestId::Path(_) = test_id {
33 res.push("--exact".to_string());
34 }
35 res.push("--nocapture".to_string());
20 } 36 }
21 res.push("--".to_string()); 37 RunnableKind::TestMod { path } => {
22 res.push(test_id.to_string()); 38 res.push("test".to_string());
23 if let TestId::Path(_) = test_id { 39 if let Some(spec) = spec {
24 res.push("--exact".to_string()); 40 spec.push_to(&mut res);
41 }
42 res.push("--".to_string());
43 res.push(path.to_string());
44 res.push("--nocapture".to_string());
25 } 45 }
26 res.push("--nocapture".to_string()); 46 RunnableKind::Bench { test_id } => {
27 } 47 res.push("bench".to_string());
28 RunnableKind::TestMod { path } => { 48 if let Some(spec) = spec {
29 res.push("test".to_string()); 49 spec.push_to(&mut res);
30 if let Some(spec) = spec { 50 }
31 spec.push_to(&mut res); 51 res.push("--".to_string());
52 res.push(test_id.to_string());
53 if let TestId::Path(_) = test_id {
54 res.push("--exact".to_string());
55 }
56 res.push("--nocapture".to_string());
32 } 57 }
33 res.push("--".to_string()); 58 RunnableKind::Bin => {
34 res.push(path.to_string()); 59 res.push("run".to_string());
35 res.push("--nocapture".to_string()); 60 if let Some(spec) = spec {
36 } 61 spec.push_to(&mut res);
37 RunnableKind::Bench { test_id } => { 62 }
38 res.push("bench".to_string());
39 if let Some(spec) = spec {
40 spec.push_to(&mut res);
41 }
42 res.push("--".to_string());
43 res.push(test_id.to_string());
44 if let TestId::Path(_) = test_id {
45 res.push("--exact".to_string());
46 }
47 res.push("--nocapture".to_string());
48 }
49 RunnableKind::Bin => {
50 res.push("run".to_string());
51 if let Some(spec) = spec {
52 spec.push_to(&mut res);
53 } 63 }
54 } 64 }
65 Ok(res)
55 } 66 }
56 Ok(res)
57}
58 67
59pub struct CargoTargetSpec { 68 pub(crate) fn for_file(
60 pub package: String, 69 world: &WorldSnapshot,
61 pub target: String, 70 file_id: FileId,
62 pub target_kind: TargetKind, 71 ) -> Result<Option<CargoTargetSpec>> {
63}
64
65impl CargoTargetSpec {
66 pub fn for_file(world: &WorldSnapshot, file_id: FileId) -> Result<Option<CargoTargetSpec>> {
67 let &crate_id = match world.analysis().crate_for(file_id)?.first() { 72 let &crate_id = match world.analysis().crate_for(file_id)?.first() {
68 Some(crate_id) => crate_id, 73 Some(crate_id) => crate_id,
69 None => return Ok(None), 74 None => return Ok(None),
@@ -84,7 +89,7 @@ impl CargoTargetSpec {
84 Ok(res) 89 Ok(res)
85 } 90 }
86 91
87 pub fn push_to(self, buf: &mut Vec<String>) { 92 pub(crate) fn push_to(self, buf: &mut Vec<String>) {
88 buf.push("--package".to_string()); 93 buf.push("--package".to_string());
89 buf.push(self.package); 94 buf.push(self.package);
90 match self.target_kind { 95 match self.target_kind {
diff --git a/crates/ra_lsp_server/src/cli.rs b/crates/ra_lsp_server/src/cli.rs
index 3c7b8e250..c9738d101 100644
--- a/crates/ra_lsp_server/src/cli.rs
+++ b/crates/ra_lsp_server/src/cli.rs
@@ -1,4 +1,4 @@
1//! FIXME: write short doc here 1//! Various batch processing tasks, intended primarily for debugging.
2 2
3mod load_cargo; 3mod load_cargo;
4mod analysis_stats; 4mod analysis_stats;
diff --git a/crates/ra_lsp_server/src/cli/analysis_bench.rs b/crates/ra_lsp_server/src/cli/analysis_bench.rs
index e00f81073..91855e592 100644
--- a/crates/ra_lsp_server/src/cli/analysis_bench.rs
+++ b/crates/ra_lsp_server/src/cli/analysis_bench.rs
@@ -1,4 +1,4 @@
1//! FIXME: write short doc here 1//! Benchmark operations like highlighting or goto definition.
2 2
3use std::{ 3use std::{
4 path::{Path, PathBuf}, 4 path::{Path, PathBuf},
diff --git a/crates/ra_lsp_server/src/cli/analysis_stats.rs b/crates/ra_lsp_server/src/cli/analysis_stats.rs
index c27fabe3c..99ab6e443 100644
--- a/crates/ra_lsp_server/src/cli/analysis_stats.rs
+++ b/crates/ra_lsp_server/src/cli/analysis_stats.rs
@@ -1,4 +1,5 @@
1//! FIXME: write short doc here 1//! Fully type-check project and print various stats, like the number of type
2//! errors.
2 3
3use std::{collections::HashSet, fmt::Write, path::Path, time::Instant}; 4use std::{collections::HashSet, fmt::Write, path::Path, time::Instant};
4 5
diff --git a/crates/ra_lsp_server/src/cli/load_cargo.rs b/crates/ra_lsp_server/src/cli/load_cargo.rs
index bb3e1513b..8cd08ecb6 100644
--- a/crates/ra_lsp_server/src/cli/load_cargo.rs
+++ b/crates/ra_lsp_server/src/cli/load_cargo.rs
@@ -1,18 +1,18 @@
1//! FIXME: write short doc here 1//! Loads a Cargo project into a static instance of analysis, without support
2//! for incorporating changes.
2 3
3use std::{collections::HashSet, path::Path}; 4use std::path::Path;
4 5
6use anyhow::Result;
5use crossbeam_channel::{unbounded, Receiver}; 7use crossbeam_channel::{unbounded, Receiver};
6use ra_db::{CrateGraph, FileId, SourceRootId}; 8use ra_db::{CrateGraph, FileId, SourceRootId};
7use ra_ide::{AnalysisChange, AnalysisHost, FeatureFlags}; 9use ra_ide::{AnalysisChange, AnalysisHost, FeatureFlags};
8use ra_project_model::{get_rustc_cfg_options, PackageRoot, ProjectWorkspace}; 10use ra_project_model::{get_rustc_cfg_options, PackageRoot, ProjectWorkspace};
9use ra_vfs::{RootEntry, Vfs, VfsChange, VfsTask, Watch}; 11use ra_vfs::{RootEntry, Vfs, VfsChange, VfsTask, Watch};
10use rustc_hash::FxHashMap; 12use rustc_hash::{FxHashMap, FxHashSet};
11 13
12use crate::vfs_glob::RustPackageFilterBuilder; 14use crate::vfs_glob::RustPackageFilterBuilder;
13 15
14use anyhow::Result;
15
16fn vfs_file_to_id(f: ra_vfs::VfsFile) -> FileId { 16fn vfs_file_to_id(f: ra_vfs::VfsFile) -> FileId {
17 FileId(f.0) 17 FileId(f.0)
18} 18}
@@ -20,7 +20,9 @@ fn vfs_root_to_id(r: ra_vfs::VfsRoot) -> SourceRootId {
20 SourceRootId(r.0) 20 SourceRootId(r.0)
21} 21}
22 22
23pub fn load_cargo(root: &Path) -> Result<(AnalysisHost, FxHashMap<SourceRootId, PackageRoot>)> { 23pub(crate) fn load_cargo(
24 root: &Path,
25) -> Result<(AnalysisHost, FxHashMap<SourceRootId, PackageRoot>)> {
24 let root = std::env::current_dir()?.join(root); 26 let root = std::env::current_dir()?.join(root);
25 let ws = ProjectWorkspace::discover(root.as_ref(), &Default::default())?; 27 let ws = ProjectWorkspace::discover(root.as_ref(), &Default::default())?;
26 let project_roots = ws.to_roots(); 28 let project_roots = ws.to_roots();
@@ -74,7 +76,7 @@ pub fn load_cargo(root: &Path) -> Result<(AnalysisHost, FxHashMap<SourceRootId,
74 Ok((host, source_roots)) 76 Ok((host, source_roots))
75} 77}
76 78
77pub fn load( 79pub(crate) fn load(
78 source_roots: &FxHashMap<SourceRootId, PackageRoot>, 80 source_roots: &FxHashMap<SourceRootId, PackageRoot>,
79 crate_graph: CrateGraph, 81 crate_graph: CrateGraph,
80 vfs: &mut Vfs, 82 vfs: &mut Vfs,
@@ -86,7 +88,7 @@ pub fn load(
86 analysis_change.set_crate_graph(crate_graph); 88 analysis_change.set_crate_graph(crate_graph);
87 89
88 // wait until Vfs has loaded all roots 90 // wait until Vfs has loaded all roots
89 let mut roots_loaded = HashSet::new(); 91 let mut roots_loaded = FxHashSet::default();
90 for task in receiver { 92 for task in receiver {
91 vfs.handle_task(task); 93 vfs.handle_task(task);
92 let mut done = false; 94 let mut done = false;
diff --git a/crates/ra_lsp_server/src/conv.rs b/crates/ra_lsp_server/src/conv.rs
index 8af74b211..90ef74056 100644
--- a/crates/ra_lsp_server/src/conv.rs
+++ b/crates/ra_lsp_server/src/conv.rs
@@ -1,4 +1,5 @@
1//! Convenience module responsible for translating between rust-analyzer's types and LSP types. 1//! Convenience module responsible for translating between rust-analyzer's types
2//! and LSP types.
2 3
3use lsp_types::{ 4use lsp_types::{
4 self, CreateFile, DiagnosticSeverity, DocumentChangeOperation, DocumentChanges, Documentation, 5 self, CreateFile, DiagnosticSeverity, DocumentChangeOperation, DocumentChanges, Documentation,
diff --git a/crates/ra_lsp_server/src/diagnostics.rs b/crates/ra_lsp_server/src/diagnostics.rs
index ea08bce24..e7924f0a3 100644
--- a/crates/ra_lsp_server/src/diagnostics.rs
+++ b/crates/ra_lsp_server/src/diagnostics.rs
@@ -1,7 +1,9 @@
1//! Book keeping for keeping diagnostics easily in sync with the client. 1//! Book keeping for keeping diagnostics easily in sync with the client.
2
3use std::{collections::HashMap, sync::Arc};
4
2use lsp_types::{CodeActionOrCommand, Diagnostic, Range}; 5use lsp_types::{CodeActionOrCommand, Diagnostic, Range};
3use ra_ide::FileId; 6use ra_ide::FileId;
4use std::{collections::HashMap, sync::Arc};
5 7
6pub type CheckFixes = Arc<HashMap<FileId, Vec<Fix>>>; 8pub type CheckFixes = Arc<HashMap<FileId, Vec<Fix>>>;
7 9
diff --git a/crates/ra_lsp_server/src/lib.rs b/crates/ra_lsp_server/src/lib.rs
index 958c70fe5..0dae30e46 100644
--- a/crates/ra_lsp_server/src/lib.rs
+++ b/crates/ra_lsp_server/src/lib.rs
@@ -1,10 +1,13 @@
1//! Implementation of the LSP for rust-analyzer. 1//! Implementation of the LSP for rust-analyzer.
2//! 2//!
3//! This crate takes Rust-specific analysis results from ra_ide and 3//! This crate takes Rust-specific analysis results from ra_ide and translates
4//! translates into LSP types. 4//! into LSP types.
5//! 5//!
6//! It also is the root of all state. `world` module defines the bulk of the 6//! It also is the root of all state. `world` module defines the bulk of the
7//! state, and `main_loop` module defines the rules for modifying it. 7//! state, and `main_loop` module defines the rules for modifying it.
8//!
9//! The `cli` submodule implements some batch-processing analysis, primarily as
10//! a debugging aid.
8#![recursion_limit = "512"] 11#![recursion_limit = "512"]
9 12
10pub mod cli; 13pub mod cli;
diff --git a/crates/ra_lsp_server/src/main_loop.rs b/crates/ra_lsp_server/src/main_loop.rs
index 944074118..67d8a5f6f 100644
--- a/crates/ra_lsp_server/src/main_loop.rs
+++ b/crates/ra_lsp_server/src/main_loop.rs
@@ -1,5 +1,5 @@
1//! The main loop of `ra_lsp_server` responsible for dispatching LSP requests/replies and 1//! The main loop of `ra_lsp_server` responsible for dispatching LSP
2//! notifications back to the client. 2//! requests/replies and notifications back to the client.
3 3
4mod handlers; 4mod handlers;
5mod subscriptions; 5mod subscriptions;
diff --git a/crates/ra_lsp_server/src/main_loop/handlers.rs b/crates/ra_lsp_server/src/main_loop/handlers.rs
index ae51141cb..bb7bab372 100644
--- a/crates/ra_lsp_server/src/main_loop/handlers.rs
+++ b/crates/ra_lsp_server/src/main_loop/handlers.rs
@@ -1,5 +1,6 @@
1//! This module is responsible for implementing handlers for Lanuage Server Protocol. 1//! This module is responsible for implementing handlers for Language Server
2//! The majority of requests are fulfilled by calling into the `ra_ide` crate. 2//! Protocol. The majority of requests are fulfilled by calling into the
3//! `ra_ide` crate.
3 4
4use std::{ 5use std::{
5 collections::hash_map::Entry, 6 collections::hash_map::Entry,
@@ -29,7 +30,7 @@ use serde::{Deserialize, Serialize};
29use serde_json::to_value; 30use serde_json::to_value;
30 31
31use crate::{ 32use crate::{
32 cargo_target_spec::{runnable_args, CargoTargetSpec}, 33 cargo_target_spec::CargoTargetSpec,
33 conv::{ 34 conv::{
34 to_call_hierarchy_item, to_location, Conv, ConvWith, FoldConvCtx, MapConvWith, TryConvWith, 35 to_call_hierarchy_item, to_location, Conv, ConvWith, FoldConvCtx, MapConvWith, TryConvWith,
35 TryConvWithToVec, 36 TryConvWithToVec,
@@ -921,7 +922,8 @@ fn to_lsp_runnable(
921 file_id: FileId, 922 file_id: FileId,
922 runnable: Runnable, 923 runnable: Runnable,
923) -> Result<req::Runnable> { 924) -> Result<req::Runnable> {
924 let args = runnable_args(world, file_id, &runnable.kind)?; 925 let spec = CargoTargetSpec::for_file(world, file_id)?;
926 let args = CargoTargetSpec::runnable_args(spec, &runnable.kind)?;
925 let line_index = world.analysis().file_line_index(file_id)?; 927 let line_index = world.analysis().file_line_index(file_id)?;
926 let label = match &runnable.kind { 928 let label = match &runnable.kind {
927 RunnableKind::Test { test_id } => format!("test {}", test_id), 929 RunnableKind::Test { test_id } => format!("test {}", test_id),
diff --git a/crates/ra_lsp_server/src/main_loop/pending_requests.rs b/crates/ra_lsp_server/src/main_loop/pending_requests.rs
index 2d2213464..73b33e419 100644
--- a/crates/ra_lsp_server/src/main_loop/pending_requests.rs
+++ b/crates/ra_lsp_server/src/main_loop/pending_requests.rs
@@ -1,4 +1,4 @@
1//! Datastructures that keep track of inflight requests. 1//! Data structures that keep track of inflight requests.
2 2
3use std::time::{Duration, Instant}; 3use std::time::{Duration, Instant};
4 4
diff --git a/crates/ra_lsp_server/src/main_loop/subscriptions.rs b/crates/ra_lsp_server/src/main_loop/subscriptions.rs
index b0bae90f5..bee6437cf 100644
--- a/crates/ra_lsp_server/src/main_loop/subscriptions.rs
+++ b/crates/ra_lsp_server/src/main_loop/subscriptions.rs
@@ -1,4 +1,5 @@
1//! Keeps track of file subscriptions. 1//! Keeps track of file subscriptions -- the set of currently opened files for
2//! which we want to publish diagnostics, syntax highlighting, etc.
2 3
3use ra_ide::FileId; 4use ra_ide::FileId;
4use rustc_hash::FxHashSet; 5use rustc_hash::FxHashSet;
diff --git a/crates/ra_lsp_server/src/vfs_glob.rs b/crates/ra_lsp_server/src/vfs_glob.rs
index 12401d75a..91b33f94e 100644
--- a/crates/ra_lsp_server/src/vfs_glob.rs
+++ b/crates/ra_lsp_server/src/vfs_glob.rs
@@ -1,4 +1,4 @@
1//! `ra_vfs_glob` crate implements exclusion rules for vfs. 1//! Exclusion rules for vfs.
2//! 2//!
3//! By default, we include only `.rs` files, and skip some know offenders like 3//! By default, we include only `.rs` files, and skip some know offenders like
4//! `/target` or `/node_modules` altogether. 4//! `/target` or `/node_modules` altogether.
diff --git a/crates/ra_lsp_server/src/world.rs b/crates/ra_lsp_server/src/world.rs
index 71c95d4af..96efab844 100644
--- a/crates/ra_lsp_server/src/world.rs
+++ b/crates/ra_lsp_server/src/world.rs
@@ -1,5 +1,5 @@
1//! The context or environment in which the language server functions. 1//! The context or environment in which the language server functions. In our
2//! In our server implementation this is know as the `WorldState`. 2//! server implementation this is know as the `WorldState`.
3//! 3//!
4//! Each tick provides an immutable snapshot of the state as `WorldSnapshot`. 4//! Each tick provides an immutable snapshot of the state as `WorldSnapshot`.
5 5