sublimelsp / LSP

Client implementation of the Language Server Protocol for Sublime Text
https://lsp.sublimetext.io/
MIT License
1.65k stars 181 forks source link

LSP doesn't work within duplicated tab. #2251

Open yaroslavyaroslav opened 1 year ago

yaroslavyaroslav commented 1 year ago

Describe the bug LSP-Sourcekit doesn't initiates on opening already opened file in a new tab from command pallet with an option or cmd key.

To Reproduce

  1. create new swift package with swift package init
  2. Create few more empty files within ./Sources/<PackageName>/ dir. Let's say AdditionalClass.swift, AnotherClass.swift
  3. Add import Foundation line to all of those files, just in case.
  4. Open the folder of a package within Sublime Text 4 and all three files within pinned tabs. Let's say AdditionalClass.swift and convince that SourceKit label appears on Sublime Text status bar.
  5. Open files pallet (cmd+P) to chose any another file, let's say AnotherClass.swift.
  6. Hold cmd or option while hitting enter on a given file, to open it in a split view.

There would be new [duplicated] tab opened with this file, and there would be no SourceKit label appeared as well as a LSP support.

Expected behavior To provide LSP support for a files opened with an duplicated tab through command pallet.

Screenshots

Screenshot 2023-05-11 at 15 13 20 Screenshot 2023-05-11 at 15 13 26

Environment (please complete the following information):

Additional context Add any other context about the problem here. For example, whether you're using a helper package or your manual server configuration in LSP.sublime-settings. When using a manual server configuration please include it here if you believe it's applicable.

jwortmann commented 1 year ago

This is a known issue (see "LSP not initialized on views that are opened multiple times" in #2007) and it is caused by a bug in Sublime Text: https://github.com/sublimehq/sublime_text/issues/2411

rchl commented 1 year ago

We did make a workaround though - https://github.com/sublimelsp/LSP/pull/2174 Is this a different case? Haven't checked yet myself.

jwortmann commented 1 year ago

From a quick look it seems like the fix would only apply if you manually call the open_file function from LSP/plugin/core/open.py (like, for example using LSP's "Goto Definition").

yaroslavyaroslav commented 1 year ago

Just wonder, why the file: Split View doesn't affected by that?

jwortmann commented 1 year ago

Just wonder, why the file: Split View doesn't affected by that?

I guess you have to ask this the ST devs, why they employ their bugs only when the duplicate views are created from "Goto Anything", and not via "Split View" 😄

Now seriously, you can test yourself with a little plugin like

import sublime_plugin

class ViewEventListener(sublime_plugin.ViewEventListener):

    @classmethod
    def applies_to_primary_view_only(cls):
        return False

    def on_activated_async(self):
        print(f"on_activated_async View({self.view.id()}) Buffer({self.view.buffer_id()}) File({self.view.file_name()})")

and will see, that it does print the message in the console after "File: Split View" (or "Split View" from the tab context menu), but not when using the "Goto Anything" panel.

And LSP uses on_activated_async to check whether to attach a LSP server: https://github.com/sublimelsp/LSP/blob/673e5138141295813d06133d7bcdfebfb56727fb/plugin/documents.py#L335-L339