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

VSCode extension: incorrect formatting #192

Closed
wdscxsj opened this issue Oct 2, 2023 · 5 comments
Closed

VSCode extension: incorrect formatting #192

wdscxsj opened this issue Oct 2, 2023 · 5 comments

Comments

@wdscxsj
Copy link
Contributor

wdscxsj commented Oct 2, 2023

In VSCode v1.82.2 on Windows 10 with templ-vscode v0.0.14, executing the Format Document command repeatedly may mangle the file:

demo

Running templ fmt on this file repeatedly doesn't have this issue.

@a-h
Copy link
Owner

a-h commented Oct 2, 2023

I wasn't able to reproduce this on my Mac. I haven't tried on a Linux machine yet. Can you drop an exact copy of the file on the issue please?

I'm wondering what character the spaces are. Are they 0x20, or something else?

@wdscxsj
Copy link
Contributor Author

wdscxsj commented Oct 2, 2023

Thanks for your investigation! A moment ago I upgraded to VSCode 1.82.3, and the formatting behavior changed on my machine (Windows 10 64-bit). The original file is attached here. Current behavior:

  1. The first Format Document command works fine, changing {name} to { name }. But now the Problems panel shows one red item: "template closing brace not found". Apparently it's not the case, since the code builds well.
  2. Press Ctrl+Z to revert the change, and any Format Document command does nothing. I suppose it's prevented by the identified problem.
  3. Restart VSCode, and it can be formatted again (go to step 1).

@wdscxsj
Copy link
Contributor Author

wdscxsj commented Oct 3, 2023

Hello, after a sleep, the first issue occurs again (tearing name apart). Here is the exact file.

And it seems templ fmt (not the VSCode extension) doesn't work quite well with a block of commented out code. For example, it formats this

// package main

// templ Hello() {
// 	<div>Hello</div>
// }

package main

templ Hello(name string) {
	<div>Hello, {name}</div>
}

into

package main

// package main

// templ Hello() {
// 	<div>Hello</div>
// }

package main

templ Hello(name string) {
	<div>Hello, { name }</div>
}

@wdscxsj
Copy link
Contributor Author

wdscxsj commented Oct 15, 2023

@a-h I can confirm this issue has been fixed in v0.2.408. Thanks for your wonderful work!

@a-h
Copy link
Owner

a-h commented Oct 15, 2023

Glad to hear that it's sorted!

@a-h a-h closed this as completed Oct 15, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants