From 27303da419df800f96c93e2618d5429e980a4987 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Tue, 6 Aug 2019 09:29:06 +0200 Subject: use Conv for severity --- crates/ra_lsp_server/src/conv.rs | 20 +++++++++++++++----- crates/ra_lsp_server/src/main_loop/handlers.rs | 21 ++++++--------------- 2 files changed, 21 insertions(+), 20 deletions(-) (limited to 'crates/ra_lsp_server') diff --git a/crates/ra_lsp_server/src/conv.rs b/crates/ra_lsp_server/src/conv.rs index 59c5e1582..df8ea6e0d 100644 --- a/crates/ra_lsp_server/src/conv.rs +++ b/crates/ra_lsp_server/src/conv.rs @@ -1,13 +1,13 @@ use lsp_types::{ - self, CreateFile, DocumentChangeOperation, DocumentChanges, Documentation, Location, - LocationLink, MarkupContent, MarkupKind, Position, Range, RenameFile, ResourceOp, SymbolKind, - TextDocumentEdit, TextDocumentIdentifier, TextDocumentItem, TextDocumentPositionParams, Url, - VersionedTextDocumentIdentifier, WorkspaceEdit, + self, CreateFile, DiagnosticSeverity, DocumentChangeOperation, DocumentChanges, Documentation, + Location, LocationLink, MarkupContent, MarkupKind, Position, Range, RenameFile, ResourceOp, + SymbolKind, TextDocumentEdit, TextDocumentIdentifier, TextDocumentItem, + TextDocumentPositionParams, Url, VersionedTextDocumentIdentifier, WorkspaceEdit, }; use ra_ide_api::{ translate_offset_with_edit, CompletionItem, CompletionItemKind, FileId, FilePosition, FileRange, FileSystemEdit, InsertTextFormat, LineCol, LineIndex, NavigationTarget, RangeInfo, - SourceChange, SourceFileEdit, + Severity, SourceChange, SourceFileEdit, }; use ra_syntax::{SyntaxKind, TextRange, TextUnit}; use ra_text_edit::{AtomTextEdit, TextEdit}; @@ -79,6 +79,16 @@ impl Conv for CompletionItemKind { } } +impl Conv for Severity { + type Output = DiagnosticSeverity; + fn conv(self) -> DiagnosticSeverity { + match self { + Severity::Error => DiagnosticSeverity::Error, + Severity::WeakWarning => DiagnosticSeverity::Hint, + } + } +} + impl ConvWith for CompletionItem { type Ctx = LineIndex; type Output = ::lsp_types::CompletionItem; diff --git a/crates/ra_lsp_server/src/main_loop/handlers.rs b/crates/ra_lsp_server/src/main_loop/handlers.rs index c2a44ffa0..005ce08b3 100644 --- a/crates/ra_lsp_server/src/main_loop/handlers.rs +++ b/crates/ra_lsp_server/src/main_loop/handlers.rs @@ -3,13 +3,13 @@ use std::{fmt::Write as _, io::Write as _}; use gen_lsp_server::ErrorCode; use lsp_types::{ 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, + 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, RunnableKind, Severity, + AssistId, Cancelable, FileId, FilePosition, FileRange, FoldKind, Query, RunnableKind, }; use ra_prof::profile; use ra_syntax::{AstNode, SyntaxKind, TextRange, TextUnit}; @@ -838,7 +838,7 @@ pub fn publish_diagnostics( .into_iter() .map(|d| Diagnostic { range: d.range.conv_with(&line_index), - severity: Some(to_diagnostic_severity(d.severity)), + severity: Some(d.severity.conv()), code: None, source: Some("rust-analyzer".to_string()), message: d.message, @@ -871,15 +871,6 @@ fn highlight(world: &WorldSnapshot, file_id: FileId) -> Result> Ok(res) } -fn to_diagnostic_severity(severity: Severity) -> DiagnosticSeverity { - use ra_ide_api::Severity::*; - - match severity { - Error => DiagnosticSeverity::Error, - WeakWarning => DiagnosticSeverity::Hint, - } -} - pub fn handle_inlay_hints( world: WorldSnapshot, params: InlayHintsParams, -- cgit v1.2.3