LunaLua Intellisense
Posted: Mon Jul 22, 2024 8:14 am
What is Intellisense?
Intellisense is the term Microsoft uses to describe an intelligent code-editor suggestion system. You can read more about it here.
Note: intellisense does NOT equal "generative AI". There is NO generative AI being distributed or used here.
Lua being as dynamic of a language as it is, it doesn't support advanced features like that out of the box. Proper lua intellisense is only achieved by manual documentation, which is what this project achieves. You can find the Github repo here.
Why should I use this?
Catch errors before running your code
Diagnostic information will warn you about syntax errors, unused code, deprecated libraries, and it will tell you whenever it thinks you're misusing your own code and the code from SMBX/LunaLua. For example:
Deprecated:

Syntax error:

Misuse:

Less time searching the docs, handbook, and code examples
Sometimes you know what you're looking for but its exact name is only on the tip of your tongue, so you're forced to open the docs and go search for it. Or maybe you know the name of the function you're trying to call, but you don't remember the order of its arguments, or their types; intellisense will help there too.

Large and collaborative projects
The size of your project its number of contributors directly affect the ease at which you and your team members complete goals. It's easy to forget code you wrote months ago, and it's confusing to decipher the code others wrote. With intellisense, you can navigate difficult codebases much more easily.
Using "Find references" to see where a function is used:

Highly configurable
If there are features you do not fancy, I can almost guarantee you that they can be disabled and adjusted. Additionally, there are lots of additional features that you can turn on. Language servers, especially lua-language-server, are generally very robust and built with configurability in mind, and there are some keyboard shortcuts to toggle between the different levels of diagnostic "verbosity". Plus, lua-language-server is open source and I've already made one of my own contributions to it, which improved the configurability of addons.
So how do I install this?
If you're using VSCode or VSCodium it's really simple. First you need sumneko's lua language server extension. Once you install that extension, open the folder your workspace is in and hit CTRL+SHIFT+P. Then type in "Lua: Open Addon Manager" and hit enter. You should see a search bar. Now you should type in "SMBX2 LunaLua" and install the addon.
Note: you will need to have git installed to use the addon manager.
Then I recommend you open the file that gets generated at .vscode/settings.json and paste some of these settings in (if they weren't already put there automatically):
Also, make sure to enable this option for the best experience. It isn't applied automatically.
If you're using another editor it may not be quite as simple as installing an extension (though for jetbrains, it is), but it should still be very straight forwards. For example, here's a guide for how to use this with neovim. Also make sure to check out the language server documentation. If you scroll down from the main landing page you'll find some materials to help you get started. The settings listed above are compatible with all editors that support the language server protocol, and by extension, lua language server. The format you set them in may differ.
Contributing
So far there's a total 120 lua files in here because SMBX2 is damn massive, but there's still some work to be done. Follow the link to the repo and read the CONTRIBUTORS guide if you want to add to the project. But note that I'm pretty much done working on this myself.
Also, I greatly appreciate all kinds of feedback. If you have a question, concern, criticism, or just want to voice some idea, please do tell me!
Intellisense is the term Microsoft uses to describe an intelligent code-editor suggestion system. You can read more about it here.
Note: intellisense does NOT equal "generative AI". There is NO generative AI being distributed or used here.
Lua being as dynamic of a language as it is, it doesn't support advanced features like that out of the box. Proper lua intellisense is only achieved by manual documentation, which is what this project achieves. You can find the Github repo here.
Why should I use this?
Catch errors before running your code
Diagnostic information will warn you about syntax errors, unused code, deprecated libraries, and it will tell you whenever it thinks you're misusing your own code and the code from SMBX/LunaLua. For example:
Deprecated:

Syntax error:

Misuse:

Less time searching the docs, handbook, and code examples
Sometimes you know what you're looking for but its exact name is only on the tip of your tongue, so you're forced to open the docs and go search for it. Or maybe you know the name of the function you're trying to call, but you don't remember the order of its arguments, or their types; intellisense will help there too.

Large and collaborative projects
The size of your project its number of contributors directly affect the ease at which you and your team members complete goals. It's easy to forget code you wrote months ago, and it's confusing to decipher the code others wrote. With intellisense, you can navigate difficult codebases much more easily.
Using "Find references" to see where a function is used:

Highly configurable
If there are features you do not fancy, I can almost guarantee you that they can be disabled and adjusted. Additionally, there are lots of additional features that you can turn on. Language servers, especially lua-language-server, are generally very robust and built with configurability in mind, and there are some keyboard shortcuts to toggle between the different levels of diagnostic "verbosity". Plus, lua-language-server is open source and I've already made one of my own contributions to it, which improved the configurability of addons.
So how do I install this?
If you're using VSCode or VSCodium it's really simple. First you need sumneko's lua language server extension. Once you install that extension, open the folder your workspace is in and hit CTRL+SHIFT+P. Then type in "Lua: Open Addon Manager" and hit enter. You should see a search bar. Now you should type in "SMBX2 LunaLua" and install the addon.
Note: you will need to have git installed to use the addon manager.
Then I recommend you open the file that gets generated at .vscode/settings.json and paste some of these settings in (if they weren't already put there automatically):
Code: Select all
{
"Lua.addonManager.enable": true, // If the addon manager wasn't working, turn this on manually
// This field should be set by the addon manager when you install plugins
"Lua.workspace.library": [
// The directory these definitions are located
"C:/Users/<user>/AppData/Roaming/Code/User/globalStorage/sumneko.lua/addonManager/addons/smbx2-lunalua/module/library",
// The directory lpeg is located (if you're using it)
"C:/Users/<user>/AppData/Roaming/Code/User/globalStorage/sumneko.lua/addonManager/addons/lpeg/module/library"
],
"Lua.type.inferParamType": true, // This might help improve diagnostic information
"Lua.runtime.version": "LuaJIT", // The version of lua that LunaLua is based on
"Lua.diagnostics.disable": [
// "lowercase-global", // if you prefer to use lowercase names for your global variables, disable this diagnostic.
// If you are experiencing a "missing field" diagnostic error when you know you don't need the field it says you do,
// you can disable this diagnostic
// As of 9/10/2024 I believe that this is no longer necessary. Improvements have been made.
// "missing-fields",
// If you are experiencing a "missing parameter" diagnostic error when you know you don't need the parameter it says you do,
// you can disable this diagnostic
// As of 9/10/2024 I believe that this is no longer necessary. Improvements have been made.
// "missing-parameter"
],
// If you're experiencing errors with casting a number to an integer, you can turn this on. Lua does not make the distinction between
// these types during runtime, it is purely for enhanced diagnostics.
// "Lua.type.castNumberToInteger": true,
// For when something *could* be nil but you know that it won't be.
// For example: Misc.resolveFile returns a string or nil, so it will give you a diagnostic error when you try to use the
// result as a string without first checking if it's nil. Generally it's good practice to nil-check before using values, but
// you can still choose to disable this diagnostic here.
// "Lua.type.weakNilCheck": true,
}
Code: Select all
"Lua.runtime.plugin": "C:/Users/<user>/AppData/Roaming/Code/User/globalStorage/sumneko.lua/addonManager/addons/smbx2-lunalua/module/plugin.lua"
Contributing
So far there's a total 120 lua files in here because SMBX2 is damn massive, but there's still some work to be done. Follow the link to the repo and read the CONTRIBUTORS guide if you want to add to the project. But note that I'm pretty much done working on this myself.
Also, I greatly appreciate all kinds of feedback. If you have a question, concern, criticism, or just want to voice some idea, please do tell me!