Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LSP doesn't work within duplicated tab. #2251

Open
yaroslavyaroslav opened this issue May 11, 2023 · 5 comments
Open

LSP doesn't work within duplicated tab. #2251

yaroslavyaroslav opened this issue May 11, 2023 · 5 comments
Labels
sublime issue Issues related to shortcomings or bugs in the ST API

Comments

@yaroslavyaroslav
Copy link

yaroslavyaroslav commented May 11, 2023

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):

  • OS: macOS 13.3.1(a)
  • Sublime Text version: 4150
  • LSP version: 1.23.0
  • Language servers used: SourceKit

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
Copy link
Member

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: sublimehq/sublime_text#2411

@rchl
Copy link
Member

rchl commented May 11, 2023

We did make a workaround though - #2174
Is this a different case? Haven't checked yet myself.

@jwortmann
Copy link
Member

jwortmann commented May 11, 2023

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
Copy link
Author

yaroslavyaroslav commented May 11, 2023

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

@jwortmann
Copy link
Member

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:

LSP/plugin/documents.py

Lines 335 to 339 in 673e513

def on_activated_async(self) -> None:
if self.view.is_loading() or not is_regular_view(self.view):
return
if not self._registered:
self._register_async()

@rchl rchl added the sublime issue Issues related to shortcomings or bugs in the ST API label May 11, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
sublime issue Issues related to shortcomings or bugs in the ST API
Projects
None yet
Development

No branches or pull requests

3 participants