Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix bad formatting on several operators #605

Merged
merged 37 commits into from
Jun 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
064a690
Add test cases
DaelonSuzuka Feb 25, 2024
25fd1e2
Add support for &&, ||, and ** operators
DaelonSuzuka Feb 25, 2024
5b5c6af
Fix negative number/leading minus operator formatting
DaelonSuzuka Feb 28, 2024
9c15cd9
Clean up operator parsing rules
DaelonSuzuka Feb 28, 2024
88086a6
Add more negative number examples
DaelonSuzuka Feb 28, 2024
1b79c09
Add syntax highlighting and formatter support for "when" keyword
DaelonSuzuka Mar 3, 2024
f8b27d7
Handle %Unique inside parens
DaelonSuzuka Mar 3, 2024
d70164f
Fix number of newlines allowed before func/class (tests are failing)
DaelonSuzuka Mar 8, 2024
a8af14e
Fix preload() having an extra space inserted into it
DaelonSuzuka Apr 6, 2024
fca61c6
Fix and/or/not keywords being incorrectly identified inside variable/…
DaelonSuzuka Apr 6, 2024
b1e9581
Improve consecutive line removal algorithm
DaelonSuzuka Apr 6, 2024
7a26248
Add support and tests for bitwise operators
DaelonSuzuka Apr 6, 2024
6ea6df5
Fix rpc() function being treated as a keyword
DaelonSuzuka Apr 16, 2024
931068c
Fix wrong scope tags being applied to parameter types
DaelonSuzuka Apr 16, 2024
db57efa
Fixed PascalCaseClass rule to properly match names like UIScreen
DaelonSuzuka Apr 16, 2024
bb2fde2
Fixed OS being highlighted as a constant instead of a class
DaelonSuzuka Apr 16, 2024
9bbb196
Fix incorrect formatting with negative numbers
DaelonSuzuka Apr 26, 2024
d6bca31
Format file
DaelonSuzuka Apr 26, 2024
70c4481
Add highlighting support for string brace placeholders
DaelonSuzuka Apr 29, 2024
bb1ed1a
Merge branch 'master' into formatter_fixes
DaelonSuzuka Jun 23, 2024
239eeef
Fix lint issues
DaelonSuzuka Jun 23, 2024
8f07072
Fix linter complaints
DaelonSuzuka Jun 23, 2024
917d140
Prevent error during setup if there's no godot project
DaelonSuzuka Jun 23, 2024
2962c5c
Add snapshot_template files to make it easier to create new formatter…
DaelonSuzuka Jun 23, 2024
daf1358
Fix format failing when max blank lines == 2
DaelonSuzuka Jun 23, 2024
3b4eacf
Add formatter.denseFunctionDeclarations option and standardize format…
DaelonSuzuka Jun 23, 2024
f22a536
Change configuration default
DaelonSuzuka Jun 23, 2024
148eac3
Adjust test output to match new defaults
DaelonSuzuka Jun 23, 2024
4cb9cb4
Fix detection of ":=" in param lists
DaelonSuzuka Jun 23, 2024
2507bbe
Properly detect static func
DaelonSuzuka Jun 24, 2024
d53d06f
Properly detect ## comments
DaelonSuzuka Jun 24, 2024
08e3773
Properly handle comments plus empty line trimming
DaelonSuzuka Jun 24, 2024
ef3823a
Fix compound assignment operators having wrong precedence
DaelonSuzuka Jun 24, 2024
f3bbde4
Fix some negative int literal issues
DaelonSuzuka Jun 24, 2024
2bb45e1
Fix operator precedence order again
DaelonSuzuka Jun 24, 2024
c6ba6d8
Add missing assignment operators + tests
DaelonSuzuka Jun 24, 2024
20e3069
Add comment example to snapshot
DaelonSuzuka Jun 24, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,24 @@
"default": true,
"description": "Whether to reveal the terminal when launching the Godot Editor"
},
"godotTools.formatter.emptyLinesBeforeFunctions": {
"type": "string",
"enum": [
"one",
"two"
],
"enumDescriptions": [
"One line before functions. A more compact style.",
"Two lines before functions. Conforms to the official GDScript style guide."
],
"default": "two",
"description": "Number of blank lines to leave before functions."
},
"godotTools.formatter.denseFunctionDeclarations": {
"type": "boolean",
"default": false,
"description": "Whether extra space should be removed from function declarations"
},
"godotTools.lsp.serverProtocol": {
"type": [
"string"
Expand Down
6 changes: 5 additions & 1 deletion src/extension.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as path from "path";
import * as path from "node:path";
import * as vscode from "vscode";
import { attemptSettingsUpdate, get_extension_uri, clean_godot_path } from "./utils";
import {
Expand Down Expand Up @@ -81,6 +81,10 @@ export function activate(context: vscode.ExtensionContext) {

async function initial_setup() {
const projectVersion = await get_project_version();
if (projectVersion === undefined) {
// TODO: actually handle this?
return;
}
const settingName = `editorPath.godot${projectVersion[0]}`;
const result = verify_godot_version(get_configuration(settingName), projectVersion[0]);
const godotPath = result.godotPath;
Expand Down
4 changes: 2 additions & 2 deletions src/formatter/formatter.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as vscode from "vscode";
import * as path from "path";
import * as fs from "fs";
import * as path from "node:path";
import * as fs from "node:fs";

import { format_document } from "./textmate";

Expand Down
Empty file.
Empty file.
16 changes: 16 additions & 0 deletions src/formatter/snapshots/arithmetic/in.gd
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ func f():
a= 1.0* .2
a =1.0 * 2.

a = 10**10
a = min(10, 10**10)

a= a% b
a =1%2

Expand All @@ -36,3 +39,16 @@ func f():

var v = Vector2( 1 , - 1 )
var w = Vector2(1,10-1)

print( - 1 )
print( 1 - 1 )

print( - 1 + (1-1))
print( - 1 + (-1-1))

if a > - 1:
if a < - 1:
if a == - 1:
pass

return - 1
16 changes: 16 additions & 0 deletions src/formatter/snapshots/arithmetic/out.gd
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ func f():
a = 1.0 * .2
a = 1.0 * 2.

a = 10 ** 10
a = min(10, 10 ** 10)

a = a % b
a = 1 % 2

Expand All @@ -36,3 +39,16 @@ func f():

var v = Vector2(1, -1)
var w = Vector2(1, 10 - 1)

print(-1)
print(1 - 1)

print(-1 + (1 - 1))
print(-1 + (-1 - 1))

if a > -1:
if a < -1:
if a == -1:
pass

return -1
15 changes: 15 additions & 0 deletions src/formatter/snapshots/assignment-operators/in.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
func f():
# arithmetic
x += 1
x -= 1
x *= 1
x /= 1
x %= 1

# bitwise
x |= 1
x &= 1
x ~= 1
x /= 1
x >>= 1
x <<= 1
15 changes: 15 additions & 0 deletions src/formatter/snapshots/assignment-operators/out.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
func f():
# arithmetic
x += 1
x -= 1
x *= 1
x /= 1
x %= 1

# bitwise
x |= 1
x &= 1
x ~= 1
x /= 1
x >>= 1
x <<= 1
5 changes: 5 additions & 0 deletions src/formatter/snapshots/bitwise-operators/in.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
func f():
collision_mask = 1 << 1 | 1 << 3
collision_mask = 1 << 1 & 1 << 3
collision_mask = ~1
collision_mask = 1 ^ ~ 1
5 changes: 5 additions & 0 deletions src/formatter/snapshots/bitwise-operators/out.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
func f():
collision_mask = 1 << 1 | 1 << 3
collision_mask = 1 << 1 & 1 << 3
collision_mask = ~1
collision_mask = 1 ^ ~1
4 changes: 4 additions & 0 deletions src/formatter/snapshots/boolean-operators/in.gd
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,7 @@ func f():
func g():
print(true and ( not false ) or ( true))
print(true and not false or not (true) )

func h():
print(true && ( not false ) || ( true))
print(true && not false || not (true) )
4 changes: 4 additions & 0 deletions src/formatter/snapshots/boolean-operators/out.gd
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,7 @@ func f():
func g():
print(true and (not false) or (true))
print(true and not false or not (true))

func h():
print(true && (not false) || (true))
print(true && not false || not (true))
21 changes: 21 additions & 0 deletions src/formatter/snapshots/consecutive-empty-lines-are-removed/in.gd
Original file line number Diff line number Diff line change
@@ -1,6 +1,27 @@



class Test:




func _ready():


pass



func test():


pass




# comments
func with_comments():

pass
14 changes: 14 additions & 0 deletions src/formatter/snapshots/consecutive-empty-lines-are-removed/out.gd
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
class Test:


func _ready():

pass


func test():

pass


# comments
func with_comments():

pass
12 changes: 6 additions & 6 deletions src/formatter/snapshots/initialization/out.gd
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ var a = 10
var b := 10
var c: int = 10

func f(b:=10):
return func(c:=10):
func f(b := 10):
return func(c := 10):
pass

func f(b: int=10):
return func(c: int=10):
func f(b: int = 10):
return func(c: int = 10):
pass

func f(b=10):
return func(c=10):
func f(b = 10):
return func(c = 10):
pass
10 changes: 10 additions & 0 deletions src/formatter/snapshots/keywords/in.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
func f():
const a = preload("res://a.gd")
const b = load("res://b.gd")

var origin: Vector2 = Vector2.ZERO
origin.x = 1
var andigin: Vector2 = Vector2.ZERO
andigin.x = 1

print(a)
10 changes: 10 additions & 0 deletions src/formatter/snapshots/keywords/out.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
func f():
const a = preload("res://a.gd")
const b = load("res://b.gd")

var origin: Vector2 = Vector2.ZERO
origin.x = 1
var andigin: Vector2 = Vector2.ZERO
andigin.x = 1

print(a)
4 changes: 4 additions & 0 deletions src/formatter/snapshots/match/in.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
func f(x):
match x:
var y when y>20:
pass
4 changes: 4 additions & 0 deletions src/formatter/snapshots/match/out.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
func f(x):
match x:
var y when y > 20:
pass
3 changes: 3 additions & 0 deletions src/formatter/snapshots/nodepaths/in.gd
Original file line number Diff line number Diff line change
Expand Up @@ -69,3 +69,6 @@ var a = $"%Child/GrandChild".some_method()
var a = $Child.get_node('GrandChild').some_method()
var a = $"Child".get_node('GrandChild').some_method()
var a = $"%Child".get_node('GrandChild').some_method()

func f():
$Child.add_child(%Unique)
3 changes: 3 additions & 0 deletions src/formatter/snapshots/nodepaths/out.gd
Original file line number Diff line number Diff line change
Expand Up @@ -69,3 +69,6 @@ var a = $"%Child/GrandChild".some_method()
var a = $Child.get_node('GrandChild').some_method()
var a = $"Child".get_node('GrandChild').some_method()
var a = $"%Child".get_node('GrandChild').some_method()

func f():
$Child.add_child(%Unique)
5 changes: 5 additions & 0 deletions src/formatter/symbols.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export const keywords = [
"master",
"mastersync",
"match",
"when",
"not",
"onready",
"or",
Expand Down Expand Up @@ -58,10 +59,14 @@ export const symbols = [
"&=",
"^=",
"|=",
"~=",
"<<=",
">>=",
":=",
"->",
"&",
"|",
"^",
"-",
"+",
"/",
Expand Down
Loading
Loading