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

Formatter cannot handle tabs and spaces properly for hidden terminal rules #1351

Open
joluj opened this issue Jan 23, 2024 · 3 comments
Open
Labels
bug Something isn't working

Comments

@joluj
Copy link

joluj commented Jan 23, 2024

Langium version: reproducible in 1.2.0 & 2.1.0 (current)
Package name: langium

Steps To Reproduce

  1. Open example/domainmodel in vscode with the domainmodel extension enabled
  2. Add a new line with tabs and spaces before a comment (i.e. a hidden terminal rule)
  3. Format code

Code example:

qualified-names.dmodel

This file contains tabs and spaces mixed. It works fine with non-hidden rules but breaks with hidden rules (e.g. comments)

entity E1 {
	name: String // Tabs are replaced in non-hidden nodes (expected)
  	  time: big.Int // Tabs and spaces mixed are converted to spaces (expected)
	// Tabs are not replaced in hidden nodes
 	  // Tabs and spaces mixed lead to total confusion
}

The current behavior

  • Tabs are not converted to spaces in hidden rules.
  • Indent breaks if tabs and spaces are mixed in hidden rules.
  • Both bugs don't occur with non-hidden rules.
entity E1 {
-	name: String // Tabs are replaced in non-hidden nodes (expected)
-  	  time: big.Int // Tabs and spaces mixed are converted to spaces (expected)
-	// Tabs are not replaced in hidden nodes
- 	  // Tabs and spaces mixed lead to total confusion
+    name: String // Tabs are replaced in non-hidden nodes (expected)
+    time: big.Int // Tabs and spaces mixed are converted to spaces (expected)
+	// Tabs are not replaced in hidden nodes
+ // Tabs and spaces mixed lead to total confusion
}

The expected behavior

  • Hidden and non-hidden rules have the same behavior
entity E1 {
-	name: String // Tabs are replaced in non-hidden nodes (expected)
-  	  time: big.Int // Tabs and spaces mixed are converted to spaces (expected)
-	// Tabs are not replaced in hidden nodes
- 	  // Tabs and spaces mixed lead to total confusion
+    name: String // Tabs are replaced in non-hidden nodes (expected)
+    time: big.Int // Tabs and spaces mixed are converted to spaces (expected)
+    // Tabs are not replaced in hidden nodes
+    // Tabs and spaces mixed lead to total confusion
}
@georg-schwarz
Copy link

Is there already any known workaround or solution for this?

@msujew
Copy link
Contributor

msujew commented May 8, 2024

@georg-schwarz Someone would probably need to take a look at how edits for hidden nodes are created. I don't think there's a fix for this yet. I have a general refactoring of the formatter in mind, which is why this issue is currently in the backlog.

@georg-schwarz
Copy link

Thanks for the pointer!
We will share our solution here in case we decide to tackle it before you are done with the refactoring you mentioned ;-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants