From 3f44aaf363be0669e618a8340fd91b47ae6344c4 Mon Sep 17 00:00:00 2001
From: Jeremy Kolb <kjeremy@gmail.com>
Date: Sun, 7 Jul 2019 14:13:13 -0400
Subject: use flatten branch of lsp-types

---
 Cargo.lock                                     |  8 +++---
 crates/gen_lsp_server/Cargo.toml               |  2 +-
 crates/ra_lsp_server/Cargo.toml                |  2 +-
 crates/ra_lsp_server/src/main_loop/handlers.rs | 35 +++++++++-----------------
 crates/ra_lsp_server/tests/heavy_tests/main.rs |  6 +++--
 5 files changed, 22 insertions(+), 31 deletions(-)

diff --git a/Cargo.lock b/Cargo.lock
index e0599edb3..eea206f99 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -541,7 +541,7 @@ dependencies = [
  "crossbeam-channel 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)",
  "flexi_logger 0.13.2 (registry+https://github.com/rust-lang/crates.io-index)",
  "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)",
- "lsp-types 0.58.1 (registry+https://github.com/rust-lang/crates.io-index)",
+ "lsp-types 0.58.1 (git+https://github.com/kjeremy/languageserver-types?branch=flatten)",
  "serde 1.0.94 (registry+https://github.com/rust-lang/crates.io-index)",
  "serde_json 1.0.40 (registry+https://github.com/rust-lang/crates.io-index)",
 ]
@@ -775,7 +775,7 @@ dependencies = [
 [[package]]
 name = "lsp-types"
 version = "0.58.1"
-source = "registry+https://github.com/rust-lang/crates.io-index"
+source = "git+https://github.com/kjeremy/languageserver-types?branch=flatten#f3f793173bb1461602dabf83d324b638b3e6ec61"
 dependencies = [
  "bitflags 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
  "num-derive 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -1200,7 +1200,7 @@ dependencies = [
  "flexi_logger 0.13.2 (registry+https://github.com/rust-lang/crates.io-index)",
  "gen_lsp_server 0.2.0",
  "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)",
- "lsp-types 0.58.1 (registry+https://github.com/rust-lang/crates.io-index)",
+ "lsp-types 0.58.1 (git+https://github.com/kjeremy/languageserver-types?branch=flatten)",
  "parking_lot 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)",
  "ra_arena 0.1.0",
  "ra_ide_api 0.1.0",
@@ -2201,7 +2201,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
 "checksum linked-hash-map 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)" = "ae91b68aebc4ddb91978b11a1b02ddd8602a05ec19002801c5666000e05e0f83"
 "checksum lock_api 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ed946d4529956a20f2d63ebe1b69996d5a2137c91913fe3ebbeff957f5bca7ff"
 "checksum log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)" = "c84ec4b527950aa83a329754b01dbe3f58361d1c5efacd1f6d68c494d08a17c6"
-"checksum lsp-types 0.58.1 (registry+https://github.com/rust-lang/crates.io-index)" = "42c7edac51b6739544453fd33c7ae5e910d1ec4f2d9904cf1990f8f6581e26f5"
+"checksum lsp-types 0.58.1 (git+https://github.com/kjeremy/languageserver-types?branch=flatten)" = "<none>"
 "checksum maplit 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "08cbb6b4fef96b6d77bfc40ec491b1690c779e77b05cd9f07f787ed376fd4c43"
 "checksum matches 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)" = "7ffc5c5338469d4d3ea17d269fa8ea3512ad247247c30bd2df69e68309ed0a08"
 "checksum memchr 2.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "2efc7bc57c883d4a4d6e3246905283d8dae951bb3bd32f49d6ef297f546e1c39"
diff --git a/crates/gen_lsp_server/Cargo.toml b/crates/gen_lsp_server/Cargo.toml
index bf57df81f..46b02a459 100644
--- a/crates/gen_lsp_server/Cargo.toml
+++ b/crates/gen_lsp_server/Cargo.toml
@@ -8,7 +8,7 @@ license = "MIT OR Apache-2.0"
 description = "Generic LSP server scaffold."
 
 [dependencies]
-lsp-types = "0.58.0"
+lsp-types = { git = "https://github.com/kjeremy/languageserver-types", branch = "flatten" }
 log = "0.4.3"
 serde_json = "1.0.34"
 serde = { version = "1.0.83", features = ["derive"] }
diff --git a/crates/ra_lsp_server/Cargo.toml b/crates/ra_lsp_server/Cargo.toml
index 2c4b3789e..9c9dda01f 100644
--- a/crates/ra_lsp_server/Cargo.toml
+++ b/crates/ra_lsp_server/Cargo.toml
@@ -13,7 +13,7 @@ crossbeam-channel = "0.3.5"
 flexi_logger = "0.13.0"
 log = "0.4.3"
 url_serde = "0.2.0"
-lsp-types = { version = "0.58.0", features = ["proposed"] }
+lsp-types = { git = "https://github.com/kjeremy/languageserver-types", branch = "flatten", features = ["proposed"] }
 rustc-hash = "1.0"
 parking_lot = "0.8.0"
 
diff --git a/crates/ra_lsp_server/src/main_loop/handlers.rs b/crates/ra_lsp_server/src/main_loop/handlers.rs
index a8d6f7c23..6b407cb0c 100644
--- a/crates/ra_lsp_server/src/main_loop/handlers.rs
+++ b/crates/ra_lsp_server/src/main_loop/handlers.rs
@@ -153,14 +153,12 @@ pub fn handle_on_type_formatting(
     params: req::DocumentOnTypeFormattingParams,
 ) -> Result<Option<Vec<TextEdit>>> {
     let _p = profile("handle_on_type_formatting");
-    let file_id = params.text_document.try_conv_with(&world)?;
-    let line_index = world.analysis().file_line_index(file_id);
-    let position = FilePosition {
-        file_id,
-        /// in `ra_ide_api`, the `on_type` invariant is that
-        /// `text.char_at(position) == typed_char`.
-        offset: params.position.conv_with(&line_index) - TextUnit::of_char('.'),
-    };
+    let mut position = params.text_document_position.try_conv_with(&world)?;
+    let line_index = world.analysis().file_line_index(position.file_id);
+
+    // in `ra_ide_api`, the `on_type` invariant is that
+    // `text.char_at(position) == typed_char`.
+    position.offset = position.offset - TextUnit::of_char('.');
 
     let edit = match params.ch.as_str() {
         "=" => world.analysis().on_eq_typed(position),
@@ -407,12 +405,7 @@ pub fn handle_completion(
     params: req::CompletionParams,
 ) -> Result<Option<req::CompletionResponse>> {
     let _p = profile("handle_completion");
-    let position = {
-        let file_id = params.text_document.try_conv_with(&world)?;
-        let line_index = world.analysis().file_line_index(file_id);
-        let offset = params.position.conv_with(&line_index);
-        FilePosition { file_id, offset }
-    };
+    let position = params.text_document_position.try_conv_with(&world)?;
     let completion_triggered_after_single_colon = {
         let mut res = false;
         if let Some(ctx) = params.context {
@@ -543,9 +536,7 @@ pub fn handle_prepare_rename(
 }
 
 pub fn handle_rename(world: WorldSnapshot, params: RenameParams) -> Result<Option<WorkspaceEdit>> {
-    let file_id = params.text_document.try_conv_with(&world)?;
-    let line_index = world.analysis().file_line_index(file_id);
-    let offset = params.position.conv_with(&line_index);
+    let position = params.text_document_position.try_conv_with(&world)?;
 
     if params.new_name.is_empty() {
         return Err(LspError::new(
@@ -555,8 +546,7 @@ pub fn handle_rename(world: WorldSnapshot, params: RenameParams) -> Result<Optio
         .into());
     }
 
-    let optional_change =
-        world.analysis().rename(FilePosition { file_id, offset }, &*params.new_name)?;
+    let optional_change = world.analysis().rename(position, &*params.new_name)?;
     let change = match optional_change {
         None => return Ok(None),
         Some(it) => it,
@@ -571,11 +561,10 @@ pub fn handle_references(
     world: WorldSnapshot,
     params: req::ReferenceParams,
 ) -> Result<Option<Vec<Location>>> {
-    let file_id = params.text_document.try_conv_with(&world)?;
-    let line_index = world.analysis().file_line_index(file_id);
-    let offset = params.position.conv_with(&line_index);
+    let position = params.text_document_position.try_conv_with(&world)?;
+    let line_index = world.analysis().file_line_index(position.file_id);
 
-    let refs = match world.analysis().find_all_refs(FilePosition { file_id, offset })? {
+    let refs = match world.analysis().find_all_refs(position)? {
         None => return Ok(None),
         Some(refs) => refs,
     };
diff --git a/crates/ra_lsp_server/tests/heavy_tests/main.rs b/crates/ra_lsp_server/tests/heavy_tests/main.rs
index d271b02fc..451be32a8 100644
--- a/crates/ra_lsp_server/tests/heavy_tests/main.rs
+++ b/crates/ra_lsp_server/tests/heavy_tests/main.rs
@@ -37,9 +37,11 @@ use std::collections::Spam;
     eprintln!("loading took    {:?}", project_start.elapsed());
     let completion_start = Instant::now();
     let res = server.send_request::<Completion>(CompletionParams {
-        text_document: server.doc_id("src/lib.rs"),
+        text_document_position: TextDocumentPositionParams::new(
+            server.doc_id("src/lib.rs"),
+            Position::new(0, 23),
+        ),
         context: None,
-        position: Position::new(0, 23),
     });
     assert!(format!("{}", res).contains("HashMap"));
     eprintln!("completion took {:?}", completion_start.elapsed());
-- 
cgit v1.2.3


From 9c6e93cd6c108536015272b6a363ed5cc1d4fb44 Mon Sep 17 00:00:00 2001
From: Jeremy Kolb <kjeremy@gmail.com>
Date: Sun, 7 Jul 2019 17:28:21 -0400
Subject: Simplify responses by using into()

---
 Cargo.lock                                     | 10 +++++-----
 crates/gen_lsp_server/Cargo.toml               |  2 +-
 crates/ra_lsp_server/Cargo.toml                |  2 +-
 crates/ra_lsp_server/src/main_loop/handlers.rs | 23 ++++++++++++-----------
 4 files changed, 19 insertions(+), 18 deletions(-)

diff --git a/Cargo.lock b/Cargo.lock
index eea206f99..a1bb96535 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -541,7 +541,7 @@ dependencies = [
  "crossbeam-channel 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)",
  "flexi_logger 0.13.2 (registry+https://github.com/rust-lang/crates.io-index)",
  "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)",
- "lsp-types 0.58.1 (git+https://github.com/kjeremy/languageserver-types?branch=flatten)",
+ "lsp-types 0.59.0 (registry+https://github.com/rust-lang/crates.io-index)",
  "serde 1.0.94 (registry+https://github.com/rust-lang/crates.io-index)",
  "serde_json 1.0.40 (registry+https://github.com/rust-lang/crates.io-index)",
 ]
@@ -774,8 +774,8 @@ dependencies = [
 
 [[package]]
 name = "lsp-types"
-version = "0.58.1"
-source = "git+https://github.com/kjeremy/languageserver-types?branch=flatten#f3f793173bb1461602dabf83d324b638b3e6ec61"
+version = "0.59.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
 dependencies = [
  "bitflags 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
  "num-derive 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -1200,7 +1200,7 @@ dependencies = [
  "flexi_logger 0.13.2 (registry+https://github.com/rust-lang/crates.io-index)",
  "gen_lsp_server 0.2.0",
  "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)",
- "lsp-types 0.58.1 (git+https://github.com/kjeremy/languageserver-types?branch=flatten)",
+ "lsp-types 0.59.0 (registry+https://github.com/rust-lang/crates.io-index)",
  "parking_lot 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)",
  "ra_arena 0.1.0",
  "ra_ide_api 0.1.0",
@@ -2201,7 +2201,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
 "checksum linked-hash-map 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)" = "ae91b68aebc4ddb91978b11a1b02ddd8602a05ec19002801c5666000e05e0f83"
 "checksum lock_api 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ed946d4529956a20f2d63ebe1b69996d5a2137c91913fe3ebbeff957f5bca7ff"
 "checksum log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)" = "c84ec4b527950aa83a329754b01dbe3f58361d1c5efacd1f6d68c494d08a17c6"
-"checksum lsp-types 0.58.1 (git+https://github.com/kjeremy/languageserver-types?branch=flatten)" = "<none>"
+"checksum lsp-types 0.59.0 (registry+https://github.com/rust-lang/crates.io-index)" = "8961cde7f6f856771910edf37ff0729e59e02d2a8592a94c27495b746320e6ed"
 "checksum maplit 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "08cbb6b4fef96b6d77bfc40ec491b1690c779e77b05cd9f07f787ed376fd4c43"
 "checksum matches 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)" = "7ffc5c5338469d4d3ea17d269fa8ea3512ad247247c30bd2df69e68309ed0a08"
 "checksum memchr 2.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "2efc7bc57c883d4a4d6e3246905283d8dae951bb3bd32f49d6ef297f546e1c39"
diff --git a/crates/gen_lsp_server/Cargo.toml b/crates/gen_lsp_server/Cargo.toml
index 46b02a459..36a29265c 100644
--- a/crates/gen_lsp_server/Cargo.toml
+++ b/crates/gen_lsp_server/Cargo.toml
@@ -8,7 +8,7 @@ license = "MIT OR Apache-2.0"
 description = "Generic LSP server scaffold."
 
 [dependencies]
-lsp-types = { git = "https://github.com/kjeremy/languageserver-types", branch = "flatten" }
+lsp-types = "0.59.0"
 log = "0.4.3"
 serde_json = "1.0.34"
 serde = { version = "1.0.83", features = ["derive"] }
diff --git a/crates/ra_lsp_server/Cargo.toml b/crates/ra_lsp_server/Cargo.toml
index 9c9dda01f..50bc8111b 100644
--- a/crates/ra_lsp_server/Cargo.toml
+++ b/crates/ra_lsp_server/Cargo.toml
@@ -13,7 +13,7 @@ crossbeam-channel = "0.3.5"
 flexi_logger = "0.13.0"
 log = "0.4.3"
 url_serde = "0.2.0"
-lsp-types = { git = "https://github.com/kjeremy/languageserver-types", branch = "flatten", features = ["proposed"] }
+lsp-types = { version = "0.59.0", features = ["proposed"] }
 rustc-hash = "1.0"
 parking_lot = "0.8.0"
 
diff --git a/crates/ra_lsp_server/src/main_loop/handlers.rs b/crates/ra_lsp_server/src/main_loop/handlers.rs
index 6b407cb0c..62c8cbf71 100644
--- a/crates/ra_lsp_server/src/main_loop/handlers.rs
+++ b/crates/ra_lsp_server/src/main_loop/handlers.rs
@@ -2,11 +2,11 @@ use std::{fmt::Write as _, io::Write as _};
 
 use gen_lsp_server::ErrorCode;
 use lsp_types::{
-    CodeAction, CodeActionResponse, CodeLens, Command, Diagnostic, DiagnosticSeverity,
-    DocumentFormattingParams, DocumentHighlight, DocumentSymbol, FoldingRange, FoldingRangeKind,
-    FoldingRangeParams, Hover, HoverContents, Location, MarkupContent, MarkupKind, Position,
-    PrepareRenameResponse, Range, RenameParams, SymbolInformation, TextDocumentIdentifier,
-    TextEdit, WorkspaceEdit,
+    CodeAction, CodeActionResponse, CodeLens, Command, CompletionItem, Diagnostic,
+    DiagnosticSeverity, DocumentFormattingParams, DocumentHighlight, DocumentSymbol, FoldingRange,
+    FoldingRangeKind, FoldingRangeParams, Hover, HoverContents, Location, MarkupContent,
+    MarkupKind, Position, PrepareRenameResponse, Range, RenameParams, SymbolInformation,
+    TextDocumentIdentifier, TextEdit, WorkspaceEdit,
 };
 use ra_ide_api::{
     AssistId, Cancelable, FileId, FilePosition, FileRange, FoldKind, Query, RangeInfo,
@@ -212,7 +212,7 @@ pub fn handle_document_symbol(
         }
     }
 
-    Ok(Some(req::DocumentSymbolResponse::Nested(res)))
+    Ok(Some(res.into()))
 }
 
 pub fn handle_workspace_symbol(
@@ -275,7 +275,7 @@ pub fn handle_goto_definition(
         .map(|nav| RangeInfo::new(nav_range, nav))
         .map(|nav| to_location_link(&nav, &world, &line_index))
         .collect::<Result<Vec<_>>>()?;
-    Ok(Some(req::GotoDefinitionResponse::Link(res)))
+    Ok(Some(res.into()))
 }
 
 pub fn handle_goto_implementation(
@@ -295,7 +295,7 @@ pub fn handle_goto_implementation(
         .map(|nav| RangeInfo::new(nav_range, nav))
         .map(|nav| to_location_link(&nav, &world, &line_index))
         .collect::<Result<Vec<_>>>()?;
-    Ok(Some(req::GotoDefinitionResponse::Link(res)))
+    Ok(Some(res.into()))
 }
 
 pub fn handle_goto_type_definition(
@@ -315,7 +315,7 @@ pub fn handle_goto_type_definition(
         .map(|nav| RangeInfo::new(nav_range, nav))
         .map(|nav| to_location_link(&nav, &world, &line_index))
         .collect::<Result<Vec<_>>>()?;
-    Ok(Some(req::GotoDefinitionResponse::Link(res)))
+    Ok(Some(res.into()))
 }
 
 pub fn handle_parent_module(
@@ -433,9 +433,10 @@ pub fn handle_completion(
         Some(items) => items,
     };
     let line_index = world.analysis().file_line_index(position.file_id);
-    let items = items.into_iter().map(|item| item.conv_with(&line_index)).collect();
+    let items: Vec<CompletionItem> =
+        items.into_iter().map(|item| item.conv_with(&line_index)).collect();
 
-    Ok(Some(req::CompletionResponse::Array(items)))
+    Ok(Some(items.into()))
 }
 
 pub fn handle_folding_range(
-- 
cgit v1.2.3