Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
54 commits
Select commit Hold shift + click to select a range
9589b5a
Parse method return types from inline RBS
castwide Mar 4, 2026
590ef56
RbsToComplex module
castwide Mar 5, 2026
52f179a
RbsTranslator
castwide Mar 6, 2026
b960ac0
Generate signatures from inline RBS
castwide Mar 6, 2026
5aba72c
Generate all parameters for signatures
castwide Mar 7, 2026
e88771f
Linting
castwide Mar 7, 2026
821da53
Parameters for untyped functions
castwide Mar 7, 2026
6839560
Refactor RbsTranslator.type_to_tag
castwide Mar 8, 2026
25badf5
Trailing comma
castwide Mar 8, 2026
8c2d260
Ignore type_location for UntypedFunction
castwide Mar 8, 2026
d76e9f6
Ignore length of Pin::Method
castwide Mar 8, 2026
548c67c
Redundant code
castwide Mar 8, 2026
37db0e0
Tags
castwide Mar 8, 2026
249c6da
RbsTranslator roots complex types
castwide Mar 8, 2026
6536a23
Redundant force_rooted calls
castwide Mar 8, 2026
21fb27c
Return tag
castwide Mar 8, 2026
3cdeb78
Fixed return tag
castwide Mar 8, 2026
8edcfcd
Revert Conversions
castwide Mar 8, 2026
6ba97e4
Cache command checks workspace for RBS config
castwide Mar 11, 2026
b4c59d9
Conversions use RbsTranslator.to_complex_type
castwide Mar 11, 2026
c1038b8
Redundant code
castwide Mar 11, 2026
a4b4c8f
Redundant code
castwide Mar 11, 2026
745ce36
Type fix
castwide Mar 11, 2026
eb3a640
Updates for 0.59.0
castwide May 19, 2026
db5de3b
Convert RBS implicit nil annotations (#1197)
castwide May 19, 2026
2906e3c
Parse method return types from inline RBS
castwide Mar 4, 2026
82b3ff6
RbsToComplex module
castwide Mar 5, 2026
13aa620
RbsTranslator
castwide Mar 6, 2026
9c899ac
Generate signatures from inline RBS
castwide Mar 6, 2026
b97c025
Generate all parameters for signatures
castwide Mar 7, 2026
fb3089d
Linting
castwide Mar 7, 2026
da43a95
Parameters for untyped functions
castwide Mar 7, 2026
a7ba700
Refactor RbsTranslator.type_to_tag
castwide Mar 8, 2026
ba7a7b7
Trailing comma
castwide Mar 8, 2026
d62095b
Ignore type_location for UntypedFunction
castwide Mar 8, 2026
43db78a
Ignore length of Pin::Method
castwide Mar 8, 2026
9ea9fa7
Redundant code
castwide Mar 8, 2026
e2f093f
Tags
castwide Mar 8, 2026
015c10e
RbsTranslator roots complex types
castwide Mar 8, 2026
2455167
Redundant force_rooted calls
castwide Mar 8, 2026
ee4b7ed
Return tag
castwide Mar 8, 2026
f15f608
Fixed return tag
castwide Mar 8, 2026
5835864
Revert Conversions
castwide Mar 8, 2026
b2543b9
Cache command checks workspace for RBS config
castwide Mar 11, 2026
f6bb23f
Conversions use RbsTranslator.to_complex_type
castwide Mar 11, 2026
e5247f4
Redundant code
castwide Mar 11, 2026
4f12505
Redundant code
castwide Mar 11, 2026
4a34279
Type fix
castwide Mar 11, 2026
ad28b36
Updates for 0.59.0
castwide May 19, 2026
c82522c
Merge branch 'inline-rbs' of github.com:castwide/solargraph into inli…
castwide May 19, 2026
1e3cba4
Merge fixes
castwide May 19, 2026
1907985
Private constant
castwide May 19, 2026
d21efd8
Linting
castwide May 20, 2026
1cbde41
RBS inheritance parameters
castwide May 20, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions lib/solargraph.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ class InvalidRubocopVersionError < RuntimeError; end
autoload :RbsMap, 'solargraph/rbs_map'
autoload :GemPins, 'solargraph/gem_pins'
autoload :PinCache, 'solargraph/pin_cache'
autoload :RbsTranslator, 'solargraph/rbs_translator'

dir = File.dirname(__FILE__)
VIEWS_PATH = File.join(dir, 'solargraph', 'views')
Expand Down
33 changes: 28 additions & 5 deletions lib/solargraph/parser/parser_gem/node_processors/namespace_node.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,26 @@
include ParserGem::NodeMethods

def process
superclass_name = nil
superclass_name = unpack_name(node.children[1]) if node.type == :class && node.children[1]&.type == :const
name = unpack_name(node.children[0])
comments = comments_for(node)
superclass_name = if node.type == :class
"#{type_from_node}#{parameters_from_inline_rbs}"

Check warning on line 14 in lib/solargraph/parser/parser_gem/node_processors/namespace_node.rb

View workflow job for this annotation

GitHub Actions / rubocop

[rubocop] reported by reviewdog 🐶 Use 2 (not -16) spaces for indentation. Raw Output: lib/solargraph/parser/parser_gem/node_processors/namespace_node.rb:14:15: C: Layout/IndentationWidth: Use 2 (not -16) spaces for indentation.
end

Check warning on line 15 in lib/solargraph/parser/parser_gem/node_processors/namespace_node.rb

View workflow job for this annotation

GitHub Actions / rubocop

[rubocop] reported by reviewdog 🐶 `end` at 15, 12 is not aligned with `if` at 13, 30. Raw Output: lib/solargraph/parser/parser_gem/node_processors/namespace_node.rb:15:13: W: Layout/EndAlignment: `end` at 15, 12 is not aligned with `if` at 13, 30.

loc = get_node_location(node)
nspin = Solargraph::Pin::Namespace.new(
type: node.type,
location: loc,
closure: region.closure,
name: unpack_name(node.children[0]),
comments: comments_for(node),
name: name,
comments: comments,
visibility: :public,
gates: region.closure.gates.freeze,
source: :parser
)
pins.push nspin
unless superclass_name.nil?
Solargraph.logger.warn "Superclass: #{superclass_name}" if superclass_name&.start_with?('Array')
if superclass_name
pins.push Pin::Reference::Superclass.new(
location: loc,
closure: pins.last,
Expand All @@ -33,6 +37,25 @@
end
process_children region.update(closure: nspin, visibility: :public)
end

private

# @param comments [String]
# @return [String, nil]
def parameters_from_inline_rbs
source = region.source.code_for(node)
match = source.match(/[^\n]*?#\s?+\[([^\]]*)/)
return unless match && match[1]

code = match[1].strip
return if code.empty?

"<#{code}>"
end

def type_from_node
unpack_name(node.children[1]) if node.children[1]&.type == :const
end
end
end
end
Expand Down
55 changes: 41 additions & 14 deletions lib/solargraph/pin/method.rb
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ def symbol_kind
end

def return_type
@return_type ||= ComplexType.new(signatures.map(&:return_type).flat_map(&:items))
@return_type ||= return_type_from_inline_rbs || ComplexType.new(signatures.map(&:return_type).flat_map(&:items))
end

# @param parameters [::Array<Parameter>]
Expand Down Expand Up @@ -188,18 +188,11 @@ def generate_signature parameters, return_type

# @return [::Array<Signature>]
def signatures
@signatures ||= begin
top_type = generate_complex_type
result = []
result.push generate_signature(parameters, top_type) if top_type.defined?
unless overloads.empty?
result.concat(overloads.map do |meth|
generate_signature(meth.parameters, meth.return_type)
end)
end
result.push generate_signature(parameters, @return_type || ComplexType::UNDEFINED) if result.empty?
result
end
@signatures ||= if inline_rbs.empty?
signatures_from_yard
else
signatures_from_inline_rbs
end
end

# @param return_type [ComplexType]
Expand Down Expand Up @@ -451,7 +444,6 @@ def rest_of_stack api_map

attr_writer :block, :signature_help, :documentation, :return_type

# @sg-ignore Need to add nil check here
def dodgy_visibility_source?
# as of 2025-03-12, the RBS generator used for
# e.g. activesupport did not understand 'private' markings
Expand Down Expand Up @@ -721,6 +713,41 @@ def concat_example_tags
.join("\n")
.concat("```\n")
end

# @return [ComplexType, nil]
def return_type_from_inline_rbs
return nil if inline_rbs.empty?
method_type = RBS::Parser.parse_method_type(inline_rbs)
RbsTranslator.to_complex_type(method_type.type.return_type)
rescue RBS::ParsingError
nil
end

# @return [Array<Pin::Signature>]
def signatures_from_inline_rbs
method_type = RBS::Parser.parse_method_type(inline_rbs)
[RbsTranslator.to_signature(method_type, self, parameter_names)]
rescue RBS::ParsingError
signatures_from_yard
end

# @return [Array<Pin::Signature>]
def signatures_from_yard
top_type = generate_complex_type
result = []
result.push generate_signature(parameters, top_type) if top_type.defined?
result.concat(overloads.map { |meth| generate_signature(meth.parameters, meth.return_type) }) unless overloads.empty?
result.push generate_signature(parameters, @return_type || ComplexType::UNDEFINED) if result.empty?
result
end

# @return [String]
def inline_rbs
comments.lines
.select { |line| line.start_with?(': ') }
.map { |line| line[2..].strip }
.join("\n")
end
end
end
end
Loading
Loading