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 preview #960

Closed
sumneko opened this issue Feb 21, 2022 · 9 comments
Closed

Formatter preview #960

sumneko opened this issue Feb 21, 2022 · 9 comments
Labels
feat/formatter Related to code formatter

Comments

@sumneko
Copy link
Collaborator

sumneko commented Feb 21, 2022

Version 2.6.6 integrates formatter.
The formatter is still in development and looking forward to your feedback!

How to enable

The formatter can be enabled by adding the parameter --preview to the command line parameters.
For VSCode, add this parameter in the Lua.misc.parameters setting.

how to use

The formatter provides two functions: "format document" and "format selected range".
For VSCode users, you can find thease features in the right-click menu.
In addition, VSCode can also enable Format On Paste and Format On Save in the settings.
Note that the Format On Type feature is currently provided by this language server, not by the formatter.

The formatter also provides the Code style check feature, but it is disabled by default. To enable it, please set:

"Lua.diagnostics.neededFileStatus": {
    "codestyle-check": "Any"
}

How to configure

Please read the wiki https://github.com/sumneko/lua-language-server/wiki/Code-Reformat

How to give feedback

If you have any suggestions or bug reports about the formatter, please open issues in https://github.com/CppCXY/EmmyLuaCodeStyle/issues

Other

In fact, I didn't plan to add the formatting feature before.

  1. I've always formatted manually because I feel like I can get some rest and force myself to review the code. So I have no motivation to develop formatter.
  2. I think the formatter is very different from the other features of the language server, the language server is dedicated to intellisense, and all features are based on understanding the semantics of your code. But code formatting only needs to check the current file, or even a code snippet. The extensive settings required for formatting is also very different from the language server itself.
  3. There are already many independent formatters on the market, and users can choose freely.
  4. This language server supports Lua5.1 to Lua5.4 (and LuaJIT) and can run on multiple platforms. These issues also need to be addressed if integrating third-party formatters, especially cross-platform compilation issues.

Fortunately, this PR took the initiative to help me solve 1 and 4, so I decided to integrate it in the new version.
I've raised dozens of issues after trying out this formatting tool, so if you have any suggestions or report, please feel free to feedback.

@sumneko sumneko added the feat/formatter Related to code formatter label Feb 21, 2022
@sumneko sumneko changed the title Code formatting preview Formatter preview Feb 21, 2022
@FlashHit
Copy link

@sumneko in 2.6.5 the formatter worked but now it doesn't anymore. Did something change? Do I need to do anything to make it work again?

@sumneko
Copy link
Collaborator Author

sumneko commented Feb 21, 2022

@sumneko in 2.6.5 the formatter worked but now it doesn't anymore. Did something change? Do I need to do anything to make it work again?

The formatter still has a lot of issues to fix, so I disabled it in 2.6.6.
You can use --preview to enable it again, see How to enable above.

@przepompownia
Copy link

I noticed that --preview takes effect when added after -E ...path/to/main.lua.

@Philofallever
Copy link

怎么配置格式化,?我建了xx.editorconfig 或者在setting里配置测试都不起作用

    "Lua.format.defaultConfig": {
        "continuous_assign_statement_align_to_equal_sign": false
    },

@sumneko
Copy link
Collaborator Author

sumneko commented Mar 4, 2022

怎么配置格式化,?我建了xx.editorconfig 或者在setting里配置测试都不起作用

    "Lua.format.defaultConfig": {
        "continuous_assign_statement_align_to_equal_sign": false
    },

2.6.6 版本只支持从 .editorconfig 中加载设置,从 setting 中加载设置请等2.6.7发布

@Philofallever
Copy link

怎么配置格式化,?我建了xx.editorconfig 或者在setting里配置测试都不起作用

    "Lua.format.defaultConfig": {
        "continuous_assign_statement_align_to_equal_sign": false
    },

2.6.6 版本只支持从 .editorconfig 中加载设置,从 setting 中加载设置请等2.6.7发布

好的 😄

@0x0D15
Copy link

0x0D15 commented Mar 13, 2022

Any thoughts on adding support for alternative formatter in the future? I believe a lot of the neovim community has coalesced around stylua so it would be nice to see some support for that eventually.

@sumneko
Copy link
Collaborator Author

sumneko commented Mar 13, 2022

Any thoughts on adding support for alternative formatter in the future? I believe a lot of the neovim community has coalesced around stylua so it would be nice to see some support for that eventually.

AFAIK, StyLua dose not support Lua 5.4.
I think the formatter is very different from the other features of the language server, you can easily install other formatters and choose freely.

@sumneko
Copy link
Collaborator Author

sumneko commented Apr 10, 2022

Published in 3.0.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feat/formatter Related to code formatter
Projects
None yet
Development

No branches or pull requests

5 participants