Register extra definition files depending on file
It would be good to be able to register extra definitions, e.g. testez.d.lua.
We should put this in configuration and make it so it maps globs to extra definitions
@JohnnyMorganz I'm not sure how much work this issue will be to implement properly, so in the meantime, would it be possible to just expose this file after the extension is installed? https://github.com/JohnnyMorganz/luau-lsp/blob/master/scripts/globalTypes.d.lua
If we could simply add to or replace this file (in the VS Code extensions directory) post-installation, that'd be perfect for now.
@mikejohnstn You should be able to find the file installed at %appdata%\Code\User\globalStorage\johnnymorganz.luau-lsp (or the non-Windows equivalent). Note that it does automatically run an update every Roblox update (which is weekly), so you may have to rewrite it every so often.
Hopefully I'll get something to sort this out soon (and probably another option to disable the auto API update if you don't need it!)
Found the file, and works perfectly for now. Thanks!
I updated and confirmed the new definition file is working, as well as disabling the Roblox definition file. 👍
A couple issues (and maybe why you haven't closed this yet):
-
If there's an error while reading the definition file, you only get a very generic message. Is there a way to surface what the problem might be? Otherwise it takes a lot of guessing when you have a typo or other problem in the definitions. My workaround is to manually reload after pretty much every small change to my definition file to make sure it works.
-
Any way to auto-refresh when the definition file changes, so we don't have to manually reload?
Definitely want to improve both of these aspects, the issue right now is that definition files are passed and loaded at server startup (using command line flags). We can't display diagnostics until the initialisation handshake is complete, but we load in the file before this. Loading at startup is also why a reboot is required currently.
I plan on looking into deferring the definition files until later, just need to find out a way to cleanly clear the old types and reload the new ones, which is the main hurdle right now. Forcing a reload right now is just me being lazy 😅
- If there's an error while reading the definition file, you only get a very generic message. Is there a way to surface what the problem might be? Otherwise it takes a lot of guessing when you have a typo or other problem in the definitions. My workaround is to manually reload after pretty much every small change to my definition file to make sure it works.
What I would recommend for the time being if you are iterating on your definitions file is to run the standalone CLI tool:
luau-lsp analyze --definitions=/path/to/definitions.d.lua test.lua
This should give more helpful error diagnostics if the definitions file fails to load
What I would recommend for the time being if you are iterating on your definitions file is to run the standalone CLI tool
Ah nice, I didn't think of that. Cheers.