sublimelsp / lsp_utils

Module with LSP-related utilities for Sublime Text
https://sublimelsp.github.io/lsp_utils/
MIT License
16 stars 6 forks source link

Try to avoid deleting server files when in use #65

Closed husanjun closed 3 years ago

husanjun commented 3 years ago

Please see https://github.com/sublimelsp/LSP/pull/1737

rchl commented 3 years ago

Since this will only help when stopping the server on the main thread, and we don't really want to do that, I'm thinking we could try something else.

Instead of deleting the server files, we could try to put a marker file in the server (added such functionality in a recent PR). Then only on starting the server again we would update the server files.

I'm not sure if that would still guarantee a full server stop before we touch the files but could be worth a try.

husanjun commented 3 years ago

Yes, you only need to remove the plugin when you remove it, otherwise you just need to update it

rchl commented 3 years ago

We can't distinguish those case though. In both situations we just get plugin_unloaded called.

husanjun commented 3 years ago

https://packagecontrol.io/docs/events

I don't know if it works but I didn't try

rchl commented 3 years ago

Interesting. Didn't remember about it.

husanjun commented 3 years ago

@rchl My tests work fine f2644ff

husanjun commented 3 years ago
  1. Remove the plugin through the package control tool, the console has no errors and the directory is deleted
  2. Ignore the plugin by setting, the console has no errors
rchl commented 3 years ago

Also I'm assuming that you had server active at the time. Also, which server are you testing with?

husanjun commented 3 years ago

Yes,Occurs only in an active state,I use LSP-pyright

rwols commented 3 years ago

This bug plagued windows users for a long time unfortunately. Maybe this diff can help in the short run. In the long run I'm hoping to fix this by running all the necessary async clean up code in the UI thread using a registered exit_handler async function: https://github.com/sublimelsp/sublime_asyncio/blob/master/globalstate.py#L147

rchl commented 3 years ago

In the long run I'm hoping to fix this by running all the necessary async clean up code in the UI thread using a registered exit_handler async function: https://github.com/sublimelsp/sublime_asyncio/blob/master/globalstate.py#L147

Wouldn't that potentially result in server getting called from two different threads? Maybe even deadlocks?

rwols commented 3 years ago

No, because the entire loop stops, and then runs that single async function on the main thread. Potentially, other async operations are also handled in-between the suspension points of the exit handler.

rchl commented 3 years ago

I've tried uninstalling LSP-pyright on Windows when testing https://github.com/sublimelsp/LSP-pyright/issues/75 and gotten:

ignored packages updated to: ["LSP-pyright", "Vintage"]
unloading python 3.3 plugin LSP-pyright.commands
reloading settings Packages/LSP-pyright/LSP-pyright.sublime-settings
unloading python 3.3 plugin LSP-pyright.plugin
Traceback (most recent call last):
  File "C:\Program Files\Sublime Text\Lib\python33\sublime_plugin.py", line 243, in unload_module
    module.plugin_unloaded()
  File "C:\Users\IEUser\AppData\Roaming\Sublime Text\Installed Packages\LSP-pyright.sublime-package\plugin.py", line 15, in plugin_unloaded
    LspPyrightPlugin.cleanup()
  File "C:\Users\IEUser\AppData\Roaming\SUBLIM~1\Packages\LSP_UT~1\st3\lsp_utils\generic_client_handler.py", line 44, in cleanup
    shutil.rmtree(cls.package_storage())
  File "./python3.3/shutil.py", line 478, in rmtree
  File "./python3.3/shutil.py", line 368, in _rmtree_unsafe
  File "./python3.3/shutil.py", line 368, in _rmtree_unsafe
  File "./python3.3/shutil.py", line 368, in _rmtree_unsafe
  File "./python3.3/shutil.py", line 368, in _rmtree_unsafe
  File "./python3.3/shutil.py", line 368, in _rmtree_unsafe
  File "./python3.3/shutil.py", line 377, in _rmtree_unsafe
  File "./python3.3/shutil.py", line 375, in _rmtree_unsafe
PermissionError: [WinError 32] The process cannot access the file because it is being used by another process: 'C:\\Users\\IEUser\\AppData\\Local\\Sublime Text\\Package Storage\\LSP-pyright\\14.17.1\\language-server\\node_modules\\pyright\\dist'
reloading settings Packages/User/Package Control.sublime-settings
reloading settings Packages/User/Preferences.sublime-settings
Package Control: The package LSP-pyright has been removed
reloading settings Packages/User/Package Control.sublime-settings
ignored packages updated to: ["Vintage"]
Error loading C:\Users\IEUser\AppData\Roaming\Sublime Text\Installed Packages\LSP-pyright.sublime-package: [Errno 13] Permission denied: 'C:\\Users\\IEUser\\AppData\\Roaming\\Sublime Text\\Installed Packages\\LSP-pyright.sublime-package'
reloading settings Packages/User/Package Control.sublime-settings
reloading settings Packages/User/Preferences.sublime-settings
reloading settings Packages/User/Preferences.sublime-settings

Which makes sense because nothing is stopping the server on uninstalling the package. Even if it would, there is no guarantee that it will be stopped within one second.