-
Notifications
You must be signed in to change notification settings - Fork 172
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Integrate builder pattern to refactor hover responses
Hover response construction and manipulation can be delegated to a builder class to promote extensibility and encapsulation.
- Loading branch information
Aryan Soni
committed
Jan 21, 2024
1 parent
291bc84
commit 3526517
Showing
11 changed files
with
89 additions
and
107 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
# typed: strict | ||
# frozen_string_literal: true | ||
|
||
module RubyLsp | ||
class OperationNotPermitted < StandardError; end | ||
|
||
class ResponseBuilder | ||
extend T::Sig | ||
extend T::Generic | ||
|
||
Elem = type_member { { upper: Object } } | ||
|
||
sig { void } | ||
def initialize | ||
@response = T.let([], T::Array[Elem]) | ||
end | ||
|
||
sig { params(elem: Elem).void } | ||
def <<(elem) | ||
@response << elem | ||
end | ||
|
||
sig { returns(T.nilable(Elem)) } | ||
def pop | ||
@response.pop | ||
end | ||
|
||
sig { returns(T::Boolean) } | ||
def empty? | ||
@response.empty? | ||
end | ||
end | ||
|
||
class HoverResponseBuilder < ResponseBuilder | ||
extend T::Sig | ||
extend T::Generic | ||
|
||
Elem = type_member { { fixed: String } } | ||
|
||
sig { returns(String) } | ||
def build_concatenated_response | ||
@response.join("\n\n") | ||
end | ||
|
||
sig { override.returns(T.nilable(Elem)) } | ||
def pop | ||
raise OperationNotPermitted, "Cannot pop from a HoverResponseBuilder" | ||
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