mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-12-26 13:03:31 +00:00
Better structure
This commit is contained in:
parent
220813dcb0
commit
f1a5c489fd
4 changed files with 15 additions and 20 deletions
1
Cargo.lock
generated
1
Cargo.lock
generated
|
@ -1376,7 +1376,6 @@ name = "rust-analyzer"
|
|||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"cargo_metadata",
|
||||
"crossbeam-channel",
|
||||
"env_logger",
|
||||
"globset",
|
||||
|
|
|
@ -12,6 +12,11 @@ use std::{
|
|||
use cargo_metadata::Message;
|
||||
use crossbeam_channel::{never, select, unbounded, Receiver, RecvError, Sender};
|
||||
|
||||
pub use cargo_metadata::diagnostic::{
|
||||
Applicability, Diagnostic, DiagnosticLevel, DiagnosticSpan,
|
||||
DiagnosticSpanMacroExpansion,
|
||||
};
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
||||
pub enum FlycheckConfig {
|
||||
CargoCommand { command: String, all_targets: bool, all_features: bool, extra_args: Vec<String> },
|
||||
|
@ -52,7 +57,7 @@ pub enum CheckTask {
|
|||
ClearDiagnostics,
|
||||
|
||||
/// Request adding a diagnostic with fixes included to a file
|
||||
AddDiagnostic { workspace_root: PathBuf, diagnostic: cargo_metadata::diagnostic::Diagnostic },
|
||||
AddDiagnostic { workspace_root: PathBuf, diagnostic: Diagnostic },
|
||||
|
||||
/// Request check progress notification to client
|
||||
Status(Status),
|
||||
|
@ -239,12 +244,6 @@ impl FlycheckThread {
|
|||
}
|
||||
}
|
||||
|
||||
// #[derive(Debug)]
|
||||
// pub struct DiagnosticWithFixes {
|
||||
// diagnostic: Diagnostic,
|
||||
// fixes: Vec<CodeAction>,
|
||||
// }
|
||||
|
||||
enum CheckEvent {
|
||||
Begin,
|
||||
Msg(cargo_metadata::Message),
|
||||
|
|
|
@ -29,7 +29,6 @@ rustc-hash = "1.1.0"
|
|||
serde = { version = "1.0.106", features = ["derive"] }
|
||||
serde_json = "1.0.48"
|
||||
threadpool = "1.7.1"
|
||||
cargo_metadata = "0.10.0"
|
||||
|
||||
stdx = { path = "../stdx" }
|
||||
|
||||
|
|
|
@ -1,13 +1,5 @@
|
|||
//! This module provides the functionality needed to convert diagnostics from
|
||||
//! `cargo check` json format to the LSP diagnostic format.
|
||||
use cargo_metadata::diagnostic::{
|
||||
Applicability, Diagnostic as RustDiagnostic, DiagnosticLevel, DiagnosticSpan,
|
||||
DiagnosticSpanMacroExpansion,
|
||||
};
|
||||
use lsp_types::{
|
||||
CodeAction, Diagnostic, DiagnosticRelatedInformation, DiagnosticSeverity, DiagnosticTag,
|
||||
Location, NumberOrString, Position, Range, TextEdit, Url, WorkspaceEdit,
|
||||
};
|
||||
use std::{
|
||||
collections::HashMap,
|
||||
fmt::Write,
|
||||
|
@ -15,6 +7,12 @@ use std::{
|
|||
str::FromStr,
|
||||
};
|
||||
|
||||
use lsp_types::{
|
||||
CodeAction, Diagnostic, DiagnosticRelatedInformation, DiagnosticSeverity, DiagnosticTag,
|
||||
Location, NumberOrString, Position, Range, TextEdit, Url, WorkspaceEdit,
|
||||
};
|
||||
use ra_flycheck::{Applicability, DiagnosticLevel, DiagnosticSpan, DiagnosticSpanMacroExpansion};
|
||||
|
||||
/// Converts a Rust level string to a LSP severity
|
||||
fn map_level_to_severity(val: DiagnosticLevel) -> Option<DiagnosticSeverity> {
|
||||
match val {
|
||||
|
@ -91,7 +89,7 @@ fn map_secondary_span_to_related(
|
|||
}
|
||||
|
||||
/// Determines if diagnostic is related to unused code
|
||||
fn is_unused_or_unnecessary(rd: &RustDiagnostic) -> bool {
|
||||
fn is_unused_or_unnecessary(rd: &ra_flycheck::Diagnostic) -> bool {
|
||||
if let Some(code) = &rd.code {
|
||||
match code.code.as_str() {
|
||||
"dead_code" | "unknown_lints" | "unreachable_code" | "unused_attributes"
|
||||
|
@ -122,7 +120,7 @@ enum MappedRustChildDiagnostic {
|
|||
}
|
||||
|
||||
fn map_rust_child_diagnostic(
|
||||
rd: &RustDiagnostic,
|
||||
rd: &ra_flycheck::Diagnostic,
|
||||
workspace_root: &PathBuf,
|
||||
) -> MappedRustChildDiagnostic {
|
||||
let spans: Vec<&DiagnosticSpan> = rd.spans.iter().filter(|s| s.is_primary).collect();
|
||||
|
@ -179,7 +177,7 @@ pub(crate) struct MappedRustDiagnostic {
|
|||
///
|
||||
/// If the diagnostic has no primary span this will return `None`
|
||||
pub(crate) fn map_rust_diagnostic_to_lsp(
|
||||
rd: &RustDiagnostic,
|
||||
rd: &ra_flycheck::Diagnostic,
|
||||
workspace_root: &PathBuf,
|
||||
) -> Vec<MappedRustDiagnostic> {
|
||||
let primary_spans: Vec<&DiagnosticSpan> = rd.spans.iter().filter(|s| s.is_primary).collect();
|
||||
|
|
Loading…
Reference in a new issue