From f1f2804c71ee997e36904dea72911104b2e2375b Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Sat, 22 Dec 2018 01:59:32 +0300 Subject: move completion items to conv --- crates/gen_lsp_server/Cargo.toml | 2 +- crates/gen_lsp_server/src/msg.rs | 2 +- crates/ra_hir/src/function/scope.rs | 2 +- crates/ra_lsp_server/src/conv.rs | 28 +++++++++++++++++++++++-- crates/ra_lsp_server/src/main_loop/handlers.rs | 29 ++++---------------------- 5 files changed, 33 insertions(+), 30 deletions(-) diff --git a/crates/gen_lsp_server/Cargo.toml b/crates/gen_lsp_server/Cargo.toml index 5f90d39d6..9776a82e3 100644 --- a/crates/gen_lsp_server/Cargo.toml +++ b/crates/gen_lsp_server/Cargo.toml @@ -12,5 +12,5 @@ languageserver-types = "0.53.0" log = "0.4.3" failure = "0.1.2" serde_json = "1.0.24" -serde = "1.0.71" +serde = { version = "1.0.71", features = ["derive"] } crossbeam-channel = "0.2.4" diff --git a/crates/gen_lsp_server/src/msg.rs b/crates/gen_lsp_server/src/msg.rs index ef6358cb1..af901d0d2 100644 --- a/crates/gen_lsp_server/src/msg.rs +++ b/crates/gen_lsp_server/src/msg.rs @@ -7,7 +7,7 @@ use failure::{bail, format_err}; use crate::Result; -#[derive(Debug, Serialize, Deserialize, Clone)] +#[derive(Serialize, Deserialize, Debug, Clone)] #[serde(untagged)] pub enum RawMessage { Request(RawRequest), diff --git a/crates/ra_hir/src/function/scope.rs b/crates/ra_hir/src/function/scope.rs index 9f1aa1ef2..d12f1781e 100644 --- a/crates/ra_hir/src/function/scope.rs +++ b/crates/ra_hir/src/function/scope.rs @@ -95,7 +95,7 @@ impl FnScopes { r1.start().cmp(&r2.start()) } }) - .map(|(ptr, scope)| *scope) + .map(|(_ptr, scope)| *scope) .unwrap_or(original_scope) } diff --git a/crates/ra_lsp_server/src/conv.rs b/crates/ra_lsp_server/src/conv.rs index 218ded4ee..973e0915e 100644 --- a/crates/ra_lsp_server/src/conv.rs +++ b/crates/ra_lsp_server/src/conv.rs @@ -1,8 +1,8 @@ use languageserver_types::{ self, Location, Position, Range, SymbolKind, TextDocumentEdit, TextDocumentIdentifier, - TextDocumentItem, TextDocumentPositionParams, Url, VersionedTextDocumentIdentifier, + TextDocumentItem, TextDocumentPositionParams, Url, VersionedTextDocumentIdentifier, InsertTextFormat, }; -use ra_analysis::{FileId, FileSystemEdit, SourceChange, SourceFileEdit, FilePosition}; +use ra_analysis::{FileId, FileSystemEdit, SourceChange, SourceFileEdit, FilePosition, CompletionItem, InsertText}; use ra_editor::{LineCol, LineIndex}; use ra_text_edit::{AtomTextEdit, TextEdit}; use ra_syntax::{SyntaxKind, TextRange, TextUnit}; @@ -45,6 +45,30 @@ impl Conv for SyntaxKind { } } +impl Conv for CompletionItem { + type Output = ::languageserver_types::CompletionItem; + + fn conv(self) -> ::Output { + let mut res = ::languageserver_types::CompletionItem { + label: self.label().to_string(), + filter_text: Some(self.lookup().to_string()), + ..Default::default() + }; + match self.insert_text() { + InsertText::PlainText { text } => { + res.insert_text = Some(text); + res.insert_text_format = Some(InsertTextFormat::PlainText); + } + InsertText::Snippet { text } => { + res.insert_text = Some(text); + res.insert_text_format = Some(InsertTextFormat::Snippet); + res.kind = Some(languageserver_types::CompletionItemKind::Keyword); + } + } + res + } +} + impl ConvWith for Position { type Ctx = LineIndex; type Output = TextUnit; diff --git a/crates/ra_lsp_server/src/main_loop/handlers.rs b/crates/ra_lsp_server/src/main_loop/handlers.rs index 2dfeb061a..252d1ba3e 100644 --- a/crates/ra_lsp_server/src/main_loop/handlers.rs +++ b/crates/ra_lsp_server/src/main_loop/handlers.rs @@ -2,13 +2,13 @@ use std::collections::HashMap; use gen_lsp_server::ErrorCode; use languageserver_types::{ - CodeActionResponse, Command, CompletionItem, CompletionItemKind, Diagnostic, + CodeActionResponse, Command, Diagnostic, DiagnosticSeverity, DocumentSymbol, Documentation, FoldingRange, FoldingRangeKind, - FoldingRangeParams, InsertTextFormat, Location, MarkupContent, MarkupKind, MarkedString, Position, + FoldingRangeParams, Location, MarkupContent, MarkupKind, MarkedString, Position, PrepareRenameResponse, RenameParams, SymbolInformation, TextDocumentIdentifier, TextEdit, WorkspaceEdit, ParameterInformation, ParameterLabel, SignatureInformation, Hover, HoverContents, }; -use ra_analysis::{FileId, FoldKind, Query, RunnableKind, FilePosition, InsertText}; +use ra_analysis::{FileId, FoldKind, Query, RunnableKind, FilePosition}; use ra_syntax::{TextUnit, text_utils::intersect}; use ra_text_edit::text_utils::contains_offset_nonstrict; use rustc_hash::FxHashMap; @@ -419,28 +419,7 @@ pub fn handle_completion( None => return Ok(None), Some(items) => items, }; - let items = items - .into_iter() - .map(|item| { - let mut res = CompletionItem { - label: item.label().to_string(), - filter_text: Some(item.lookup().to_string()), - ..Default::default() - }; - match item.insert_text() { - InsertText::PlainText { text } => { - res.insert_text = Some(text); - res.insert_text_format = Some(InsertTextFormat::PlainText); - } - InsertText::Snippet { text } => { - res.insert_text = Some(text); - res.insert_text_format = Some(InsertTextFormat::Snippet); - res.kind = Some(CompletionItemKind::Keyword); - } - } - res - }) - .collect(); + let items = items.into_iter().map(|item| item.conv()).collect(); Ok(Some(req::CompletionResponse::Array(items))) } -- cgit v1.2.3