Skip to content
This repository was archived by the owner on Dec 29, 2022. It is now read-only.

Commit 5cdf425

Browse files
committed
Move rls-span crate
Based on rust-dev-tools/rls-span@45700a3
1 parent 63d8cd1 commit 5cdf425

File tree

5 files changed

+527
-1
lines changed

5 files changed

+527
-1
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ rls-analysis = "0.16.12"
2525
rls-blacklist = "0.1.3"
2626
rls-data = { version = "0.18.2", features = ["serialize-serde", "serialize-rustc"] }
2727
rls-rustc = "0.5.0"
28+
rls-span = { version = "0.4", features = ["serialize-serde"] }
2829

2930
cargo = { git = "https://github.com/rust-lang/cargo", rev = "4e74e2fc0908524d17735c768067117d3e84ee9c" }
3031
cargo_metadata = "0.7"
@@ -41,7 +42,6 @@ num_cpus = "1"
4142
racer = { version = "=2.1.18", default-features = false }
4243
rand = "0.6"
4344
rayon = "1"
44-
rls-span = { version = "0.4", features = ["serialize-serde"] }
4545
rls-vfs = "0.7"
4646
rustc_tools_util = "0.1.1"
4747
rustfmt-nightly = "1.0.1"

rls-span/.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
target
2+
Cargo.lock

rls-span/Cargo.toml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
[package]
2+
name = "rls-span"
3+
version = "0.4.1"
4+
authors = ["Nick Cameron <ncameron@mozilla.com>"]
5+
description = "Types for identifying code spans/ranges"
6+
license = "Apache-2.0/MIT"
7+
repository = "https://github.com/rust-dev-tools/rls-span"
8+
categories = ["development-tools"]
9+
10+
[features]
11+
default = []
12+
serialize-serde = ["serde", "serde_derive"]
13+
serialize-rustc = ["rustc-serialize"]
14+
15+
[dependencies]
16+
rustc-serialize = { version = "0.3", optional = true }
17+
serde = { version = "1.0", optional = true }
18+
serde_derive = { version = "1.0", optional = true }

rls-span/src/compiler.rs

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
// Copyright 2016 The RLS Project Developers.
2+
//
3+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
4+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
5+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
6+
// option. This file may not be copied, modified, or distributed
7+
// except according to those terms.
8+
9+
/// These are the structures emitted by the compiler as part of JSON errors.
10+
/// The original source can be found at
11+
/// https://github.com/rust-lang/rust/blob/master/src/libsyntax/json.rs
12+
13+
use std::path::PathBuf;
14+
15+
use {Span, Row, Column, OneIndexed};
16+
17+
#[cfg_attr(feature = "serialize-serde", derive(Deserialize))]
18+
#[derive(Debug, Clone)]
19+
pub struct DiagnosticSpan {
20+
pub file_name: String,
21+
pub byte_start: u32,
22+
pub byte_end: u32,
23+
/// 1-based.
24+
pub line_start: usize,
25+
pub line_end: usize,
26+
/// 1-based, character offset.
27+
pub column_start: usize,
28+
pub column_end: usize,
29+
/// Is this a "primary" span -- meaning the point, or one of the points,
30+
/// where the error occurred?
31+
pub is_primary: bool,
32+
/// Source text from the start of line_start to the end of line_end.
33+
pub text: Vec<DiagnosticSpanLine>,
34+
/// Label that should be placed at this location (if any)
35+
pub label: Option<String>,
36+
/// If we are suggesting a replacement, this will contain text
37+
/// that should be sliced in atop this span. You may prefer to
38+
/// load the fully rendered version from the parent `Diagnostic`,
39+
/// however.
40+
pub suggested_replacement: Option<String>,
41+
/// Macro invocations that created the code at this span, if any.
42+
pub expansion: Option<Box<DiagnosticSpanMacroExpansion>>,
43+
}
44+
45+
impl DiagnosticSpan {
46+
pub fn rls_span(&self) -> Span<OneIndexed> {
47+
Span::new(
48+
Row::new(self.line_start as u32),
49+
Row::new(self.line_end as u32),
50+
Column::new(self.column_start as u32),
51+
Column::new(self.column_end as u32),
52+
PathBuf::from(&self.file_name),
53+
)
54+
}
55+
}
56+
57+
#[cfg_attr(feature = "serialize-serde", derive(Deserialize))]
58+
#[derive(Debug, Clone)]
59+
pub struct DiagnosticSpanLine {
60+
pub text: String,
61+
62+
/// 1-based, character offset in self.text.
63+
pub highlight_start: usize,
64+
65+
pub highlight_end: usize,
66+
}
67+
68+
#[cfg_attr(feature = "serialize-serde", derive(Deserialize))]
69+
#[derive(Debug, Clone)]
70+
pub struct DiagnosticSpanMacroExpansion {
71+
/// span where macro was applied to generate this code; note that
72+
/// this may itself derive from a macro (if
73+
/// `span.expansion.is_some()`)
74+
pub span: DiagnosticSpan,
75+
76+
/// name of macro that was applied (e.g., "foo!" or "#[derive(Eq)]")
77+
pub macro_decl_name: String,
78+
79+
/// span where macro was defined (if known)
80+
pub def_site_span: Option<DiagnosticSpan>,
81+
}

0 commit comments

Comments
 (0)