Skip to content

Commit 05e623d

Browse files
authored
fix: Location of variables declared in VAR_CONFIG (#1304)
Previously the location of a variable name declared in a VAR_CONFIG block would include the AT keyword in it. With this commit the `AT` keyword is omitted such that a slice of the variable name is e.g. `main.instance.foo` instead of `main.instance.foo AT`.
1 parent bca3c31 commit 05e623d

File tree

3 files changed

+20
-7
lines changed

3 files changed

+20
-7
lines changed

src/index/tests/index_tests.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2124,8 +2124,8 @@ fn var_config_hardware_address_creates_global_variable() {
21242124
offset: 40,
21252125
}..TextLocation {
21262126
line: 2,
2127-
column: 26,
2128-
offset: 50,
2127+
column: 23,
2128+
offset: 47,
21292129
},
21302130
),
21312131
},

src/parser.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1104,7 +1104,7 @@ fn try_parse_config_var(lexer: &mut ParseSession) -> Option<ConfigVariable> {
11041104
lexer.try_consume(&KeywordDot);
11051105
}
11061106

1107-
let location = start.span(&lexer.location());
1107+
let location = start.span(&lexer.last_location());
11081108
if !lexer.try_consume(&KeywordAt) {
11091109
lexer.accept_diagnostic(Diagnostic::missing_token("AT", lexer.location()));
11101110
}

src/parser/tests/variable_parser_tests.rs

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -304,8 +304,8 @@ fn var_config_test() {
304304
offset: 24,
305305
}..TextLocation {
306306
line: 2,
307-
column: 24,
308-
offset: 40,
307+
column: 21,
308+
offset: 37,
309309
},
310310
),
311311
},
@@ -351,8 +351,8 @@ fn var_config_test() {
351351
offset: 64,
352352
}..TextLocation {
353353
line: 3,
354-
column: 24,
355-
offset: 80,
354+
column: 21,
355+
offset: 77,
356356
},
357357
),
358358
},
@@ -365,3 +365,16 @@ fn var_config_test() {
365365
}
366366
"###);
367367
}
368+
369+
#[test]
370+
fn var_config_location() {
371+
let src = r#"
372+
VAR_CONFIG
373+
main.instance.foo AT %IX3.1 : BOOL;
374+
END_VAR
375+
"#;
376+
377+
let (result, _) = parse(src);
378+
379+
assert_eq!("main.instance.foo", &src[result.var_config[0].location.to_range().unwrap()]);
380+
}

0 commit comments

Comments
 (0)