diff options
-rw-r--r-- | Cargo.lock | 8 | ||||
-rw-r--r-- | crates/ra_batch/Cargo.toml | 2 | ||||
-rw-r--r-- | crates/ra_batch/src/lib.rs | 29 | ||||
-rw-r--r-- | crates/ra_lsp_server/Cargo.toml | 2 | ||||
-rw-r--r-- | crates/ra_lsp_server/src/server_world.rs | 30 | ||||
-rw-r--r-- | crates/tools/src/main.rs | 41 | ||||
-rw-r--r-- | editors/code/package.json | 5 | ||||
-rw-r--r-- | editors/code/src/commands/runnables.ts | 91 | ||||
-rw-r--r-- | editors/code/src/config.ts | 8 | ||||
-rw-r--r-- | editors/code/src/extension.ts | 4 |
10 files changed, 207 insertions, 13 deletions
diff --git a/Cargo.lock b/Cargo.lock index 6f4c4f767..ad9f6970b 100644 --- a/Cargo.lock +++ b/Cargo.lock | |||
@@ -928,7 +928,7 @@ dependencies = [ | |||
928 | "ra_hir 0.1.0", | 928 | "ra_hir 0.1.0", |
929 | "ra_project_model 0.1.0", | 929 | "ra_project_model 0.1.0", |
930 | "ra_syntax 0.1.0", | 930 | "ra_syntax 0.1.0", |
931 | "ra_vfs 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", | 931 | "ra_vfs 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", |
932 | "rustc-hash 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)", | 932 | "rustc-hash 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)", |
933 | "test_utils 0.1.0", | 933 | "test_utils 0.1.0", |
934 | ] | 934 | ] |
@@ -1050,7 +1050,7 @@ dependencies = [ | |||
1050 | "ra_project_model 0.1.0", | 1050 | "ra_project_model 0.1.0", |
1051 | "ra_syntax 0.1.0", | 1051 | "ra_syntax 0.1.0", |
1052 | "ra_text_edit 0.1.0", | 1052 | "ra_text_edit 0.1.0", |
1053 | "ra_vfs 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", | 1053 | "ra_vfs 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", |
1054 | "relative-path 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", | 1054 | "relative-path 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", |
1055 | "rustc-hash 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)", | 1055 | "rustc-hash 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)", |
1056 | "serde 1.0.89 (registry+https://github.com/rust-lang/crates.io-index)", | 1056 | "serde 1.0.89 (registry+https://github.com/rust-lang/crates.io-index)", |
@@ -1131,7 +1131,7 @@ dependencies = [ | |||
1131 | 1131 | ||
1132 | [[package]] | 1132 | [[package]] |
1133 | name = "ra_vfs" | 1133 | name = "ra_vfs" |
1134 | version = "0.1.1" | 1134 | version = "0.2.0" |
1135 | source = "registry+https://github.com/rust-lang/crates.io-index" | 1135 | source = "registry+https://github.com/rust-lang/crates.io-index" |
1136 | dependencies = [ | 1136 | dependencies = [ |
1137 | "crossbeam-channel 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", | 1137 | "crossbeam-channel 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", |
@@ -1996,7 +1996,7 @@ dependencies = [ | |||
1996 | "checksum proptest 0.9.1 (registry+https://github.com/rust-lang/crates.io-index)" = "8ea66c78d75f2c6e9f304269eaef90899798daecc69f1a625d5a3dd793ff3522" | 1996 | "checksum proptest 0.9.1 (registry+https://github.com/rust-lang/crates.io-index)" = "8ea66c78d75f2c6e9f304269eaef90899798daecc69f1a625d5a3dd793ff3522" |
1997 | "checksum quick-error 1.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "9274b940887ce9addde99c4eee6b5c44cc494b182b97e73dc8ffdcb3397fd3f0" | 1997 | "checksum quick-error 1.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "9274b940887ce9addde99c4eee6b5c44cc494b182b97e73dc8ffdcb3397fd3f0" |
1998 | "checksum quote 0.6.11 (registry+https://github.com/rust-lang/crates.io-index)" = "cdd8e04bd9c52e0342b406469d494fcb033be4bdbe5c606016defbb1681411e1" | 1998 | "checksum quote 0.6.11 (registry+https://github.com/rust-lang/crates.io-index)" = "cdd8e04bd9c52e0342b406469d494fcb033be4bdbe5c606016defbb1681411e1" |
1999 | "checksum ra_vfs 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "5978b0ced52f013ce44bfca6ac903141359e7cc3baea462a4a670de9e5087101" | 1999 | "checksum ra_vfs 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "bb1839e4e003d865b58b8b6c231aae6c463dfcd01bfbbddffbdb7662a7b5a627" |
2000 | "checksum rand 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)" = "6d71dacdc3c88c1fde3885a3be3fbab9f35724e6ce99467f7d9c5026132184ca" | 2000 | "checksum rand 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)" = "6d71dacdc3c88c1fde3885a3be3fbab9f35724e6ce99467f7d9c5026132184ca" |
2001 | "checksum rand_chacha 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "556d3a1ca6600bfcbab7c7c91ccb085ac7fbbcd70e008a98742e7847f4f7bcef" | 2001 | "checksum rand_chacha 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "556d3a1ca6600bfcbab7c7c91ccb085ac7fbbcd70e008a98742e7847f4f7bcef" |
2002 | "checksum rand_core 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "7a6fdeb83b075e8266dcc8762c22776f6877a63111121f5f8c7411e5be7eed4b" | 2002 | "checksum rand_core 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "7a6fdeb83b075e8266dcc8762c22776f6877a63111121f5f8c7411e5be7eed4b" |
diff --git a/crates/ra_batch/Cargo.toml b/crates/ra_batch/Cargo.toml index 5b78cb76e..3037e27c4 100644 --- a/crates/ra_batch/Cargo.toml +++ b/crates/ra_batch/Cargo.toml | |||
@@ -10,7 +10,7 @@ rustc-hash = "1.0" | |||
10 | 10 | ||
11 | failure = "0.1.4" | 11 | failure = "0.1.4" |
12 | 12 | ||
13 | ra_vfs = "0.1.0" | 13 | ra_vfs = "0.2.0" |
14 | ra_syntax = { path = "../ra_syntax" } | 14 | ra_syntax = { path = "../ra_syntax" } |
15 | ra_db = { path = "../ra_db" } | 15 | ra_db = { path = "../ra_db" } |
16 | ra_hir = { path = "../ra_hir" } | 16 | ra_hir = { path = "../ra_hir" } |
diff --git a/crates/ra_batch/src/lib.rs b/crates/ra_batch/src/lib.rs index c6d10107d..a054d0da3 100644 --- a/crates/ra_batch/src/lib.rs +++ b/crates/ra_batch/src/lib.rs | |||
@@ -1,5 +1,5 @@ | |||
1 | use std::sync::Arc; | 1 | use std::sync::Arc; |
2 | use std::path::Path; | 2 | use std::path::{Path, PathBuf}; |
3 | use std::collections::HashSet; | 3 | use std::collections::HashSet; |
4 | 4 | ||
5 | use rustc_hash::FxHashMap; | 5 | use rustc_hash::FxHashMap; |
@@ -9,7 +9,7 @@ use ra_db::{ | |||
9 | }; | 9 | }; |
10 | use ra_hir::{db, HirInterner}; | 10 | use ra_hir::{db, HirInterner}; |
11 | use ra_project_model::ProjectWorkspace; | 11 | use ra_project_model::ProjectWorkspace; |
12 | use ra_vfs::{Vfs, VfsChange}; | 12 | use ra_vfs::{Vfs, VfsChange, RootEntry, Filter, RelativePath}; |
13 | 13 | ||
14 | type Result<T> = std::result::Result<T, failure::Error>; | 14 | type Result<T> = std::result::Result<T, failure::Error>; |
15 | 15 | ||
@@ -43,6 +43,30 @@ fn vfs_root_to_id(r: ra_vfs::VfsRoot) -> SourceRootId { | |||
43 | SourceRootId(r.0.into()) | 43 | SourceRootId(r.0.into()) |
44 | } | 44 | } |
45 | 45 | ||
46 | struct IncludeRustFiles; | ||
47 | |||
48 | impl IncludeRustFiles { | ||
49 | fn to_entry(path: PathBuf) -> RootEntry { | ||
50 | RootEntry::new(path, Box::new(Self {})) | ||
51 | } | ||
52 | } | ||
53 | |||
54 | impl Filter for IncludeRustFiles { | ||
55 | fn include_dir(&self, dir_path: &RelativePath) -> bool { | ||
56 | const IGNORED_FOLDERS: &[&str] = &["node_modules", "target", ".git"]; | ||
57 | |||
58 | let is_ignored = dir_path.components().any(|c| IGNORED_FOLDERS.contains(&c.as_str())); | ||
59 | |||
60 | let hidden = dir_path.components().any(|c| c.as_str().starts_with(".")); | ||
61 | |||
62 | !is_ignored && !hidden | ||
63 | } | ||
64 | |||
65 | fn include_file(&self, file_path: &RelativePath) -> bool { | ||
66 | file_path.extension() == Some("rs") | ||
67 | } | ||
68 | } | ||
69 | |||
46 | impl BatchDatabase { | 70 | impl BatchDatabase { |
47 | pub fn load(crate_graph: CrateGraph, vfs: &mut Vfs) -> BatchDatabase { | 71 | pub fn load(crate_graph: CrateGraph, vfs: &mut Vfs) -> BatchDatabase { |
48 | let mut db = | 72 | let mut db = |
@@ -100,6 +124,7 @@ impl BatchDatabase { | |||
100 | let mut roots = Vec::new(); | 124 | let mut roots = Vec::new(); |
101 | roots.push(root.clone()); | 125 | roots.push(root.clone()); |
102 | roots.extend(ws.to_roots()); | 126 | roots.extend(ws.to_roots()); |
127 | let roots = roots.into_iter().map(IncludeRustFiles::to_entry).collect::<Vec<_>>(); | ||
103 | let (mut vfs, roots) = Vfs::new(roots); | 128 | let (mut vfs, roots) = Vfs::new(roots); |
104 | let mut load = |path: &Path| { | 129 | let mut load = |path: &Path| { |
105 | let vfs_file = vfs.load(path); | 130 | let vfs_file = vfs.load(path); |
diff --git a/crates/ra_lsp_server/Cargo.toml b/crates/ra_lsp_server/Cargo.toml index 2b3890e01..d82410700 100644 --- a/crates/ra_lsp_server/Cargo.toml +++ b/crates/ra_lsp_server/Cargo.toml | |||
@@ -19,7 +19,7 @@ lsp-types = "0.56.0" | |||
19 | rustc-hash = "1.0" | 19 | rustc-hash = "1.0" |
20 | parking_lot = "0.7.0" | 20 | parking_lot = "0.7.0" |
21 | 21 | ||
22 | ra_vfs = "0.1.0" | 22 | ra_vfs = "0.2.0" |
23 | thread_worker = { path = "../thread_worker" } | 23 | thread_worker = { path = "../thread_worker" } |
24 | ra_syntax = { path = "../ra_syntax" } | 24 | ra_syntax = { path = "../ra_syntax" } |
25 | ra_text_edit = { path = "../ra_text_edit" } | 25 | ra_text_edit = { path = "../ra_text_edit" } |
diff --git a/crates/ra_lsp_server/src/server_world.rs b/crates/ra_lsp_server/src/server_world.rs index 7163568b9..cf7c17c5c 100644 --- a/crates/ra_lsp_server/src/server_world.rs +++ b/crates/ra_lsp_server/src/server_world.rs | |||
@@ -8,8 +8,8 @@ use ra_ide_api::{ | |||
8 | Analysis, AnalysisChange, AnalysisHost, CrateGraph, FileId, LibraryData, | 8 | Analysis, AnalysisChange, AnalysisHost, CrateGraph, FileId, LibraryData, |
9 | SourceRootId | 9 | SourceRootId |
10 | }; | 10 | }; |
11 | use ra_vfs::{Vfs, VfsChange, VfsFile, VfsRoot}; | 11 | use ra_vfs::{Vfs, VfsChange, VfsFile, VfsRoot, RootEntry, Filter}; |
12 | use relative_path::RelativePathBuf; | 12 | use relative_path::{RelativePath, RelativePathBuf}; |
13 | use parking_lot::RwLock; | 13 | use parking_lot::RwLock; |
14 | use failure::format_err; | 14 | use failure::format_err; |
15 | 15 | ||
@@ -33,6 +33,30 @@ pub struct ServerWorld { | |||
33 | pub vfs: Arc<RwLock<Vfs>>, | 33 | pub vfs: Arc<RwLock<Vfs>>, |
34 | } | 34 | } |
35 | 35 | ||
36 | struct IncludeRustFiles; | ||
37 | |||
38 | impl IncludeRustFiles { | ||
39 | fn to_entry(path: PathBuf) -> RootEntry { | ||
40 | RootEntry::new(path, Box::new(Self {})) | ||
41 | } | ||
42 | } | ||
43 | |||
44 | impl Filter for IncludeRustFiles { | ||
45 | fn include_dir(&self, dir_path: &RelativePath) -> bool { | ||
46 | const IGNORED_FOLDERS: &[&str] = &["node_modules", "target", ".git"]; | ||
47 | |||
48 | let is_ignored = dir_path.components().any(|c| IGNORED_FOLDERS.contains(&c.as_str())); | ||
49 | |||
50 | let hidden = dir_path.components().any(|c| c.as_str().starts_with(".")); | ||
51 | |||
52 | !is_ignored && !hidden | ||
53 | } | ||
54 | |||
55 | fn include_file(&self, file_path: &RelativePath) -> bool { | ||
56 | file_path.extension() == Some("rs") | ||
57 | } | ||
58 | } | ||
59 | |||
36 | impl ServerWorldState { | 60 | impl ServerWorldState { |
37 | pub fn new(root: PathBuf, workspaces: Vec<ProjectWorkspace>) -> ServerWorldState { | 61 | pub fn new(root: PathBuf, workspaces: Vec<ProjectWorkspace>) -> ServerWorldState { |
38 | let mut change = AnalysisChange::new(); | 62 | let mut change = AnalysisChange::new(); |
@@ -42,6 +66,8 @@ impl ServerWorldState { | |||
42 | for ws in workspaces.iter() { | 66 | for ws in workspaces.iter() { |
43 | roots.extend(ws.to_roots()); | 67 | roots.extend(ws.to_roots()); |
44 | } | 68 | } |
69 | let roots = roots.into_iter().map(IncludeRustFiles::to_entry).collect::<Vec<_>>(); | ||
70 | |||
45 | let (mut vfs, roots) = Vfs::new(roots); | 71 | let (mut vfs, roots) = Vfs::new(roots); |
46 | let roots_to_scan = roots.len(); | 72 | let roots_to_scan = roots.len(); |
47 | for r in roots { | 73 | for r in roots { |
diff --git a/crates/tools/src/main.rs b/crates/tools/src/main.rs index 4a1b2ff9a..0c3339685 100644 --- a/crates/tools/src/main.rs +++ b/crates/tools/src/main.rs | |||
@@ -5,6 +5,7 @@ use tools::{ | |||
5 | generate, gen_tests, install_format_hook, run, run_with_output, run_rustfmt, | 5 | generate, gen_tests, install_format_hook, run, run_with_output, run_rustfmt, |
6 | Overwrite, Result, run_fuzzer, | 6 | Overwrite, Result, run_fuzzer, |
7 | }; | 7 | }; |
8 | use std::{path::{PathBuf}, env}; | ||
8 | 9 | ||
9 | fn main() -> Result<()> { | 10 | fn main() -> Result<()> { |
10 | let matches = App::new("tasks") | 11 | let matches = App::new("tasks") |
@@ -17,7 +18,12 @@ fn main() -> Result<()> { | |||
17 | .subcommand(SubCommand::with_name("fuzz-tests")) | 18 | .subcommand(SubCommand::with_name("fuzz-tests")) |
18 | .get_matches(); | 19 | .get_matches(); |
19 | match matches.subcommand_name().expect("Subcommand must be specified") { | 20 | match matches.subcommand_name().expect("Subcommand must be specified") { |
20 | "install-code" => install_code_extension()?, | 21 | "install-code" => { |
22 | if cfg!(target_os = "macos") { | ||
23 | fix_path_for_mac()?; | ||
24 | } | ||
25 | install_code_extension()?; | ||
26 | } | ||
21 | "gen-tests" => gen_tests(Overwrite)?, | 27 | "gen-tests" => gen_tests(Overwrite)?, |
22 | "gen-syntax" => generate(Overwrite)?, | 28 | "gen-syntax" => generate(Overwrite)?, |
23 | "format" => run_rustfmt(Overwrite)?, | 29 | "format" => run_rustfmt(Overwrite)?, |
@@ -63,3 +69,36 @@ fn verify_installed_extensions() -> Result<()> { | |||
63 | } | 69 | } |
64 | Ok(()) | 70 | Ok(()) |
65 | } | 71 | } |
72 | |||
73 | fn fix_path_for_mac() -> Result<()> { | ||
74 | let mut vscode_path: Vec<PathBuf> = { | ||
75 | const COMMON_APP_PATH: &str = | ||
76 | r"/Applications/Visual Studio Code.app/Contents/Resources/app/bin"; | ||
77 | const ROOT_DIR: &str = ""; | ||
78 | let home_dir = match env::var("HOME") { | ||
79 | Ok(home) => home, | ||
80 | Err(e) => bail!("Failed getting HOME from environment with error: {}.", e), | ||
81 | }; | ||
82 | |||
83 | [ROOT_DIR, &home_dir] | ||
84 | .iter() | ||
85 | .map(|dir| String::from(dir.clone()) + COMMON_APP_PATH) | ||
86 | .map(PathBuf::from) | ||
87 | .filter(|path| path.exists()) | ||
88 | .collect() | ||
89 | }; | ||
90 | |||
91 | if !vscode_path.is_empty() { | ||
92 | let vars = match env::var_os("PATH") { | ||
93 | Some(path) => path, | ||
94 | None => bail!("Could not get PATH variable from env."), | ||
95 | }; | ||
96 | |||
97 | let mut paths = env::split_paths(&vars).collect::<Vec<_>>(); | ||
98 | paths.append(&mut vscode_path); | ||
99 | let new_paths = env::join_paths(paths)?; | ||
100 | env::set_var("PATH", &new_paths); | ||
101 | } | ||
102 | |||
103 | Ok(()) | ||
104 | } | ||
diff --git a/editors/code/package.json b/editors/code/package.json index 3834f2847..3e8cde388 100644 --- a/editors/code/package.json +++ b/editors/code/package.json | |||
@@ -168,6 +168,11 @@ | |||
168 | "default": "ra_lsp_server", | 168 | "default": "ra_lsp_server", |
169 | "description": "Path to ra_lsp_server executable" | 169 | "description": "Path to ra_lsp_server executable" |
170 | }, | 170 | }, |
171 | "rust-analyzer.enableCargoWatchOnStartup": { | ||
172 | "type": "boolean", | ||
173 | "default": "true", | ||
174 | "description": "When enabled, ask the user whether to run `cargo watch` on startup" | ||
175 | }, | ||
171 | "rust-analyzer.trace.server": { | 176 | "rust-analyzer.trace.server": { |
172 | "type": "string", | 177 | "type": "string", |
173 | "scope": "window", | 178 | "scope": "window", |
diff --git a/editors/code/src/commands/runnables.ts b/editors/code/src/commands/runnables.ts index c0f2ada76..ea2883ad4 100644 --- a/editors/code/src/commands/runnables.ts +++ b/editors/code/src/commands/runnables.ts | |||
@@ -1,5 +1,8 @@ | |||
1 | import * as child_process from 'child_process'; | ||
2 | import * as util from 'util'; | ||
1 | import * as vscode from 'vscode'; | 3 | import * as vscode from 'vscode'; |
2 | import * as lc from 'vscode-languageclient'; | 4 | import * as lc from 'vscode-languageclient'; |
5 | |||
3 | import { Server } from '../server'; | 6 | import { Server } from '../server'; |
4 | 7 | ||
5 | interface RunnablesParams { | 8 | interface RunnablesParams { |
@@ -8,7 +11,6 @@ interface RunnablesParams { | |||
8 | } | 11 | } |
9 | 12 | ||
10 | interface Runnable { | 13 | interface Runnable { |
11 | range: lc.Range; | ||
12 | label: string; | 14 | label: string; |
13 | bin: string; | 15 | bin: string; |
14 | args: string[]; | 16 | args: string[]; |
@@ -38,7 +40,7 @@ function createTask(spec: Runnable): vscode.Task { | |||
38 | const TASK_SOURCE = 'Rust'; | 40 | const TASK_SOURCE = 'Rust'; |
39 | const definition: CargoTaskDefinition = { | 41 | const definition: CargoTaskDefinition = { |
40 | type: 'cargo', | 42 | type: 'cargo', |
41 | label: 'cargo', | 43 | label: spec.label, |
42 | command: spec.bin, | 44 | command: spec.bin, |
43 | args: spec.args, | 45 | args: spec.args, |
44 | env: spec.env | 46 | env: spec.env |
@@ -124,3 +126,88 @@ export async function handleSingle(runnable: Runnable) { | |||
124 | 126 | ||
125 | return vscode.tasks.executeTask(task); | 127 | return vscode.tasks.executeTask(task); |
126 | } | 128 | } |
129 | |||
130 | export const autoCargoWatchTask: vscode.Task = { | ||
131 | name: 'cargo watch', | ||
132 | source: 'rust-analyzer', | ||
133 | definition: { | ||
134 | type: 'watch' | ||
135 | }, | ||
136 | execution: new vscode.ShellExecution('cargo', ['watch'], { cwd: '.' }), | ||
137 | |||
138 | isBackground: true, | ||
139 | problemMatchers: ['$rustc-watch'], | ||
140 | presentationOptions: { | ||
141 | clear: true | ||
142 | }, | ||
143 | // Not yet exposed in the vscode.d.ts | ||
144 | // https://github.com/Microsoft/vscode/blob/ea7c31d770e04b51d586b0d3944f3a7feb03afb9/src/vs/workbench/contrib/tasks/common/tasks.ts#L444-L456 | ||
145 | runOptions: ({ | ||
146 | runOn: 2 // RunOnOptions.folderOpen | ||
147 | } as unknown) as vscode.RunOptions | ||
148 | }; | ||
149 | |||
150 | /** | ||
151 | * Interactively asks the user whether we should run `cargo check` in order to | ||
152 | * provide inline diagnostics; the user is met with a series of dialog boxes | ||
153 | * that, when accepted, allow us to `cargo install cargo-watch` and then run it. | ||
154 | */ | ||
155 | export async function interactivelyStartCargoWatch() { | ||
156 | if (!Server.config.enableCargoWatchOnStartup) { | ||
157 | return; | ||
158 | } | ||
159 | |||
160 | const execPromise = util.promisify(child_process.exec); | ||
161 | |||
162 | const watch = await vscode.window.showInformationMessage( | ||
163 | 'Start watching changes with cargo? (Executes `cargo watch`, provides inline diagnostics)', | ||
164 | 'yes', | ||
165 | 'no' | ||
166 | ); | ||
167 | if (watch === 'no') { | ||
168 | return; | ||
169 | } | ||
170 | |||
171 | const { stderr } = await execPromise('cargo watch --version').catch(e => e); | ||
172 | if (stderr.includes('no such subcommand: `watch`')) { | ||
173 | const msg = | ||
174 | 'The `cargo-watch` subcommand is not installed. Install? (takes ~1-2 minutes)'; | ||
175 | const install = await vscode.window.showInformationMessage( | ||
176 | msg, | ||
177 | 'yes', | ||
178 | 'no' | ||
179 | ); | ||
180 | if (install === 'no') { | ||
181 | return; | ||
182 | } | ||
183 | |||
184 | const label = 'install-cargo-watch'; | ||
185 | const taskFinished = new Promise((resolve, reject) => { | ||
186 | const disposable = vscode.tasks.onDidEndTask(({ execution }) => { | ||
187 | if (execution.task.name === label) { | ||
188 | disposable.dispose(); | ||
189 | resolve(); | ||
190 | } | ||
191 | }); | ||
192 | }); | ||
193 | |||
194 | vscode.tasks.executeTask( | ||
195 | createTask({ | ||
196 | label, | ||
197 | bin: 'cargo', | ||
198 | args: ['install', 'cargo-watch'], | ||
199 | env: {} | ||
200 | }) | ||
201 | ); | ||
202 | await taskFinished; | ||
203 | const output = await execPromise('cargo watch --version').catch(e => e); | ||
204 | if (output.stderr !== '') { | ||
205 | vscode.window.showErrorMessage( | ||
206 | `Couldn't install \`cargo-\`watch: ${output.stderr}` | ||
207 | ); | ||
208 | return; | ||
209 | } | ||
210 | } | ||
211 | |||
212 | vscode.tasks.executeTask(autoCargoWatchTask); | ||
213 | } | ||
diff --git a/editors/code/src/config.ts b/editors/code/src/config.ts index afc5cc6af..d8795f3b0 100644 --- a/editors/code/src/config.ts +++ b/editors/code/src/config.ts | |||
@@ -9,6 +9,7 @@ export class Config { | |||
9 | public enableEnhancedTyping = true; | 9 | public enableEnhancedTyping = true; |
10 | public raLspServerPath = RA_LSP_DEBUG || 'ra_lsp_server'; | 10 | public raLspServerPath = RA_LSP_DEBUG || 'ra_lsp_server'; |
11 | public showWorkspaceLoadedNotification = true; | 11 | public showWorkspaceLoadedNotification = true; |
12 | public enableCargoWatchOnStartup = true; | ||
12 | 13 | ||
13 | private prevEnhancedTyping: null | boolean = null; | 14 | private prevEnhancedTyping: null | boolean = null; |
14 | 15 | ||
@@ -68,5 +69,12 @@ export class Config { | |||
68 | this.raLspServerPath = | 69 | this.raLspServerPath = |
69 | RA_LSP_DEBUG || (config.get('raLspServerPath') as string); | 70 | RA_LSP_DEBUG || (config.get('raLspServerPath') as string); |
70 | } | 71 | } |
72 | |||
73 | if (config.has('enableCargoWatchOnStartup')) { | ||
74 | this.enableCargoWatchOnStartup = config.get<boolean>( | ||
75 | 'enableCargoWatchOnStartup', | ||
76 | true | ||
77 | ); | ||
78 | } | ||
71 | } | 79 | } |
72 | } | 80 | } |
diff --git a/editors/code/src/extension.ts b/editors/code/src/extension.ts index 941beba18..2e13c87de 100644 --- a/editors/code/src/extension.ts +++ b/editors/code/src/extension.ts | |||
@@ -2,6 +2,7 @@ import * as vscode from 'vscode'; | |||
2 | import * as lc from 'vscode-languageclient'; | 2 | import * as lc from 'vscode-languageclient'; |
3 | 3 | ||
4 | import * as commands from './commands'; | 4 | import * as commands from './commands'; |
5 | import { interactivelyStartCargoWatch } from './commands/runnables'; | ||
5 | import { SyntaxTreeContentProvider } from './commands/syntaxTree'; | 6 | import { SyntaxTreeContentProvider } from './commands/syntaxTree'; |
6 | import * as events from './events'; | 7 | import * as events from './events'; |
7 | import * as notifications from './notifications'; | 8 | import * as notifications from './notifications'; |
@@ -119,6 +120,9 @@ export function activate(context: vscode.ExtensionContext) { | |||
119 | context.subscriptions | 120 | context.subscriptions |
120 | ); | 121 | ); |
121 | 122 | ||
123 | // Executing `cargo watch` provides us with inline diagnostics on save | ||
124 | interactivelyStartCargoWatch(); | ||
125 | |||
122 | // Start the language server, finally! | 126 | // Start the language server, finally! |
123 | Server.start(allNotifications); | 127 | Server.start(allNotifications); |
124 | } | 128 | } |