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 removes final newline on package.json #13475

Open
Tracked by #13192
tsmaeder opened this issue Mar 11, 2024 · 12 comments · May be fixed by #13751
Open
Tracked by #13192

Formatter removes final newline on package.json #13475

tsmaeder opened this issue Mar 11, 2024 · 12 comments · May be fixed by #13751
Labels
contributor experience issues related to the contributor experience json issues related to the json language

Comments

@tsmaeder
Copy link
Contributor

Bug Description:

The Theia workspace contains a setting to turn on "format on save" for the workspace. This is problematic, since the formatter does not work as intended: if I edit a package.json file, the formatter will remove the final newline. This leads to problems on UNIX-derived platforms.

Steps to Reproduce:

  1. Edit a package.json in the Theia source
  2. Save
  3. Observe: the formatter removes the final newline.

Additional Information

  • Operating System: Windows
  • Theia Version: 1.47.0
@tsmaeder tsmaeder added json issues related to the json language contributor experience issues related to the contributor experience labels Mar 11, 2024
@tsmaeder tsmaeder mentioned this issue Mar 11, 2024
46 tasks
@tsmaeder
Copy link
Contributor Author

In current version of VS Code, there seems to be a setting files.insertFinalNewline, but that setting does not show up yet in 1.47.100 of Theia IDE. Not sure if we're just missing a monaco update here 🤷

@xai
Copy link
Contributor

xai commented Apr 19, 2024

I cannot reproduce this on current master.

@tsmaeder
Copy link
Contributor Author

tsmaeder commented May 2, 2024

@xai are you using the a Theia workspace to test? "Format on save" is turned on in the workspace settings. I just observed this again in the Theia IDE 1.47.100.

@xai
Copy link
Contributor

xai commented May 21, 2024

I can reproduce this now (with Theia IDE 1.49.101).

@xai xai linked a pull request Jun 3, 2024 that will close this issue
1 task
@xai
Copy link
Contributor

xai commented Jun 3, 2024

Unfortunately, Monaco Editor has no such thing as editor.action.insertFinalNewline that we could call.

I opened a draft PR with a workaround to support the files.insertFinalNewline setting.
Also, I feel my current workaround (i.e., the protected function) is somehow in the wrong place. Any suggestions on where it would fit better?

@tsmaeder
Copy link
Contributor Author

tsmaeder commented Jun 3, 2024

Do we understand why the formatter removes the final newline? As far as I can tell, this does not happen in VS Code.

@xai
Copy link
Contributor

xai commented Jun 3, 2024

Do we understand why the formatter removes the final newline? As far as I can tell, this does not happen in VS Code.

I think it does, see attached screencast.

vscode-finalnewline.mp4

@tsmaeder
Copy link
Contributor Author

tsmaeder commented Jun 3, 2024

I'm sorry, but what am I seeing?

@xai
Copy link
Contributor

xai commented Jun 3, 2024

I'm sorry, but what am I seeing?

This is vscode (cleaned user data) with a workspace that has formatOnSave enabled (see right pane).

Initially, insertFinalNewline is not set (right pane).
On the first save action, the empty line at the end of the package.json in the left pane is removed automatically (i.e., line 46 is deleted in the package.json).

Then, I enabled the insertFinalNewline setting in the right pane and repeated the experiment with the package.json. The second save does not remove the empty line, i.e. line 46 remains.

@JonasHelming
Copy link
Contributor

@tsmaeder

@tsmaeder
Copy link
Contributor Author

tsmaeder commented Jun 5, 2024

@xai What's the reason the PR is in draft state?

@xai
Copy link
Contributor

xai commented Jun 5, 2024

@xai What's the reason the PR is in draft state?

Also, I feel my current workaround (i.e., the protected function) is somehow in the wrong place. Any suggestions on where it would fit better?

This concern of mine was the reason I kept it in draft state.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
contributor experience issues related to the contributor experience json issues related to the json language
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants