sublimelsp / LSP-julia

Julia support for Sublime's LSP plugin using LanguageServer.jl
MIT License
23 stars 1 forks source link

Environment not correctly read on initialization #21

Closed fredcallaway closed 1 year ago

fredcallaway commented 2 years ago

I find that whenever I open a new file/project and the language server initializes, it doesn't recognize any of the packages I have installed (this is true for project environments and the global environment). However, when I explicitly set the environment using the "Change Current Environment" command, it all works fine. Any idea what could be going on here?

jwortmann commented 2 years ago

There are some heuristics to choose the best environment when initializing the language server: https://github.com/sublimelsp/LSP-julia/blob/6a6170a0e66f917f7eaa01d8c5381ef155c154e7/plugin.py#L631-L654

Note that under certain circumstances (if you open a project folder but without a Project.toml in it), the environment name shown in the status bar might not match the actual environment. This is because the name in the status bar can only be set a little bit later from the __init__ method when the instance is created. But __init__ doesn't have information about the initiating view, and unfortunately we can't communicate this information from the classsmethod to the instance. Maybe there is room for improvements, but it would probably require some awkward workarounds.

Anyways, regarding your problem, according to https://github.com/sublimelsp/LSP/issues/1976#issuecomment-1321286591 you seem to use a custom "command" to start the language server, with env_path=Base.load_path_expand(LOAD_PATH[2]). When I run this line, it seems to always resolve to the global environment, which I guess is the cause that loading the correct environment doesn't work on your side...

fredcallaway commented 1 year ago

That's exactly the problem. I switched back to the default command and everything is working as expected. I'm very impressed that you noticed this from the issue. Thanks for putting in the time to help me out!