Fix bare nodepaths referencing absolute/root paths (#712)

This commit is contained in:
David Kincaid
2024-09-15 16:04:31 -04:00
committed by GitHub
parent 18225ab0d5
commit 5b725b55fd
5 changed files with 69 additions and 37 deletions

View File

@@ -11,6 +11,14 @@ func f():
@onready var score := $HBoxContainer/Score as Label
var a = $/root
var a = $ / root
var a = $/root/Child
var a = $ / root / Child
var a = $/root/Child/%Unique
var a = $ / root / Child/%Unique
var a = $/root/Child/GrandChild
var a = $Child
var a = $Child/ GrandChild
var a = $Child/ GrandChild / GreatGrandChild

View File

@@ -11,6 +11,14 @@ func f():
@onready var score := $HBoxContainer/Score as Label
var a = $/root
var a = $/root
var a = $/root/Child
var a = $/root/Child
var a = $/root/Child/%Unique
var a = $/root/Child/%Unique
var a = $/root/Child/GrandChild
var a = $Child
var a = $Child/GrandChild
var a = $Child/GrandChild/GreatGrandChild

View File

@@ -78,6 +78,11 @@ function parse_token(token: Token) {
token.type = "nodepath";
return;
}
if (token.scopes.includes("meta.literal.nodepath.bare.gdscript")) {
token.skip = true;
token.type = "bare_nodepath";
return;
}
if (token.scopes.includes("keyword.control.flow.gdscript")) {
token.type = "keyword";
return;
@@ -183,6 +188,7 @@ function between(tokens: Token[], current: number, options: FormatterOptions) {
if (prev === "[" && nextToken.type === "symbol") return "";
if (prev === "[" && nextToken.type === "nodepath") return "";
if (prev === "[" && nextToken.type === "bare_nodepath") return "";
if (prev === ":") return " ";
if (prev === ";") return " ";
if (prev === "##") return " ";
@@ -225,7 +231,7 @@ export function format_document(document: TextDocument, _options?: FormatterOpti
const edits: TextEdit[] = [];
const options = _options ?? get_formatter_options();
let lineTokens: vsctm.ITokenizeLineResult = null;
let onlyEmptyLinesSoFar = true;
let emptyLineCount = 0;
@@ -290,7 +296,7 @@ export function format_document(document: TextDocument, _options?: FormatterOpti
tokens.push(token);
}
for (let i = 0; i < tokens.length; i++) {
// log.debug(i, tokens[i].value, tokens[i]);
log.debug(i, tokens[i].value, tokens[i]);
if (i > 0 && tokens[i - 1].string === true && tokens[i].string === true) {
nextLine += tokens[i].original;
} else {