mirror of
https://github.com/godotengine/godot-vscode-plugin.git
synced 2025-12-31 13:48:24 +03:00
Update float syntax rules and formatting (#756)
* Update float syntax rules and formatting * Add missing export_group annotation * Moved abstract from an annotation to a keyword * Add an example of the other type of string interpolation.
This commit is contained in:
25
src/formatter/snapshots/float_notation.gd
Normal file
25
src/formatter/snapshots/float_notation.gd
Normal file
@@ -0,0 +1,25 @@
|
||||
# --- IN ---
|
||||
func test():
|
||||
# The following floating-point notations are all valid:
|
||||
print(is_equal_approx(123., 123))
|
||||
print(is_equal_approx(.123, 0.123))
|
||||
print(is_equal_approx(.123e4, 1230))
|
||||
print(is_equal_approx(123.e4, 1.23e6))
|
||||
print(is_equal_approx(.123e-1, 0.0123))
|
||||
print(is_equal_approx(123.e-1, 12.3))
|
||||
|
||||
# Same as above, but with negative numbers.
|
||||
print(is_equal_approx(-123., -123))
|
||||
print(is_equal_approx(-.123, -0.123))
|
||||
print(is_equal_approx(-.123e4, -1230))
|
||||
print(is_equal_approx(-123.e4, -1.23e6))
|
||||
print(is_equal_approx(-.123e-1, -0.0123))
|
||||
print(is_equal_approx(-123.e-1, -12.3))
|
||||
|
||||
# Same as above, but with explicit positive numbers (which is redundant).
|
||||
print(is_equal_approx(+123., +123))
|
||||
print(is_equal_approx(+.123, +0.123))
|
||||
print(is_equal_approx(+.123e4, +1230))
|
||||
print(is_equal_approx(+123.e4, +1.23e6))
|
||||
print(is_equal_approx(+.123e-1, +0.0123))
|
||||
print(is_equal_approx(+123.e-1, +12.3))
|
||||
@@ -12,5 +12,6 @@ func dump() -> String:
|
||||
preview_texture: %s,
|
||||
explorer_layer: %s,
|
||||
connections: %s,
|
||||
test {test},
|
||||
}
|
||||
"""
|
||||
|
||||
@@ -74,6 +74,10 @@ function parse_token(token: Token) {
|
||||
if (token.scopes.includes("meta.function.parameters.gdscript")) {
|
||||
token.param = true;
|
||||
}
|
||||
if (token.scopes[0].includes("constant.numeric")) {
|
||||
token.type = "literal";
|
||||
return;
|
||||
}
|
||||
if (token.value.match(/[A-Za-z_]\w+/)) {
|
||||
token.identifier = true;
|
||||
}
|
||||
@@ -144,7 +148,7 @@ function between(tokens: Token[], current: number, options: FormatterOptions) {
|
||||
|
||||
if (nextToken.param) {
|
||||
if (options.denseFunctionParameters) {
|
||||
if (prev === "-") {
|
||||
if (prev === "-" || prev === "+") {
|
||||
if (tokens[current - 2]?.value === "=") return "";
|
||||
if (["keyword", "symbol"].includes(tokens[current - 2]?.type)) {
|
||||
return "";
|
||||
@@ -181,8 +185,9 @@ function between(tokens: Token[], current: number, options: FormatterOptions) {
|
||||
}
|
||||
if (prev === "@") return "";
|
||||
|
||||
if (prev === "-") {
|
||||
if (prev === "-" || prev === "+") {
|
||||
if (nextToken.identifier) return " ";
|
||||
if (next === "(") return " ";
|
||||
if (current === 1) return "";
|
||||
if (["keyword", "symbol"].includes(tokens[current - 2]?.type)) {
|
||||
return "";
|
||||
@@ -304,7 +309,7 @@ export function format_document(document: TextDocument, _options?: FormatterOpti
|
||||
const tokens: Token[] = [];
|
||||
for (const t of lineTokens.tokens) {
|
||||
const token: Token = {
|
||||
scopes: t.scopes,
|
||||
scopes: [t.scopes.join(" "), ...t.scopes],
|
||||
original: line.text.slice(t.startIndex, t.endIndex),
|
||||
value: line.text.slice(t.startIndex, t.endIndex).trim(),
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user