lua-language-server icon indicating copy to clipboard operation
lua-language-server copied to clipboard

[FEATURE REQUEST] Invoke code formatting from CLI

Open Real-Gecko opened this issue 3 years ago • 14 comments

I have a project with 3K+ Lua files I need to format. The problem is if I use something like this it takes forever. I disabled diagnostics like this:

    "Lua.diagnostics.enable": false,
    "Lua.diagnostics.workspaceDelay": 10000,
    "Lua.diagnostics.workspaceRate": 1,
    "Lua.diagnostics.disableScheme": ["git", "."]

Yet for some reason lua-language-server triggers diagnostics all the time and it slows down the process. image

So, it would be great to trigger code formatting from CLI without doing any diagnostics.

I tried this tool but it has different styling by default so it was not really helpful, but it's blazing fast.

Real-Gecko avatar Jun 27 '22 06:06 Real-Gecko

3K+ files don't need such a high occupation. There should be a bug. Can you provide a log?

sumneko avatar Jun 27 '22 06:06 sumneko

Where's it located?

Real-Gecko avatar Jun 27 '22 06:06 Real-Gecko

see https://github.com/sumneko/lua-language-server/wiki/Default-log-path

sumneko avatar Jun 27 '22 07:06 sumneko

Please set Lua.semantic.enable to false , check whether the occupancy returns to normal?

sumneko avatar Jun 27 '22 07:06 sumneko

Is this project open source? If I can debug directly, I can solve the problem faster.

EDIT I can see a lot of strange behavior from your log.

  1. Clients requests semanticTokens for many files after server startup, but it should only request for opened files.
  2. Clients send some requests for *.events and *.ship, are these files really lua, or are these files very large?

Please add --loglevel=trace in command line and provide the new log (If you are using VSCode, add it in Lua.misc.parameters)

sumneko avatar Jun 27 '22 07:06 sumneko

code format has standlone cli tool

CppCXY avatar Jun 27 '22 07:06 CppCXY

Please set Lua.semantic.enable to false , check whether the occupancy returns to normal?

Yes this helped, things go lot faster now.

Is this project open source? If I can debug directly, I can solve the problem faster.

EDIT I can see a lot of strange behavior from your log.

Please add --loglevel=trace in command line and provide the new log (If you are using VSCode, add it in Lua.misc.parameters)

I'll create a repo for this so you can see all the stuff yourself.

1. Clients requests `semanticTokens` for many files after server startup, but it should only request for opened files.

I've set it to diagnose entire workspace, because I needed to see all available errors in workspace without opening each and every file.

2. Clients send some requests for `*.events` and `*.ship`, are these files really lua, or are these files very large?

Yes they're, they simply have this weird extension :D

code format has standlone cli tool

Yes, I've used it, but as I said it has some different default styling. So when I open file formatted with it and save in VSCode formatting may change. I spent some time trying to match formatting for both tools but failed miserably.

Real-Gecko avatar Jun 27 '22 08:06 Real-Gecko

this repo's formatting algorithm is come from EmmyluaCodeStyle. you can get cli tool from release

CppCXY avatar Jun 27 '22 09:06 CppCXY

this repo's formatting algorithm is come from EmmyluaCodeStyle. you can get cli tool from release

Oh, wait, this is different format tool, sweet will try it too, thanks!

Real-Gecko avatar Jun 27 '22 09:06 Real-Gecko

this repo's formatting algorithm is come from EmmyluaCodeStyle. you can get cli tool from release

Works like a charm, thank you!

Is this project open source? If I can debug directly, I can solve the problem faster.

https://github.com/Real-Gecko/hw2-complex This is the code, beware that's huge: image It contains a lot of legacy stuff that needs to be removed. .vscode/settings.json for the project contains everything needed for project to work except one thing: library files. globals.zip Unpack this globals.zip anywhere on your drive and adjust Lua.workspace.library accordingly.

Real-Gecko avatar Jun 27 '22 10:06 Real-Gecko

Thanks for your project, I have found a performance issue!

sumneko avatar Jun 27 '22 12:06 sumneko

You can install this version to check if the performance issue resolved: https://github.com/sumneko/lua-language-server/actions/runs/2569280528

sumneko avatar Jun 27 '22 13:06 sumneko

Yes, f9b3b65 is much better. Not only file formatting happens faster even with "Lua.semantic.enable": true, it also was able to detect some issues with the current code which 3.3.1 was unable to detect for some reason. https://github.com/CppCXY/EmmyLuaCodeStyle also works like a charm from CLI. If you make code formatting from CLI available with lua-language-server binary it's up to you.

Real-Gecko avatar Jun 27 '22 15:06 Real-Gecko