sublimelsp / LSP

Client implementation of the Language Server Protocol for Sublime Text

Home Page:https://lsp.sublimetext.io/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Capabilites with selector fails to register

yaroslavyaroslav opened this issue · comments

Describe the bug

LSP-SourceKit fails to register semanticTokensProvider capability in LSP because of its server sending documentSelector property within the response.

To Reproduce

Steps to reproduce the behavior:

  1. Install https://github.com/sublimelsp/LSP-SourceKit
  2. open a swift file within this any swift package i.e. https://github.com/Alamofire/Alamofire
  3. The error bellow would be thrown
Package Control: Installing 2 libraries...
Error handling None
Traceback (most recent call last):
  File "/Users/user/Library/Application Support/Sublime Text/Packages/LSP/plugin/core/sessions.py", line 2339, in on_payload
    handler(result)
  File "/Users/user/Library/Application Support/Sublime Text/Packages/LSP/plugin/session_buffer.py", line 597, in _on_semantic_tokens_async
    self._draw_semantic_tokens_async()
  File "/Users/user/Library/Application Support/Sublime Text/Packages/LSP/plugin/session_buffer.py", line 646, in _draw_semantic_tokens_async
    token_type, token_modifiers, scope = self.session.decode_semantic_token(
  File "/Users/user/Library/Application Support/Sublime Text/Packages/LSP/plugin/core/sessions.py", line 1818, in decode_semantic_token
    types_legend = tuple(cast(List[str], self.get_capability('semanticTokensProvider.legend.tokenTypes')

Expected behavior

LSP should handle semantic response from a server.

Screenshots

If applicable, add screenshots to help explain your problem.

Logs

Environment (please complete the following information):

  • OS: macOS 14.4.1
  • Sublime Text version: 4173
  • LSP version: 2.0.0
  • Language servers used: sourcekit-lsp

Additional context

The cause of error is this lines within capabilities registration logic from sessions.py

# for sb in self.session_buffers_async():
                #     debug("{}: session buffer:".format(self.config.name), sb, data.selector)
                #     data.check_applicable(sb)

or more precisely this from class _RegistrationData:

    def check_applicable(self, sb: SessionBufferProtocol) -> None:
        for sv in sb.session_views:
            if self.selector.matches(sv.view):
                self.session_buffers.add(sb)
                sb.register_capability_async(
                    self.registration_id, self.capability_path, self.registration_path, self.options)
                return

It seems that sb.register_capability_asyn isn't implemented.

Addition of this line self.capabilities.register(registration_id, capability_path, registration_path, options) in if data.selector leaf of a control flow fixes the issue.