Repository: sublimelsp/LSP

Issue:
side_by_side should preview files in a side view
**Describe the bug**
When using `side_by_side: true` option for commands that support it, if the command opens a quick panel with multiple items, the items open in the main view on changing selection and only on pressing Enter to select an item it opens in the side view. I suppose that it should also show previews in side view like native ST functionality does (for example `shift+primary+f12`).

**To Reproduce**
Steps to reproduce the behavior:
1. Set up keybinding like:
```
    {
        "command": "lsp_symbol_type_definition",
        "keys": ["f13"],
        "args": {"side_by_side": true},
        "context": [
            {
                "key": "lsp.session_with_capability",
                "operator": "equal",
                "operand": "typeDefinitionProvider"
            },
            {
                "key": "auto_complete_visible",
                "operator": "equal",
                "operand": false
            }
        ]
    },
```
3. Press F13 on some symbol that is referenced from multiple places

**Expected behavior**
Changing selection in quick panel should preview the file in a side by side view.

**Environment (please complete the following information):**
- OS: macOS
- Sublime Text version: 4134



Discussion:

Resolving patch:
diff --git a/plugin/locationpicker.py b/plugin/locationpicker.py
--- a/plugin/locationpicker.py
+++ b/plugin/locationpicker.py
@@ -29,11 +29,11 @@ def open_basic_file(
     position: Position,
     flags: int = 0,
     group: Optional[int] = None
-) -> None:
+) -> sublime.View:
     filename = session.config.map_server_uri_to_client_path(uri)
     if group is None:
         group = session.window.active_group()
-    session.window.open_file(to_encoded_filename(filename, position), flags=flags, group=group)
+    return session.window.open_file(to_encoded_filename(filename, position), flags=flags, group=group)
 
 
 class LocationPicker:
@@ -53,6 +53,7 @@ def __init__(
         self._weaksession = weakref.ref(session)
         self._side_by_side = side_by_side
         self._items = locations
+        self._highlighted_view = None  # type: Optional[sublime.View]
         manager = session.manager()
         base_dir = manager.get_project_path(view.file_name() or "") if manager else None
         self._window.show_quick_panel(
@@ -76,20 +77,35 @@ def _select_entry(self, index: int) -> None:
             # otherwise the bevior feels weird. It's the only reason why open_basic_file exists.
             if uri.startswith("file:"):
                 flags = sublime.ENCODED_POSITION
-                if self._side_by_side:
-                    flags |= sublime.ADD_TO_SELECTION | sublime.SEMI_TRANSIENT
-                open_basic_file(session, uri, position, flags)
+                if not self._side_by_side:
+                    open_basic_file(session, uri, position, flags)
             else:
                 sublime.set_timeout_async(functools.partial(open_location_async, session, location, self._side_by_side))
         else:
             self._window.focus_view(self._view)
+            # When in side-by-side mode close the current highlighted
+            # sheet upon canceling if the sheet is semi-transient
+            if self._side_by_side and self._highlighted_view:
+                sheet = self._highlighted_view.sheet()
+                if sheet and sheet.is_semi_transient():
+                    self._highlighted_view.close()
 
     def _highlight_entry(self, index: int) -> None:
         session, _, uri, position = self._unpack(index)
         if not session:
             return
         if uri.startswith("file:"):
-            open_basic_file(session, uri, position, sublime.TRANSIENT | sublime.ENCODED_POSITION)
+            flags = sublime.ENCODED_POSITION | sublime.FORCE_GROUP
+            if self._side_by_side:
+                if self._highlighted_view and self._highlighted_view.is_valid():
+                    # Replacing the MRU is done relative to the current highlighted sheet
+                    self._window.focus_view(self._highlighted_view)
+                    flags |= sublime.REPLACE_MRU | sublime.SEMI_TRANSIENT
+                else:
+                    flags |= sublime.ADD_TO_SELECTION | sublime.SEMI_TRANSIENT
+            else:
+                flags |= sublime.TRANSIENT
+            self._highlighted_view = open_basic_file(session, uri, position, flags, self._window.active_group())
         else:
             # TODO: Preview non-file uris?
             debug("no preview for", uri)


Test patch: