Skip to content

Commit 7ddfa87

Browse files
committed
Merge branch 'default' into cli-highlight
2 parents 0e0f13d + 2347cba commit 7ddfa87

File tree

9 files changed

+292
-209
lines changed

9 files changed

+292
-209
lines changed

.github/workflows/ci.yml

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,10 +77,9 @@ jobs:
7777
profile: minimal
7878
toolchain: stable
7979
override: true
80-
- uses: actions-rs/cargo@v1
81-
with:
82-
command: install
83-
args: wasm-pack
80+
- name: Install wasm-pack
81+
run: |
82+
curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh
8483
- run: npm install
8584
working-directory: vscode
8685
- run: npm run package

Cargo.lock

Lines changed: 142 additions & 139 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ lto = true
1616

1717
[dependencies]
1818
ansi_term = "0.12"
19-
codespan = "0.8"
20-
codespan-reporting = "0.8"
19+
codespan = "0.9"
20+
codespan-reporting = "0.9"
2121
failure = "0.1"
2222
multisplice = "^0.3.0"
2323
rms-check = { path = "crates/rms-check" }

crates/rms-check-lsp/Cargo.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@ repository = "https://github.com/goto-bus-stop/rms-check.git"
88
edition = "2018"
99

1010
[dependencies]
11-
codespan = "0.8"
12-
codespan-lsp = "0.8"
11+
codespan = "0.9"
12+
codespan-lsp = "0.9"
1313
jsonrpc-core = "14.0"
1414
lazy_static = "1.4"
15-
lsp-types = "0.70"
15+
lsp-types = "0.73"
1616
multisplice = "0.3"
1717
rms-check = { path = "../rms-check/" }
1818
serde_json = "1.0"

crates/rms-check-lsp/src/lib.rs

Lines changed: 49 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,17 @@ use codespan_lsp::range_to_byte_span;
1313
use jsonrpc_core::{ErrorCode, IoHandler, Params};
1414
use lsp_types::{
1515
CodeAction, CodeActionParams, CodeActionProviderCapability, Diagnostic,
16-
DidChangeTextDocumentParams, DidCloseTextDocumentParams, DidOpenTextDocumentParams,
17-
DocumentFormattingParams, FoldingRange, FoldingRangeParams, FoldingRangeProviderCapability,
18-
InitializeParams, InitializeResult, NumberOrString, PublishDiagnosticsParams,
19-
ServerCapabilities, ServerInfo, SignatureHelpOptions, TextDocumentItem,
20-
TextDocumentPositionParams, TextDocumentSyncCapability, TextDocumentSyncKind, TextEdit, Url,
21-
WorkDoneProgressOptions, WorkspaceEdit,
16+
DiagnosticRelatedInformation, DiagnosticSeverity, DidChangeTextDocumentParams,
17+
DidCloseTextDocumentParams, DidOpenTextDocumentParams, DocumentFormattingParams, FoldingRange,
18+
FoldingRangeParams, FoldingRangeProviderCapability, InitializeParams, InitializeResult,
19+
Location, NumberOrString, PublishDiagnosticsParams, ServerCapabilities, ServerInfo,
20+
SignatureHelpOptions, TextDocumentItem, TextDocumentPositionParams, TextDocumentSyncCapability,
21+
TextDocumentSyncKind, TextEdit, Url, WorkDoneProgressOptions, WorkspaceEdit,
2222
};
2323
use multisplice::Multisplice;
2424
use rms_check::{
25-
AutoFixReplacement, Compatibility, FormatOptions, RMSCheck, RMSCheckResult, RMSFile, Warning,
25+
AutoFixReplacement, Compatibility, FormatOptions, RMSCheck, RMSCheckResult, RMSFile, Severity,
26+
Warning,
2627
};
2728
use serde_json::{self, json};
2829
use std::borrow::Cow;
@@ -47,20 +48,47 @@ impl<Emit> Inner<Emit>
4748
where
4849
Emit: Fn(serde_json::Value) + Send + 'static,
4950
{
50-
/// Convert a codespan file name to an LSP file URL.
51-
fn codespan_name_to_url(&self, filename: &str) -> Result<Url, ()> {
52-
filename.parse().map_err(|_| ())
53-
}
54-
5551
/// Convert an rms-check warning to an LSP diagnostic.
5652
fn make_lsp_diagnostic(&self, files: &Files<Cow<'_, str>>, warn: &Warning) -> Diagnostic {
57-
let diag = codespan_lsp::make_lsp_diagnostic(
58-
files,
59-
"rms-check".to_string(),
60-
warn.diagnostic().clone(),
61-
|f| self.codespan_name_to_url(files.name(f).to_string_lossy().as_ref()),
62-
)
63-
.expect("could not convert diagnostic to lsp");
53+
let main_label = warn.main_label();
54+
let span = Span::new(main_label.range.start as u32, main_label.range.end as u32);
55+
let more_labels = warn.labels();
56+
57+
let diag = Diagnostic {
58+
range: codespan_lsp::byte_span_to_range(files, main_label.file_id, span).unwrap(),
59+
severity: Some(match warn.severity() {
60+
Severity::Bug => DiagnosticSeverity::Error,
61+
Severity::Error => DiagnosticSeverity::Error,
62+
Severity::Warning => DiagnosticSeverity::Warning,
63+
Severity::Note => DiagnosticSeverity::Information,
64+
Severity::Help => DiagnosticSeverity::Hint,
65+
}),
66+
source: Some("rms-check".into()),
67+
code: warn
68+
.diagnostic()
69+
.code
70+
.clone()
71+
.map(lsp_types::NumberOrString::String),
72+
message: warn.message().into(),
73+
related_information: Some(
74+
more_labels
75+
.iter()
76+
.map(|label| DiagnosticRelatedInformation {
77+
location: Location {
78+
uri: files.name(label.file_id).to_string_lossy().parse().unwrap(),
79+
range: codespan_lsp::byte_span_to_range(
80+
files,
81+
label.file_id,
82+
Span::new(label.range.start as u32, label.range.end as u32),
83+
)
84+
.unwrap(),
85+
},
86+
message: label.message.clone(),
87+
})
88+
.collect(),
89+
),
90+
tags: None,
91+
};
6492

6593
Diagnostic {
6694
code: warn
@@ -166,9 +194,8 @@ where
166194
.map_err(|_| jsonrpc_core::Error::new(ErrorCode::InternalError))?;
167195

168196
let warnings = result.iter().filter(|warn| {
169-
let label = &warn.diagnostic().primary_label;
170-
start >= label.span.start() && start <= label.span.end()
171-
|| end >= label.span.start() && end <= label.span.end()
197+
let label = &warn.diagnostic().labels[0];
198+
label.range.contains(&start.to_usize()) && label.range.contains(&end.to_usize())
172199
});
173200

174201
let mut actions = vec![];

crates/rms-check/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ edition = "2018"
99

1010
[dependencies]
1111
chardet = "0.2"
12-
codespan = "0.8"
13-
codespan-reporting = "0.8"
12+
codespan = "0.9"
13+
codespan-reporting = "0.9"
1414
encoding_rs = "0.8"
1515
itertools = "0.9"
1616
lazy_static = "1.4"

crates/rms-check/src/checker.rs

Lines changed: 72 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,22 @@ use crate::state::{Compatibility, ParseState};
55
use crate::wordize::Word;
66
use crate::RMSFile;
77
use codespan::{ByteIndex, FileId, Span};
8-
pub use codespan_reporting::diagnostic::{Diagnostic, Label, Severity};
8+
use codespan_reporting::diagnostic::LabelStyle;
9+
pub use codespan_reporting::diagnostic::Severity;
910
use lazy_static::lazy_static;
11+
use std::ops::Range;
12+
13+
/// Represents a diagnostic message that can provide information like errors and warnings to the user.
14+
pub type Diagnostic = codespan_reporting::diagnostic::Diagnostic<FileId>;
15+
/// A label describing an underlined region of code associated with a diagnostic.
16+
pub type Label = codespan_reporting::diagnostic::Label<FileId>;
17+
18+
fn span_to_range(span: Span) -> Range<usize> {
19+
Range {
20+
start: span.start().to_usize(),
21+
end: span.end().to_usize(),
22+
}
23+
}
1024

1125
#[derive(Debug, Clone)]
1226
pub enum AutoFixReplacement {
@@ -103,7 +117,7 @@ impl Suggestion {
103117
}
104118

105119
/// A warning.
106-
#[derive(Debug, Clone)]
120+
#[derive(Clone)]
107121
pub struct Warning {
108122
diagnostic: Diagnostic,
109123
/// A change suggestion: when present, the problem can be fixed by replacing the
@@ -120,9 +134,12 @@ impl Warning {
120134
pub const fn severity(&self) -> Severity {
121135
self.diagnostic.severity
122136
}
137+
pub fn main_label(&self) -> &Label {
138+
&self.diagnostic.labels[0]
139+
}
123140
/// Get additional labels for this warning.
124-
pub const fn labels(&self) -> &Vec<Label> {
125-
&self.diagnostic.secondary_labels
141+
pub fn labels(&self) -> &[Label] {
142+
&self.diagnostic.labels[1..]
126143
}
127144
/// Get the human-readable error message.
128145
pub fn message(&self) -> &str {
@@ -143,10 +160,14 @@ impl Warning {
143160
pub(crate) fn warning(file_id: FileId, span: Span, message: impl Into<String>) -> Self {
144161
let message: String = message.into();
145162
Warning {
146-
diagnostic: Diagnostic::new_warning(
147-
message.clone(),
148-
Label::new(file_id, span, message),
149-
),
163+
diagnostic: Diagnostic::warning()
164+
.with_message(message.clone())
165+
.with_labels(vec![Label::new(
166+
LabelStyle::Primary,
167+
file_id,
168+
span_to_range(span),
169+
)
170+
.with_message(message)]),
150171
suggestions: vec![],
151172
}
152173
}
@@ -156,7 +177,14 @@ impl Warning {
156177
pub(crate) fn error(file_id: FileId, span: Span, message: impl Into<String>) -> Self {
157178
let message: String = message.into();
158179
Warning {
159-
diagnostic: Diagnostic::new_error(message.clone(), Label::new(file_id, span, message)),
180+
diagnostic: Diagnostic::error()
181+
.with_message(message.clone())
182+
.with_labels(vec![Label::new(
183+
LabelStyle::Primary,
184+
file_id,
185+
span_to_range(span),
186+
)
187+
.with_message(message)]),
160188
suggestions: vec![],
161189
}
162190
}
@@ -169,9 +197,9 @@ impl Warning {
169197

170198
/// Add a note referencing a snippet of code.
171199
pub(crate) fn note_at(mut self, file_id: FileId, span: Span, message: &str) -> Self {
172-
self.diagnostic = self
173-
.diagnostic
174-
.with_secondary_labels(vec![Label::new(file_id, span, message)]);
200+
self.diagnostic.labels.push(
201+
Label::new(LabelStyle::Secondary, file_id, span_to_range(span)).with_message(message),
202+
);
175203
self
176204
}
177205

@@ -188,10 +216,14 @@ impl Word<'_> {
188216
pub(crate) fn warning(&self, message: impl Into<String>) -> Warning {
189217
let message: String = message.into();
190218
Warning {
191-
diagnostic: Diagnostic::new_warning(
192-
message.clone(),
193-
Label::new(self.file, self.span, message),
194-
),
219+
diagnostic: Diagnostic::warning()
220+
.with_message(message.clone())
221+
.with_labels(vec![Label::new(
222+
LabelStyle::Primary,
223+
self.file,
224+
span_to_range(self.span),
225+
)
226+
.with_message(message)]),
195227
suggestions: vec![],
196228
}
197229
}
@@ -200,10 +232,14 @@ impl Word<'_> {
200232
pub(crate) fn error(&self, message: impl Into<String>) -> Warning {
201233
let message: String = message.into();
202234
Warning {
203-
diagnostic: Diagnostic::new_error(
204-
message.clone(),
205-
Label::new(self.file, self.span, message),
206-
),
235+
diagnostic: Diagnostic::error()
236+
.with_message(message.clone())
237+
.with_labels(vec![Label::new(
238+
LabelStyle::Primary,
239+
self.file,
240+
span_to_range(self.span),
241+
)
242+
.with_message(message)]),
207243
suggestions: vec![],
208244
}
209245
}
@@ -215,10 +251,14 @@ impl Atom<'_> {
215251
pub(crate) fn warning(&self, message: impl Into<String>) -> Warning {
216252
let message: String = message.into();
217253
Warning {
218-
diagnostic: Diagnostic::new_warning(
219-
message.clone(),
220-
Label::new(self.file, self.span, message),
221-
),
254+
diagnostic: Diagnostic::warning()
255+
.with_message(message.clone())
256+
.with_labels(vec![Label::new(
257+
LabelStyle::Primary,
258+
self.file,
259+
span_to_range(self.span),
260+
)
261+
.with_message(message)]),
222262
suggestions: vec![],
223263
}
224264
}
@@ -227,10 +267,14 @@ impl Atom<'_> {
227267
pub(crate) fn error(&self, message: impl Into<String>) -> Warning {
228268
let message: String = message.into();
229269
Warning {
230-
diagnostic: Diagnostic::new_error(
231-
message.clone(),
232-
Label::new(self.file, self.span, message),
233-
),
270+
diagnostic: Diagnostic::error()
271+
.with_message(message.clone())
272+
.with_labels(vec![Label::new(
273+
LabelStyle::Primary,
274+
self.file,
275+
span_to_range(self.span),
276+
)
277+
.with_message(message)]),
234278
suggestions: vec![],
235279
}
236280
}

crates/rms-check/src/lints/arg_types.rs

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,11 @@ mod tests {
335335
use super::*;
336336
use crate::{Compatibility, RMSCheck, RMSFile, Severity};
337337
use codespan::{ColumnIndex, LineIndex, Location};
338+
use std::ops::Range;
339+
340+
fn to_span(range: Range<usize>) -> Span {
341+
Span::new(range.start as u32, range.end as u32)
342+
}
338343

339344
#[test]
340345
fn is_numeric_test() {
@@ -374,7 +379,7 @@ mod tests {
374379
assert_eq!(first.diagnostic().severity, Severity::Error);
375380
assert_eq!(first.diagnostic().code, Some("arg-types".to_string()));
376381
assert_eq!(first.message(), "Expected a const name, but got a number 0");
377-
let first_span = first.diagnostic().primary_label.span;
382+
let first_span = to_span(first.diagnostic().labels[0].range.clone());
378383
assert_eq!(
379384
result.resolve_position(file, first_span.start()).unwrap(),
380385
Location::new(LineIndex(1), ColumnIndex(17))
@@ -386,7 +391,7 @@ mod tests {
386391
second.message(),
387392
"Expected a const name, but got a number 10"
388393
);
389-
let second_span = second.diagnostic().primary_label.span;
394+
let second_span = to_span(second.diagnostic().labels[0].range.clone());
390395
assert_eq!(
391396
result.resolve_position(file, second_span.start()).unwrap(),
392397
Location::new(LineIndex(3), ColumnIndex(13))
@@ -398,7 +403,7 @@ mod tests {
398403
third.message(),
399404
"Expected a number argument to number_of_objects, but got SOMEVAL"
400405
);
401-
let third_span = third.diagnostic().primary_label.span;
406+
let third_span = to_span(third.diagnostic().labels[0].range.clone());
402407
assert_eq!(
403408
result.resolve_position(file, third_span.start()).unwrap(),
404409
Location::new(LineIndex(7), ColumnIndex(18))
@@ -407,7 +412,7 @@ mod tests {
407412
assert_eq!(fourth.diagnostic().severity, Severity::Error);
408413
assert_eq!(fourth.diagnostic().code, Some("arg-types".to_string()));
409414
assert_eq!(fourth.message(), "Missing arguments to create_object");
410-
let fourth_span = fourth.diagnostic().primary_label.span;
415+
let fourth_span = to_span(fourth.diagnostic().labels[0].range.clone());
411416
assert_eq!(
412417
result.resolve_position(file, fourth_span.start()).unwrap(),
413418
Location::new(LineIndex(10), ColumnIndex(0))
@@ -429,7 +434,7 @@ mod tests {
429434
assert_eq!(first.diagnostic().severity, Severity::Warning);
430435
assert_eq!(first.diagnostic().code, Some("arg-types".to_string()));
431436
assert_eq!(first.message(), "Elevation value out of range (0 or 1-7)");
432-
let first_span = first.diagnostic().primary_label.span;
437+
let first_span = to_span(first.diagnostic().labels[0].range.clone());
433438
assert_eq!(
434439
result.resolve_position(file, first_span.start()).unwrap(),
435440
Location::new(LineIndex(0), ColumnIndex(29))
@@ -457,7 +462,7 @@ mod tests {
457462
first.message(),
458463
"`assign_to` Target must be AT_COLOR, AT_PLAYER, AT_TEAM"
459464
);
460-
let first_span = first.diagnostic().primary_label.span;
465+
let first_span = to_span(first.diagnostic().labels[0].range.clone());
461466
assert_eq!(
462467
result.resolve_position(file, first_span.start()).unwrap(),
463468
Location::new(LineIndex(0), ColumnIndex(24))

0 commit comments

Comments
 (0)