-
-
Notifications
You must be signed in to change notification settings - Fork 354
How to apply different libraries to different files? #2157
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
Comments
I think that this will do just right #2098 Are you going to implement it any time soon? |
I think I can solve my problem with this code:
file2.lua
but this seems like a bad solution |
Using the "multi-workspaces" feature of VSCode. |
lua-language-server is not just a VSCode plugin, it's a language server with a CLI. We need a way to define the project in a way that is IDE agnostic so that we can (for example) run |
I believe this is unachievable in single workspace mode, since only 1 config is allowed in the same workspace. But actually the support of multi-workspace is not specific to vscode: lua-language-server/script/provider/provider.lua Lines 111 to 126 in dc4c9f2
So now this is another problem/issue, that currently there is no way to do a lua-language-server/script/cli/check_worker.lua Lines 215 to 221 in dc4c9f2
|
Something I'm confused about... Can I define a global such that it's only available if required via a For example if I could do: library: ---a.lua
---@meta
A = { foo = 1 } ---b.lua
---@meta
B = { bar = 2 } app: ---@module "a"
A.foo -- good!
B.bar -- error, global B not declared |
I don't think so 🤔 at least not in the current state. First of all I think that the description for
---@module "library"
local library
--> this has the same effect as `local library = require "library"` You can verify this by full searching lua-language-server/script/vm/compiler.lua Lines 52 to 66 in dc4c9f2
However, I have no idea whether this is an unfinished feature or not. Back to the (multi) workspace concept, assuming my understanding is correct, a single workspace means a single runtime environment, that's why a single workspace can only have 1 set of config:
|
Okay, multi-workspace sounds theoretically possible. However, this is a giant 20 year old codebase with, for example, a folder with 30 or so files that are each in a completely isolated (but identical) environment. That is, they all have access to the same global, but it's their own unique copy. I don't think I can reasonably create that many lua configs. It would confuse everyone who is used to working on the project, and because an unreasonable maintenance burden. Without a doubt, the best solution for this project would be to be able to I am not sure how I'll proceed but we can still get value out of it even if the types have to lie in many cases. |
I don't quite get the situation. I have absolutely no idea how to tackle this ... 🙈 Assumed vscode will be used, I don't know if a
{
"settings": {
// all settings under this section will be shared among all defined workspace
"Lua.xxx": "yyy",
}
}
https://code.visualstudio.com/docs/editing/workspaces/multi-root-workspaces#_settings
|
Well, essentially there are many different types of entrypoint into the game, and they have access to different APIs via different injected globals. Sometimes these files are siblings in the same folder, so I can't just slap a
Yeah, kinda. tbh the system is kind of complex and I don't fully understand it. But essentially the issue is the above, I just need to be able to map certain global environments to different files. I might be able to get there with many different
That's not necessarily the case. Plenty of NeoVim users etc. I could explore that options though, it's an interesting thought. But even then it will just immediately become unmaintained. What is needed (ideally) is the file itself can just claim to be in a scope so it can benefit from intellisense etc. I am not an experienced Lua user, but is it the case that in a typical Lua project all globals appear in all other files, even if they are not |
With eight years of experience in server-side game development, I've primarily worked on projects using Lua. In our development team, we have a strict convention against using globals. By adhering to this best practice, the issue of globals appearing across different files and causing potential conflicts is non-existent in our projects. 😂 However, it's important to note that my experience doesn't represent the entire Lua community. |
Don't take any of my description of the project to be a defence or a claim of best-practise. It is simply problem I'm solving. |
How are you using the lua-language-server?
Visual Studio Code Extension (sumneko.lua)
Which OS are you using?
MacOS
What is the issue affecting?
Libraries
Expected Behaviour
Same variables refer to different definitions, depending on file
Actual Behaviour
Same variables do not refer to different definitions, depending on file
Reproduction steps
Create several libraries with different definitions for some global
Additional Notes
Hi!
This is a question and not a bug report. Imagine, that I have several lua files with global variable named SomeVar:
file1.lua
file2.lua
and there are two different files with annotations:
addon1/library/annotations1.lua
addon2/library/annotations2.lua
Is there any way to specify that for file "file1.lua" first library should be used, and for "file2.lua" second library should be used?
I think that similar question was referred in this issue #119
But I cannot run many language servers, because number of files can grow very large
Log File
No response
The text was updated successfully, but these errors were encountered: