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

Support for formatting #9

Closed
Enzojz opened this issue Jul 17, 2017 · 15 comments
Closed

Support for formatting #9

Enzojz opened this issue Jul 17, 2017 · 15 comments

Comments

@Enzojz
Copy link

Enzojz commented Jul 17, 2017

Hello,

Is it possible to add support to make automatic formatting? Thanks !

best regards,
Zheng

@trixnz
Copy link
Owner

trixnz commented Jul 17, 2017

Hi,
Could you please explain a little more what you mean?

@Enzojz
Copy link
Author

Enzojz commented Jul 17, 2017

Something like formatting with a pretty printer etc...

@trixnz
Copy link
Owner

trixnz commented Jul 17, 2017

Oh, this functionality is already implemented. You can access it via the built in vscode keybinds (Shift + Alt + F on Windows)

@Enzojz
Copy link
Author

Enzojz commented Jul 17, 2017

Hello,

Just have tried it it seems having two problems:

  1. After this function, the editor goes to the end of the file, which is very disturbing.
  2. It puts all nested tables inline, it should not happen.

Could you improve it?

@trixnz
Copy link
Owner

trixnz commented Jul 17, 2017

Hi,

  1. I suspect you may be selecting all of the text before running it, as I just tested it and it worked fine. Can you try again without selecting any text?
  2. Please take this to the luafmt issue tracker and create a bug report with a reproduction case and your expected output.

Cheers

@Enzojz
Copy link
Author

Enzojz commented Jul 17, 2017

Hi,

  1. I think anyway "jump to the end" when without selecting all is disturbing, since I will lost my input cursor, same as to doing selection all before it, and if I want to format all, why I need to select all?
  2. I will create a ticket there.

@trixnz
Copy link
Owner

trixnz commented Jul 17, 2017

You don't need to select all. Here's a video demonstrating how it should work:

2017-07-17_21-31-19

@Enzojz
Copy link
Author

Enzojz commented Jul 17, 2017

Ok, I have firgure out what it is:

Because of the first problem, my lua file gets much less lines after formatting, however, the cursor stays always on the same position.

I think it's a bug, since in your video it's not the case.
I am on windows 10.

@Enzojz
Copy link
Author

Enzojz commented Jul 17, 2017

I tested again, it seems context related, I work on a simple code like yours it work correctly, but not on my own real project:

for example this one:

https://github.com/Enzojz/flying_junction_1/blob/master/res/scripts/junction_assoc.lua

I am not sure but perhaps that may caused by unicode letters in the file.

@trixnz
Copy link
Owner

trixnz commented Jul 17, 2017

I looked into it a bit, and its more than likely because luafmt returns the whole formatted file as a single edit. I'll look into adding diff support to luafmt so we can provide minimal edits to vscode.

@Enzojz
Copy link
Author

Enzojz commented Jul 17, 2017

Not sure, since I have tested again on another file, which isn't with any unicode letter, it worked fine.

https://github.com/Enzojz/flying_junction_1/blob/master/res/scripts/junction.lua

Just for information.

@trixnz
Copy link
Owner

trixnz commented Jul 17, 2017

Thanks for the use-cases; I'll use them when implementing diff support. You can follow #10 and trixnz/lua-fmt#13 to keep track of progress.

Apologies for the bugs!

@trixnz trixnz closed this as completed Jul 17, 2017
@Enzojz
Copy link
Author

Enzojz commented Jul 17, 2017

Ok. Thank you.

@trixnz
Copy link
Owner

trixnz commented Jul 18, 2017

The new version on the marketplace (0.6.2) should fix this for you. Be advised though, the first format you run may not preserve the cursor position if the file has not been formatted before, as the number of edits will be fairly large and vscode loses track.

After that though, the cursor should stay with you through formats so long as the file is reasonably close to the same layout that luafmt will be outputting.

@Enzojz
Copy link
Author

Enzojz commented Jul 19, 2017

Thank you.

Could you have a look into line breaking issue.

trixnz/lua-fmt#15

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants