Frodo45127 / rpfm

Rusted PackFile Manager (RPFM) is a... reimplementation in Rust and Qt5 of PackFile Manager (PFM), one of the best modding tools for Total War Games.
MIT License
368 stars 58 forks source link

Move Lua LSP config to `.luarc.json` for new MyMods #217

Closed DaBultz closed 2 years ago

DaBultz commented 2 years ago

This PR moves the generated Lua LSP config when a new mod is made through RPFM out of editor specific files into the .luarc.json. as a result any editor using Sumneko's LSP Server now support code completion from tw_autogen out of the box.

The change I suggested in #216 was simple to implement, so I went ahead and implemented it. Porting the change directly to v4, should be possible.

I've included a more detailed description on the change in the commit message, a copy for easy reference.

New MyMods created for games supporting tw_autogen, now have the lua LSP
config written to `.luarc.json` instead of `.vscode/settings.json`
and `.sublime-project`.

As VSCode and Sublime Text both uses Sumneko's Lua LSP server, which
supports per project configuration via `.luarc.json` file. This allows
other editors using the LSP server by Sumneko to come pre-configured with
tw_autogen out of the box, same way as Sublime Text and VSCode.

Previously the Lua LSP config was written to `.vscode/settings.json` and
`.sublime-project` for VSCode and Sublime Text respectively. Any other
editor required the config to manually be migrated to `.luarc.json`.

Closes: #216

Frodo45127 commented 2 years ago

I've done some quick tests, but neither sublime nor vscode seems to recognize the generated file automatically. Do you know if anything else is needed, apart of the lsp, for the file to load?

DaBultz commented 2 years ago

Nothing else should be needed, other than the .luarc.json file exists in the directory and the editor have a LSP client installed i.e vscode-lua in vscode, LSP-Lua in Sublime Text, Neovims built-in client etc.

What does the LSP Server log say? you can find the locations here (no need to add the trace): https://github.com/sumneko/lua-language-server/wiki/FAQ#where-can-i-find-the-log-file

Frodo45127 commented 2 years ago

Ok, did some more tests, and it seems it indeed works on VSCode. It didn't worked initially for me because the autogen I was using was very outdated. So that one's ok.

But in sublime text it doesn't seem to work. The log says it attempts to load the file, but it does nothing with it. Here's the log.

[13:58:06.319][info] [#0:script\provider\provider.lua:40]: Load config from client file:///G:/MyMod/warhammer_3/test_new_lua_impl [13:58:06.319][info] [#0:script\provider\provider.lua:47]: Load config from .luarc.json/.luarc.jsonc file:///G:/MyMod/warhammer_3/test_new_lua_impl [13:58:06.319][warn] [#0:script\files.lua:60]: Fix real file uri: file:///G:/MyMod/warhammer_3/test_new_lua_impl/script/campaign/mod/dynamic_disasters.lua -> file:///g%3A/MyMod/warhammer_3/test_new_lua_impl/script/campaign/mod/dynamic_disasters.lua [13:58:06.319][info] [#0:script\provider\completion.lua:43]: Enable completion. [13:58:06.428][info] [#0:script\provider\provider.lua:40]: Load config from client file:///G:/MyMod/warhammer_3/test_new_lua_impl [13:58:06.428][info] [#0:script\provider\provider.lua:47]: Load config from .luarc.json/.luarc.jsonc file:///G:/MyMod/warhammer_3/test_new_lua_impl [13:58:06.428][info] [#0:script\provider\provider.lua:55]: Load config from client fallback [13:58:06.537][info] [#0:script\provider\provider.lua:55]: Load config from client fallback

DaBultz commented 2 years ago

In the log does it say that it loads the log after Preload start?

I just tested in a fresh install of Sublime Text with only LSP and LSP-Lua package installed, and for me loads the autogen (also provides code completion).

[14:11:51.657][info] [#0:script\workspace\workspace.lua:285]: Preload start:    file:///G:/modding/wh3/warhammer_3/test_mod
[14:11:51.657][info] [#0:script\workspace\workspace.lua:291]: Scan files at:    file:///G:/modding/wh3/warhammer_3/test_mod
[14:11:51.657][info] [#0:script\workspace\workspace.lua:285]: Preload start:    <fallback>
[14:11:51.657][info] [#0:script\workspace\workspace.lua:307]: Scan library at:  file:///c%3A/Users/bultz/Downloads/sublime_text_build_4126_x64/Data/Package%20Storage/LSP-lua/meta/Lua%205.4%20en-US%20utf8
[14:11:51.657][info] [#0:script\workspace\workspace.lua:307]: Scan library at:  file:///c%3A/Users/bultz/AppData/Roaming/rpfm/config/tw_autogen/output/wh3/frontend
[14:11:51.673][info] [#0:script\workspace\workspace.lua:307]: Scan library at:  file:///c%3A/Users/bultz/Downloads/sublime_text_build_4126_x64/Data/Package%20Storage/LSP-lua/meta/Lua%205.4%20en-US%20utf8
[14:11:51.673][info] [#0:script\workspace\workspace.lua:307]: Scan library at:  file:///c%3A/Users/bultz/AppData/Roaming/rpfm/config/tw_autogen/output/wh3/campaign
[14:11:51.673][info] [#0:script\workspace\workspace.lua:307]: Scan library at:  file:///c%3A/Users/bultz/AppData/Roaming/rpfm/config/tw_autogen/output/wh3/battle
[14:11:51.673][info] [#0:script\workspace\workspace.lua:307]: Scan library at:  file:///c%3A/Users/bultz/AppData/Roaming/rpfm/config/tw_autogen/output/wh3/global
Frodo45127 commented 2 years ago

Ok, definitelly sublime is doing something weird on my side. I just tested it again, and it didn't work and marked all cm: as warnings... until I started typing, when suddenly it started picking them up. Anyway, as it seems to be working, I'll merge it now and port it to the v4_rework branch later so it's also in future 4.0 betas. Thanks for the contribution!