Skip to content

Inline #2377

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 39 commits into
base: master
Choose a base branch
from
Draft

Inline #2377

Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
a5d2545
bundle prism
soutaro Jan 16, 2025
8bc685f
Update Steepfile
soutaro Jan 16, 2025
f24735d
Add syntax and parser
soutaro Jan 16, 2025
369a377
Add `Constant#type`
soutaro Jan 16, 2025
edce3a1
Update `Environment`
soutaro Jan 17, 2025
8dc1f67
DefinitionBuilder
soutaro Jan 18, 2025
b59256c
WIP
soutaro Jan 21, 2025
de7979e
Bump version to 4.0
soutaro Jan 21, 2025
fa21e59
Update `steep/Gemfile` for ruby-lsp environment
soutaro Jan 21, 2025
81585b8
:cat2:
soutaro Feb 5, 2025
84cde79
Add CommentBlock
soutaro Feb 12, 2025
f85fa0d
Add rbs-inline keywords, no changes on parser
soutaro Feb 12, 2025
7cb29b3
Working for parser
soutaro Feb 14, 2025
504f29f
WIP
soutaro Feb 19, 2025
c0154c2
Support generic module definition
soutaro Feb 19, 2025
598416a
Implement module-self annotation parsing
soutaro Feb 19, 2025
d009ef1
Fix module parsing
soutaro Feb 20, 2025
67a38fa
Parse module-self annotation
soutaro Feb 20, 2025
aa0565a
Implement `@rbs inherits` annotation parsing
soutaro Feb 20, 2025
f66233f
module self parsing
soutaro Feb 20, 2025
2b87b4f
Super annotation
soutaro Feb 20, 2025
4816d5a
Let `Buffer` can be nested
soutaro Feb 21, 2025
cb4d1a7
`module-self` annotation support
soutaro Feb 21, 2025
e1bd844
ivars: Implement annotation parser
soutaro Feb 21, 2025
1450863
Buffer/location fixup
soutaro Feb 21, 2025
39bc718
ivars: InlineParser
soutaro Feb 21, 2025
e626997
ivars: Fix DefinitionBuilder
soutaro Feb 21, 2025
e5ee033
@rbs!: annotation parsing
soutaro Feb 25, 2025
73636d7
@rbs!: implement inline parser
soutaro Feb 25, 2025
8777fee
Load declarations from embedded RBS
soutaro Feb 27, 2025
b39a58b
@rbs!: ancestor builder
soutaro Feb 27, 2025
f09c9f4
@rbs!: method builder
soutaro Feb 27, 2025
b9d0bc3
@rbs!: definition builder
soutaro Feb 27, 2025
0d14123
WIP
soutaro Mar 3, 2025
8b33b87
Limit singleton class members
soutaro Mar 19, 2025
bf124b5
WIP: singleton method definition ast
soutaro Mar 24, 2025
ad341f4
Fix type parameter handling
soutaro Mar 25, 2025
4b9f9fd
Method definition specific `private`/`public` visibility
soutaro Mar 27, 2025
5a39ba3
Add attribute members
soutaro Apr 1, 2025
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
Prev Previous commit
Next Next commit
WIP: singleton method definition ast
  • Loading branch information
soutaro committed Mar 24, 2025
commit bf124b5d9db7fc99efec02c778f45da65dc0879a
71 changes: 53 additions & 18 deletions lib/rbs/ast/ruby/members.rb
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,14 @@ def construct_method_type(parameters)
location: nil
)
end

def empty?
!return_type_annotation &&
param_type_annotations.empty? &&
!splat_type_annotation &&
!kwsplat_type_annotation &&
!block_type_annotation
end
end

attr_reader :type_annotations, :annotations, :override
Expand Down Expand Up @@ -274,6 +282,12 @@ def self.build(leading_block, trailing_block, variables)
unused_trailing_annotation
]
end

def empty?
annotations.empty? && override.nil? && (
type_annotations.nil? || type_annotations.empty?
)
end
end

class DefMember < Base
Expand Down Expand Up @@ -337,42 +351,63 @@ def name_location
end

class DefSingletonMember < Base
attr_reader :node
attr_reader :node, :name, :inline_annotations

def initialize(buffer, node)
def initialize(buffer, node, name:, inline_annotations:)
super(buffer)
@node = node
@name = name
@inline_annotations = inline_annotations
end

def overloads
[
Overload.new(
MethodType.new(
type_params: [],
type: Types::UntypedFunction.new(return_type: Types::Bases::Any.new(location: nil)),
block: nil,
location: nil
),
[]
)
]
end

def name
node.name
case inline_annotations.type_annotations
when DefAnnotations::DocStyleTypeAnnotations, nil
annots = inline_annotations.type_annotations || DefAnnotations::DocStyleTypeAnnotations.empty
method_type = annots.construct_method_type(node.parameters)
[
Overload.new(method_type, [])
]
when Array
inline_annotations.type_annotations.flat_map do |annotation|
case annotation
when Annotation::ColonMethodTypeAnnotation
[Overload.new(annotation.method_type.update(location: nil), annotation.annotations)]
when Annotation::MethodTypesAnnotation
annotation.overloads.map do
Overload.new(_1.method_type.update(location: nil), _1.annotations)
end
end
end
end
end

def self?
node.receiver.is_a?(Prism::SelfNode)
end

def override?
inline_annotations.override ? true : false
end

def annotations
[]
inline_annotations.annotations.flat_map do |annotation|
annotation.annotations
end
end

def location
buffer.rbs_location(node.location)
end

def map_type_name(&block)
DefSingletonMember.new(
buffer,
node,
name: name,
inline_annotations: inline_annotations.map_type_name(&block)
) #: self
end
end

class AliasMember < Base
Expand Down
2 changes: 1 addition & 1 deletion lib/rbs/inline_parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -453,7 +453,7 @@ def visit_def_node(node)
context.members << member
when AST::Ruby::Declarations::ModuleDecl, AST::Ruby::Declarations::ClassDecl
if node.receiver
member = AST::Ruby::Members::DefSingletonMember.new(buffer, node)
member = AST::Ruby::Members::DefSingletonMember.new(buffer, node, name: node.name, inline_annotations: annotations)
if member.self?
context.members << member
end
Expand Down
15 changes: 13 additions & 2 deletions sig/ast/ruby/members.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ module RBS
) -> void

def construct_method_type: (Prism::ParametersNode?) -> MethodType

def empty?: () -> bool
end

type type_annotations = DocStyleTypeAnnotations | Array[Annotation::ColonMethodTypeAnnotation | Annotation::MethodTypesAnnotation] | nil
Expand Down Expand Up @@ -86,6 +88,9 @@ module RBS
Array[Annotation::leading_annotation | CommentBlock::AnnotationSyntaxError],
Annotation::trailing_annotation | CommentBlock::AnnotationSyntaxError | nil
]

# Returns `true` if it doesn't have any annotation
def empty?: () -> bool
end

class DefMember < Base
Expand Down Expand Up @@ -121,20 +126,26 @@ module RBS
class DefSingletonMember < Base
attr_reader buffer: Buffer

attr_reader name: Symbol

attr_reader node: Prism::DefNode

def initialize: (Buffer, Prism::DefNode) -> void
attr_reader inline_annotations: DefAnnotations

def initialize: (Buffer, Prism::DefNode, name: Symbol, inline_annotations: DefAnnotations) -> void

def overloads: () -> Array[Overload]

def name: () -> Symbol
def override?: () -> bool

# Returns true if the receiver is `self`
def self?: () -> bool

def annotations: () -> Array[AST::Annotation]

def location: () -> Location

def map_type_name: () { (TypeName) -> TypeName } -> self
end

class AliasMember < Base
Expand Down