Skip to content

Commit c699d00

Browse files
authored
Improve error detection and messages (#81)
Improve the error ranges when mistakes are made in code blocks. Fix a colon character being interpreted as marking a procedure declaration if found in an step. Implement better detection of invalid attribute assignments, including a new error variant for that case. Hide the _language_ subcommand from main `--help` output. The command is still there, and not "undocumented" but a human users will never need to invoke it directly so there's no need to clutter the terminal with it.
2 parents fb972d4 + 62bbae5 commit c699d00

File tree

9 files changed

+198
-44
lines changed

9 files changed

+198
-44
lines changed

Cargo.lock

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

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "technique"
3-
version = "0.4.3"
3+
version = "0.4.5"
44
edition = "2021"
55
description = "A domain specific language for procedures."
66
authors = [ "Andrew Cowie" ]

src/editor/server.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -487,6 +487,9 @@ impl TechniqueLanguageServer {
487487
ParsingError::InvalidSubstep(_, _) => {
488488
("Invalid substep".to_string(), DiagnosticSeverity::ERROR)
489489
}
490+
ParsingError::InvalidAttribute(_, _) => {
491+
("Invalid attribute assignment".to_string(), DiagnosticSeverity::ERROR)
492+
}
490493
ParsingError::InvalidResponse(_, _) => {
491494
("Invalid response".to_string(), DiagnosticSeverity::ERROR)
492495
}

src/formatting/formatter.rs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,20 @@ pub fn render_procedure_declaration<'i>(procedure: &'i Procedure, renderer: &dyn
165165
render_fragments(&sub.fragments, renderer)
166166
}
167167

168+
pub fn render_scope<'i>(scope: &'i Scope, renderer: &dyn Render) -> String {
169+
let mut sub = Formatter::new(78);
170+
match scope {
171+
Scope::AttributeBlock { attributes, .. } => {
172+
// Render attributes without indentation for error messages
173+
sub.append_attributes(attributes);
174+
}
175+
_ => {
176+
panic!("Do not use for anything other than rendering Attribute line examples");
177+
}
178+
}
179+
render_fragments(&sub.fragments, renderer)
180+
}
181+
168182
/// Helper function to convert fragments to a styled string using a renderer
169183
fn render_fragments<'i>(fragments: &[(Syntax, Cow<'i, str>)], renderer: &dyn Render) -> String {
170184
let mut result = String::new();
@@ -806,6 +820,7 @@ impl<'i> Formatter<'i> {
806820
attributes,
807821
subscopes,
808822
} => {
823+
self.indent();
809824
self.append_attributes(attributes);
810825
self.add_fragment_reference(Syntax::Newline, "\n");
811826

@@ -906,7 +921,6 @@ impl<'i> Formatter<'i> {
906921
}
907922

908923
fn append_attributes(&mut self, attributes: &'i Vec<Attribute>) {
909-
self.indent();
910924
for (i, attribute) in attributes
911925
.iter()
912926
.enumerate()

src/main.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@ fn main() {
129129
.subcommand(
130130
Command::new("language")
131131
.about("Language Server Protocol integration for editors and IDEs.")
132+
.hide(true)
132133
.long_about("Run a Language Server Protocol (LSP) service \
133134
for Technique documents. This accepts commands and code \
134135
input via stdin and returns compilation errors and other \

src/parsing/checks/errors.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ making_coffee :
246246
1. Do something { re peat() }
247247
"#
248248
.trim_ascii(),
249-
ParsingError::InvalidFunction(39, 7),
249+
ParsingError::InvalidCodeBlock(39, 10),
250250
);
251251
}
252252

@@ -259,7 +259,7 @@ making_coffee :
259259
1. Do something { re peat <thing>() }
260260
"#
261261
.trim_ascii(),
262-
ParsingError::InvalidFunction(39, 15),
262+
ParsingError::InvalidCodeBlock(39, 18),
263263
);
264264
}
265265

0 commit comments

Comments
 (0)