Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
hasumikin committed Jan 4, 2024
1 parent 98684d5 commit b5199ff
Show file tree
Hide file tree
Showing 6 changed files with 82 additions and 59 deletions.
8 changes: 3 additions & 5 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,6 @@ gem "wdm", "~> 0.1.1", :platforms => [:mingw, :x64_mingw, :mswin]
# do not have a Java counterpart.
gem "http_parser.rb", "~> 0.6.0", :platforms => [:jruby]

group :development do
gem "rake"
gem "rbs"
gem "steep"
end
gem "rake"

gem "rbs"
30 changes: 6 additions & 24 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
GEM
remote: https://rubygems.org/
specs:
abbrev (0.1.1)
abbrev (0.1.2)
activesupport (7.1.2)
base64
bigdecimal
Expand All @@ -12,14 +12,10 @@ GEM
minitest (>= 5.1)
mutex_m
tzinfo (~> 2.0)
addressable (2.8.5)
addressable (2.8.6)
public_suffix (>= 2.0.2, < 6.0)
ast (2.4.2)
ast_utils (0.3.0)
parser (~> 2.4)
thor (>= 0.19)
base64 (0.2.0)
bigdecimal (3.1.4)
bigdecimal (3.1.5)
coffee-script (2.4.1)
coffee-script-source
execjs
Expand All @@ -39,7 +35,7 @@ GEM
ffi (>= 1.15.0)
eventmachine (1.2.7)
execjs (2.9.1)
faraday (2.7.12)
faraday (2.8.1)
base64
faraday-net_http (>= 2.0, < 3.1)
ruby2_keywords (>= 0.0.4)
Expand Down Expand Up @@ -216,7 +212,6 @@ GEM
rexml
kramdown-parser-gfm (1.1.0)
kramdown (~> 2.0)
language_server-protocol (3.15.0.2)
liquid (4.0.4)
listen (3.8.0)
rb-fsevent (~> 0.10, >= 0.10.3)
Expand All @@ -229,24 +224,21 @@ GEM
jekyll-seo-tag (~> 2.1)
minitest (5.20.0)
mutex_m (0.2.0)
nokogiri (1.15.5)
nokogiri (1.16.0)
mini_portile2 (~> 2.8.2)
racc (~> 1.4)
octokit (4.25.1)
faraday (>= 1, < 3)
sawyer (~> 0.9)
parser (2.7.2.0)
ast (~> 2.4.1)
pathutil (0.16.2)
forwardable-extended (~> 2.6)
public_suffix (4.0.7)
racc (1.7.3)
rainbow (3.1.1)
rake (13.1.0)
rb-fsevent (0.11.2)
rb-inotify (0.10.1)
ffi (~> 1.0)
rbs (3.3.2)
rbs (3.4.1)
abbrev
rexml (3.2.6)
rouge (3.26.0)
Expand All @@ -263,17 +255,8 @@ GEM
faraday (>= 0.17.3, < 3)
simpleidn (0.2.1)
unf (~> 0.1.4)
steep (0.38.0)
activesupport (>= 5.1)
ast_utils (~> 0.3.0)
language_server-protocol (~> 3.15.0.1)
listen (~> 3.0)
parser (~> 2.7.0)
rainbow (>= 2.2.2, < 4.0)
rbs (>= 0.20.0)
terminal-table (1.8.0)
unicode-display_width (~> 1.1, >= 1.1.1)
thor (1.3.0)
typhoeus (1.4.1)
ethon (>= 0.9.0)
tzinfo (2.0.6)
Expand All @@ -294,7 +277,6 @@ DEPENDENCIES
minima (~> 2.5)
rake
rbs
steep
tzinfo (>= 1, < 3)
tzinfo-data
wdm (~> 0.1.1)
Expand Down
30 changes: 22 additions & 8 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1,20 +1,34 @@
require "fileutils"
require_relative "./vendor/gems/steep-1.6.0/lib/steep"
load File.expand_path("../submodules/rbs_doc/tasks/rbs_doc.rake", __FILE__)

task :default => :all

desc "Run all tasks"
task :all => [:submodule, :documentation, :jekyll]
task :all => ["rbs_doc:generate", :jekyll]

desc "Setup"
task :setup => [:vendor, :submodule]
task :vendor do
sh "bundle install --path ./vendor/ steep"
end

PICORUBY_DIR = "submodules/picoruby"
MRUBYC_DIR = "submodules/picoruby/mrbgems/picoruby-mrubyc/repos/mrubyc"

desc "Update submodule"
task :submodule do
sh "git submodule update --init"
task :submodule => [PICORUBY_DIR, MRUBYC_DIR]

directory PICORUBY_DIR do
FileUtils.cd("submodules") do
sh "git clone https://github.com/picoruby/picoruby.git"
end
end

desc "Generate documentation"
task :documentation do
require_relative "lib/rbs_doc"
steepfile = ENV['STEEPFILE'] || File.expand_path("../submodules/picoruby/Steepfile", __FILE__)
RBSDoc::Generator.new(steepfile: steepfile).generate
directory MRUBYC_DIR do
FileUtils.cd("submodules/picoruby/mrbgems/picoruby-mrubyc/repos") do
sh "git clone https://github.com/mrubyc/mrubyc.git"
end
end

desc "Run jekyll"
Expand Down
57 changes: 36 additions & 21 deletions lib/rbs_doc.rb → submodules/rbs_doc/lib/rbs_doc.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
require "rbs"
require "active_support"
require "steep"

module RBSDoc
class SteepConfig
Expand All @@ -13,7 +12,11 @@ def initialize(steepfile)

class MethodFormatter
def initialize(method)
@info = { name: method.name }
@info = {
name: method.name,
kind: method.kind,
visibility: method.visibility
}
@info[:overloads] = method.overloads.map do |overload|
format_overload(overload)
end
Expand All @@ -23,6 +26,7 @@ def initialize(method)

def format_overload(overload)
Hash.new.tap do |member|
member[:source] = overload.method_type.location.source
%i[required_positionals optional_positionals rest_positionals trailing_positionals required_keywords optional_keywords rest_keywords].each do |key|
format_params1(key, overload.method_type.type).then do |params|
member[key] = params if params && !params.empty?
Expand Down Expand Up @@ -81,32 +85,43 @@ def format_param2(param)
class Generator
def initialize(steepfile:)
@steep_config = SteepConfig.new(steepfile)
@steep_config.config.targets[0].signature_pattern.patterns.each do |pattern|
Dir.glob("#{pattern}/*.rbs").map do |path|
generate(path)
end
end
end

def generate
def generate(path)
@result = []
@steep_config.config.targets[0].signature_pattern.patterns.each do |pattern|
Dir.glob("#{pattern}*.rbs").map do |path|
@result << Hash.new.tap do |h|
sig = RBS::Parser.parse_signature(File.read(path))
sig[2].each do |dec|
case dec
when RBS::AST::Declarations::Class
h[:class] = sig[2].first.name.name
h[:methods] = []
dec.members.each do |member|
case member
when RBS::AST::Members::MethodDefinition
formatter = RBSDoc::MethodFormatter.new(member)
h[:methods] << formatter.info
end
end
end
sig = RBS::Parser.parse_signature(File.read(path))
sig[2].each do |dec|
case dec
when RBS::AST::Declarations::Class
generate_class(dec)
end
end
pp @result
end

def generate_class(dec, upper_class = [])
@result << Hash.new.tap do |klass|
klass[:class] = upper_class + [dec.name.name]
klass[:super_class] = dec.super_class.name.name if dec.super_class
klass[:methods] = []
dec.members.each do |member|
case member
when RBS::AST::Members::MethodDefinition
formatter = RBSDoc::MethodFormatter.new(member)
klass[:methods] << formatter.info
klass[:methods].sort_by! do |method|
method[:name]
end
when RBS::AST::Declarations::Class
generate_class(member, klass[:class])
end
end
end
pp @result
end
end
end
14 changes: 14 additions & 0 deletions submodules/rbs_doc/tasks/rbs_doc.rake
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
require 'fileutils'
require_relative File.expand_path("../../lib/rbs_doc", __FILE__)

namespace :rbs_doc do
task :default => :generate

desc "Generate documentation"
task :generate do |t, args|
FileUtils.cd File.expand_path("../../../picoruby", __FILE__) do
steepfile = ENV['STEEPFILE'] || File.expand_path("../../../picoruby/Steepfile", __FILE__)
RBSDoc::Generator.new(steepfile: steepfile)
end
end
end

0 comments on commit b5199ff

Please sign in to comment.