-
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.
Restructure DocumentSymbol request (#1311)
Expose DocumentSymbolStack and convert restructure DocumentSymbol request
- Loading branch information
Showing
6 changed files
with
109 additions
and
53 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
# typed: strict | ||
# frozen_string_literal: true | ||
|
||
module RubyLsp | ||
class Response | ||
extend T::Sig | ||
extend T::Generic | ||
|
||
abstract! | ||
|
||
ResponseType = type_member | ||
|
||
sig { abstract.returns(ResponseType) } | ||
def result; end | ||
|
||
class DocumentSymbolStack < Response | ||
ResponseType = type_member { { fixed: T::Array[Interface::DocumentSymbol] } } | ||
|
||
class SymbolHierarchyRoot | ||
extend T::Sig | ||
|
||
sig { returns(T::Array[Interface::DocumentSymbol]) } | ||
attr_reader :children | ||
|
||
sig { void } | ||
def initialize | ||
@children = T.let([], T::Array[Interface::DocumentSymbol]) | ||
end | ||
end | ||
|
||
extend T::Sig | ||
|
||
sig { void } | ||
def initialize | ||
super | ||
@stack = T.let( | ||
[SymbolHierarchyRoot.new], | ||
T::Array[T.any(SymbolHierarchyRoot, Interface::DocumentSymbol)], | ||
) | ||
end | ||
|
||
sig { params(symbol: Interface::DocumentSymbol).void } | ||
def push(symbol) | ||
@stack << symbol | ||
end | ||
|
||
alias_method(:<<, :push) | ||
|
||
sig { returns(T.nilable(Interface::DocumentSymbol)) } | ||
def pop | ||
if @stack.size > 1 | ||
T.cast(@stack.pop, Interface::DocumentSymbol) | ||
end | ||
end | ||
|
||
sig { returns(T.any(SymbolHierarchyRoot, Interface::DocumentSymbol)) } | ||
def last | ||
T.must(@stack.last) | ||
end | ||
|
||
sig { override.returns(T::Array[Interface::DocumentSymbol]) } | ||
def result | ||
T.must(@stack.first).children | ||
end | ||
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