diff options
-rw-r--r-- | Cargo.lock | 15 | ||||
-rw-r--r-- | crates/ra_lsp_server/src/lib.rs | 8 | ||||
-rw-r--r-- | crates/ra_lsp_server/src/main.rs | 17 | ||||
-rw-r--r-- | crates/ra_lsp_server/src/main_loop/handlers.rs | 3 | ||||
-rw-r--r-- | editors/code/src/installation/download_file.ts | 16 |
5 files changed, 34 insertions, 25 deletions
diff --git a/Cargo.lock b/Cargo.lock index e29ff898d..847653696 100644 --- a/Cargo.lock +++ b/Cargo.lock | |||
@@ -110,9 +110,9 @@ dependencies = [ | |||
110 | 110 | ||
111 | [[package]] | 111 | [[package]] |
112 | name = "byteorder" | 112 | name = "byteorder" |
113 | version = "1.3.2" | 113 | version = "1.3.4" |
114 | source = "registry+https://github.com/rust-lang/crates.io-index" | 114 | source = "registry+https://github.com/rust-lang/crates.io-index" |
115 | checksum = "a7c3dd8985a7111efc5c80b44e23ecdd8c007de8ade3b96595387e812b957cf5" | 115 | checksum = "08c48aae112d48ed9f069b33538ea9e3e90aa263cfa3d1c24309612b1f7472de" |
116 | 116 | ||
117 | [[package]] | 117 | [[package]] |
118 | name = "c2-chacha" | 118 | name = "c2-chacha" |
@@ -1563,12 +1563,9 @@ checksum = "4c691c0e608126e00913e33f0ccf3727d5fc84573623b8d65b2df340b5201783" | |||
1563 | 1563 | ||
1564 | [[package]] | 1564 | [[package]] |
1565 | name = "rustc-hash" | 1565 | name = "rustc-hash" |
1566 | version = "1.0.1" | 1566 | version = "1.1.0" |
1567 | source = "registry+https://github.com/rust-lang/crates.io-index" | 1567 | source = "registry+https://github.com/rust-lang/crates.io-index" |
1568 | checksum = "7540fc8b0c49f096ee9c961cda096467dce8084bec6bdca2fc83895fd9b28cb8" | 1568 | checksum = "08d43f7aa6b08d49f382cde6a7982047c3426db949b1424bc4b7ec9ae12c6ce2" |
1569 | dependencies = [ | ||
1570 | "byteorder", | ||
1571 | ] | ||
1572 | 1569 | ||
1573 | [[package]] | 1570 | [[package]] |
1574 | name = "rustc_lexer" | 1571 | name = "rustc_lexer" |
@@ -1675,9 +1672,9 @@ dependencies = [ | |||
1675 | 1672 | ||
1676 | [[package]] | 1673 | [[package]] |
1677 | name = "serde_json" | 1674 | name = "serde_json" |
1678 | version = "1.0.46" | 1675 | version = "1.0.47" |
1679 | source = "registry+https://github.com/rust-lang/crates.io-index" | 1676 | source = "registry+https://github.com/rust-lang/crates.io-index" |
1680 | checksum = "21b01d7f0288608a01dca632cf1df859df6fd6ffa885300fc275ce2ba6221953" | 1677 | checksum = "15913895b61e0be854afd32fd4163fcd2a3df34142cf2cb961b310ce694cbf90" |
1681 | dependencies = [ | 1678 | dependencies = [ |
1682 | "itoa", | 1679 | "itoa", |
1683 | "ryu", | 1680 | "ryu", |
diff --git a/crates/ra_lsp_server/src/lib.rs b/crates/ra_lsp_server/src/lib.rs index 1208c1343..a3464a5a3 100644 --- a/crates/ra_lsp_server/src/lib.rs +++ b/crates/ra_lsp_server/src/lib.rs | |||
@@ -31,6 +31,8 @@ mod config; | |||
31 | mod world; | 31 | mod world; |
32 | mod diagnostics; | 32 | mod diagnostics; |
33 | 33 | ||
34 | use serde::de::DeserializeOwned; | ||
35 | |||
34 | pub type Result<T> = std::result::Result<T, Box<dyn std::error::Error + Send + Sync>>; | 36 | pub type Result<T> = std::result::Result<T, Box<dyn std::error::Error + Send + Sync>>; |
35 | pub use crate::{ | 37 | pub use crate::{ |
36 | caps::server_capabilities, | 38 | caps::server_capabilities, |
@@ -38,3 +40,9 @@ pub use crate::{ | |||
38 | main_loop::LspError, | 40 | main_loop::LspError, |
39 | main_loop::{main_loop, show_message}, | 41 | main_loop::{main_loop, show_message}, |
40 | }; | 42 | }; |
43 | |||
44 | pub fn from_json<T: DeserializeOwned>(what: &'static str, json: serde_json::Value) -> Result<T> { | ||
45 | let res = T::deserialize(&json) | ||
46 | .map_err(|e| format!("Failed to deserialize {}: {}; {}", what, e, json))?; | ||
47 | Ok(res) | ||
48 | } | ||
diff --git a/crates/ra_lsp_server/src/main.rs b/crates/ra_lsp_server/src/main.rs index 3879eeff2..c8a017c5c 100644 --- a/crates/ra_lsp_server/src/main.rs +++ b/crates/ra_lsp_server/src/main.rs | |||
@@ -1,7 +1,7 @@ | |||
1 | //! `ra_lsp_server` binary | 1 | //! `ra_lsp_server` binary |
2 | 2 | ||
3 | use lsp_server::Connection; | 3 | use lsp_server::Connection; |
4 | use ra_lsp_server::{show_message, Result, ServerConfig}; | 4 | use ra_lsp_server::{from_json, show_message, Result, ServerConfig}; |
5 | use ra_prof; | 5 | use ra_prof; |
6 | 6 | ||
7 | fn main() -> Result<()> { | 7 | fn main() -> Result<()> { |
@@ -45,7 +45,8 @@ fn run_server() -> Result<()> { | |||
45 | let server_capabilities = serde_json::to_value(ra_lsp_server::server_capabilities()).unwrap(); | 45 | let server_capabilities = serde_json::to_value(ra_lsp_server::server_capabilities()).unwrap(); |
46 | 46 | ||
47 | let initialize_params = connection.initialize(server_capabilities)?; | 47 | let initialize_params = connection.initialize(server_capabilities)?; |
48 | let initialize_params: lsp_types::InitializeParams = serde_json::from_value(initialize_params)?; | 48 | let initialize_params = |
49 | from_json::<lsp_types::InitializeParams>("InitializeParams", initialize_params)?; | ||
49 | 50 | ||
50 | if let Some(client_info) = initialize_params.client_info { | 51 | if let Some(client_info) = initialize_params.client_info { |
51 | log::info!("Client '{}' {}", client_info.name, client_info.version.unwrap_or_default()); | 52 | log::info!("Client '{}' {}", client_info.name, client_info.version.unwrap_or_default()); |
@@ -62,17 +63,13 @@ fn run_server() -> Result<()> { | |||
62 | .filter(|workspaces| !workspaces.is_empty()) | 63 | .filter(|workspaces| !workspaces.is_empty()) |
63 | .unwrap_or_else(|| vec![root]); | 64 | .unwrap_or_else(|| vec![root]); |
64 | 65 | ||
65 | let server_config: ServerConfig = initialize_params | 66 | let server_config = initialize_params |
66 | .initialization_options | 67 | .initialization_options |
67 | .and_then(|v| { | 68 | .and_then(|v| { |
68 | serde_json::from_value(v) | 69 | from_json::<ServerConfig>("config", v) |
69 | .map_err(|e| { | 70 | .map_err(|e| { |
70 | log::error!("failed to deserialize config: {}", e); | 71 | log::error!("{}", e); |
71 | show_message( | 72 | show_message(lsp_types::MessageType::Error, e.to_string(), &connection.sender); |
72 | lsp_types::MessageType::Error, | ||
73 | format!("failed to deserialize config: {}", e), | ||
74 | &connection.sender, | ||
75 | ); | ||
76 | }) | 73 | }) |
77 | .ok() | 74 | .ok() |
78 | }) | 75 | }) |
diff --git a/crates/ra_lsp_server/src/main_loop/handlers.rs b/crates/ra_lsp_server/src/main_loop/handlers.rs index 65e8bc856..59c86bbfa 100644 --- a/crates/ra_lsp_server/src/main_loop/handlers.rs +++ b/crates/ra_lsp_server/src/main_loop/handlers.rs | |||
@@ -35,6 +35,7 @@ use crate::{ | |||
35 | TryConvWithToVec, | 35 | TryConvWithToVec, |
36 | }, | 36 | }, |
37 | diagnostics::DiagnosticTask, | 37 | diagnostics::DiagnosticTask, |
38 | from_json, | ||
38 | req::{self, Decoration, InlayHint, InlayHintsParams, InlayKind}, | 39 | req::{self, Decoration, InlayHint, InlayHintsParams, InlayKind}, |
39 | world::WorldSnapshot, | 40 | world::WorldSnapshot, |
40 | LspError, Result, | 41 | LspError, Result, |
@@ -811,7 +812,7 @@ enum CodeLensResolveData { | |||
811 | pub fn handle_code_lens_resolve(world: WorldSnapshot, code_lens: CodeLens) -> Result<CodeLens> { | 812 | pub fn handle_code_lens_resolve(world: WorldSnapshot, code_lens: CodeLens) -> Result<CodeLens> { |
812 | let _p = profile("handle_code_lens_resolve"); | 813 | let _p = profile("handle_code_lens_resolve"); |
813 | let data = code_lens.data.unwrap(); | 814 | let data = code_lens.data.unwrap(); |
814 | let resolve = serde_json::from_value(data)?; | 815 | let resolve = from_json::<Option<CodeLensResolveData>>("CodeLensResolveData", data)?; |
815 | match resolve { | 816 | match resolve { |
816 | Some(CodeLensResolveData::Impls(lens_params)) => { | 817 | Some(CodeLensResolveData::Impls(lens_params)) => { |
817 | let locations: Vec<Location> = | 818 | let locations: Vec<Location> = |
diff --git a/editors/code/src/installation/download_file.ts b/editors/code/src/installation/download_file.ts index b51602ef9..8a0766c66 100644 --- a/editors/code/src/installation/download_file.ts +++ b/editors/code/src/installation/download_file.ts | |||
@@ -13,22 +13,28 @@ export async function downloadFile( | |||
13 | destFilePath: fs.PathLike, | 13 | destFilePath: fs.PathLike, |
14 | onProgress: (readBytes: number, totalBytes: number) => void | 14 | onProgress: (readBytes: number, totalBytes: number) => void |
15 | ): Promise<void> { | 15 | ): Promise<void> { |
16 | const response = await fetch(url); | 16 | const res = await fetch(url); |
17 | 17 | ||
18 | const totalBytes = Number(response.headers.get('content-length')); | 18 | if (!res.ok) { |
19 | console.log("Error", res.status, "while downloading file from", url); | ||
20 | console.dir({ body: await res.text(), headers: res.headers }, { depth: 3 }); | ||
21 | |||
22 | throw new Error(`Got response ${res.status} when trying to download a file`); | ||
23 | } | ||
24 | |||
25 | const totalBytes = Number(res.headers.get('content-length')); | ||
19 | assert(!Number.isNaN(totalBytes), "Sanity check of content-length protocol"); | 26 | assert(!Number.isNaN(totalBytes), "Sanity check of content-length protocol"); |
20 | 27 | ||
21 | let readBytes = 0; | 28 | let readBytes = 0; |
22 | 29 | ||
23 | console.log("Downloading file of", totalBytes, "bytes size from", url, "to", destFilePath); | 30 | console.log("Downloading file of", totalBytes, "bytes size from", url, "to", destFilePath); |
24 | 31 | ||
25 | return new Promise<void>((resolve, reject) => response.body | 32 | return new Promise<void>((resolve, reject) => res.body |
26 | .on("data", (chunk: Buffer) => { | 33 | .on("data", (chunk: Buffer) => { |
27 | readBytes += chunk.length; | 34 | readBytes += chunk.length; |
28 | onProgress(readBytes, totalBytes); | 35 | onProgress(readBytes, totalBytes); |
29 | }) | 36 | }) |
30 | .on("end", resolve) | ||
31 | .on("error", reject) | 37 | .on("error", reject) |
32 | .pipe(fs.createWriteStream(destFilePath)) | 38 | .pipe(fs.createWriteStream(destFilePath).on("close", resolve)) |
33 | ); | 39 | ); |
34 | } | 40 | } |