-
Notifications
You must be signed in to change notification settings - Fork 170
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor client capabilities into its own class (#2805)
### Motivation As pointed out by @andyw8, our implementation of the global state was growing a little too much and so was the body of `apply_options`. This PR extracts a new object to store client capabilities, so that we can organize concerns a bit better. ### Implementation Extracted the client capabilities into an object and adapted the code that was using them for the new structure. ### Automated Tests Updated existing tests.
- Loading branch information
Showing
8 changed files
with
76 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
# typed: strict | ||
# frozen_string_literal: true | ||
|
||
module RubyLsp | ||
# This class stores all client capabilities that the Ruby LSP and its add-ons depend on to ensure that we're | ||
# not enabling functionality unsupported by the editor connecting to the server | ||
class ClientCapabilities | ||
extend T::Sig | ||
|
||
sig { returns(T::Boolean) } | ||
attr_reader :supports_watching_files, | ||
:supports_request_delegation, | ||
:window_show_message_supports_extra_properties | ||
|
||
sig { void } | ||
def initialize | ||
# The editor supports watching files. This requires two capabilities: dynamic registration and relative pattern | ||
# support | ||
@supports_watching_files = T.let(false, T::Boolean) | ||
|
||
# The editor supports request delegation. This is an experimental capability since request delegation has not been | ||
# standardized into the LSP spec yet | ||
@supports_request_delegation = T.let(false, T::Boolean) | ||
|
||
# The editor supports extra arbitrary properties for `window/showMessageRequest`. Necessary for add-ons to show | ||
# dialogs with user interactions | ||
@window_show_message_supports_extra_properties = T.let(false, T::Boolean) | ||
|
||
# Which resource operations the editor supports, like renaming files | ||
@supported_resource_operations = T.let([], T::Array[String]) | ||
end | ||
|
||
sig { params(capabilities: T::Hash[Symbol, T.untyped]).void } | ||
def apply_client_capabilities(capabilities) | ||
workspace_capabilities = capabilities[:workspace] || {} | ||
|
||
file_watching_caps = workspace_capabilities[:didChangeWatchedFiles] | ||
if file_watching_caps&.dig(:dynamicRegistration) && file_watching_caps&.dig(:relativePatternSupport) | ||
@supports_watching_files = true | ||
end | ||
|
||
@supports_request_delegation = capabilities.dig(:experimental, :requestDelegation) || false | ||
supported_resource_operations = workspace_capabilities.dig(:workspaceEdit, :resourceOperations) | ||
@supported_resource_operations = supported_resource_operations if supported_resource_operations | ||
|
||
supports_additional_properties = capabilities.dig( | ||
:window, | ||
:showMessage, | ||
:messageActionItem, | ||
:additionalPropertiesSupport, | ||
) | ||
@window_show_message_supports_extra_properties = supports_additional_properties || false | ||
end | ||
|
||
sig { returns(T::Boolean) } | ||
def supports_rename? | ||
@supported_resource_operations.include?("rename") | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters