Closed deathaxe closed 4 years ago
Hmm. Seems to be related with the LSP package.
Something like view.sel().clear(); view.sel()[0]
in the console will trigger this; so I would guess that a package (LSP?) is adjusting the selection in a way that's interrupting other commands that require the selection?
If that's the case, aren't plugins supposed to be thread safe in a way that something like this shouldn't happen?
With your information I searched all and added a print
to all positions, LSP runs a sel.clear()
.
The result is:
PopupListener.on_selection_modified() for view 23
lsp_update_panel.run() for view 37
PopupListener.on_selection_modified() for view 37
Traceback (most recent call last):
File "C:\Apps\Sublime Text 4\Lib\python38\sublime_plugin.py", line 796, in on_selection_modified
run_view_callbacks('on_selection_modified', view_id)
File "C:\Apps\Sublime Text 4\Lib\python38\sublime_plugin.py", line 637, in run_view_callbacks
callback(v, *args)
File "C:\Apps\Sublime Text 4\Lib\python38\sublime_plugin.py", line 129, in profiler
return event_handler(*args)
File "C:\Apps\Sublime Text 4\Data\Packages\User\debug_popup.py", line 8, in on_selection_modified
view.show_popup("Hello World", location=view.sel()[0].begin())
File "C:\Apps\Sublime Text 4\Lib\python38\sublime.py", line 753, in __getitem__
raise IndexError()
IndexError
caused by the following command:
class LspUpdatePanelCommand(sublime_plugin.TextCommand):
"""
A update_panel command to update the error panel with new text.
"""
def run(self, edit, characters):
# Clear folds
self.view.unfold(sublime.Region(0, self.view.size()))
self.view.replace(edit, sublime.Region(0, self.view.size()), characters)
print("lsp_update_panel.run() for view", self.view.id())
# Clear the selection
selection = self.view.sel()
selection.clear()
The PopupListener is triggered by typing in the normal view (id: 23) and then by the selection.clear()
as it changes the selection of the output panel (id: 37).
From this perspective, everything works pretty fine and the IndexError
is just a "normal" situation a plugin needs to handle which means: hey boy, someone removed all cursors from the view.
So any plugin which wants to access the selection, within an on_selection_modified
handler would need to handle this situation as follows.
import sublime_plugin
class PopupListener(sublime_plugin.EventListener):
def on_selection_modified(self, view):
print("PopupListener.on_selection_modified() for view", view.id())
try:
view.show_popup("Hello World", location=view.sel()[0].begin())
# ...
# ... some other failing array operation with IndexError
except IndexError:
print(" -> No cursor to do something with.")
As a result, I woudn't call it a bug any more but rather fine behavior.
IMO any plugin leaving the selection in an empty state is a bug. For example, there's no way to get a view into a empty selection state in a vanilla Sublime Text install (and if there is, I'd consider that a bug)
For example, there's no way to get a view into a empty selection state in a vanilla Sublime Text install
There is, with alt+drag.
Description
While writing the issue report for #3099 the traceback below was realized while typing text at the end of a python source document.
Tried the same with ST3. It started to stuck a bit but didn't throw an exception.EDIT: Happens as well.The error is reproducable with my setup. It is even throught right after startup, if the cursor is at the eof.
Unfortunatelly I can't provide reliable "steps to reproduce" at this point, because there are numerous packages installed with some of them being ported/opted-in to python 3.8 already. Will be hard to narrow down the culprit.
The issue doesn't appear with a vanilla install so it seems to be related with delays all the plugins might cause, even though they are not obvious.
Steps to reproduce
Open ST4 with quite a number of plugins being installed. (LSP seems to be related)
Create a plugin with the following code
Quickly type text at the end of a python source file with python language server being active via LSP package. Was typing within the plugin's code above without saving it to disc.
Expected behavior
view.sel()[0]
should always return a value.Actual behavior
Environment
Installed Packages
Loosen Packages
Profiled Events