move completion items to conv

This commit is contained in:
Aleksey Kladov 2018-12-22 01:59:32 +03:00
parent 328d123f5b
commit f1f2804c71
5 changed files with 33 additions and 30 deletions

View file

@ -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"

View file

@ -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),

View file

@ -95,7 +95,7 @@ impl FnScopes {
r1.start().cmp(&r2.start())
}
})
.map(|(ptr, scope)| *scope)
.map(|(_ptr, scope)| *scope)
.unwrap_or(original_scope)
}

View file

@ -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) -> <Self as Conv>::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;

View file

@ -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)))
}