Skip to content

Commit

Permalink
Switch to using YARP as the parser (#41)
Browse files Browse the repository at this point in the history
* Switch to using YARP as the parser

This parser is going to be backend for Syntax Tree soon anyway, so
we may as well start using it. It comes with much increased speed
and much reduced memory.

* Fix undefined variable in `Analyzer#analyze`

* Introduce `Class/ModuleDefiniton#qualified_namespace` for matching namespaces

Now, that `Class/ModuleDefiniton#namespace` is an array of constants we need another way of comparing and matching namespaces. That's why this commit introduces `Class/ModuleDefiniton#qualified_namespace` so we can compare and match the namespaces as strings.

---------

Co-authored-by: Marco Roth <marco.roth@intergga.ch>
  • Loading branch information
kddnewton and marcoroth committed Aug 15, 2023
1 parent abe40a4 commit 8a02fb3
Show file tree
Hide file tree
Showing 13 changed files with 385 additions and 227 deletions.
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ gem "httparty", "~> 0.21.0"
gem "view_component", "~> 3.5"

# Interact with the Ruby syntax tree
gem "syntax_tree", "~> 6.1"
gem "yarp", "~> 0.6"

# A pure Ruby code highlighter that is compatible with Pygments
gem "rouge", "~> 4.1"
Expand Down
6 changes: 2 additions & 4 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,6 @@ GEM
ast (~> 2.4.1)
racc
pg (1.5.3)
prettier_print (1.2.1)
psych (5.1.0)
stringio
public_suffix (5.0.3)
Expand Down Expand Up @@ -236,8 +235,6 @@ GEM
stimulus-rails (1.2.2)
railties (>= 6.0.0)
stringio (3.0.7)
syntax_tree (6.1.1)
prettier_print (>= 1.2.0)
thor (1.2.2)
timeout (0.4.0)
turbo-rails (1.4.0)
Expand All @@ -260,6 +257,7 @@ GEM
websocket-extensions (>= 0.1.0)
websocket-extensions (0.1.5)
yard (0.9.34)
yarp (0.6.0)
zeitwerk (2.6.11)

PLATFORMS
Expand Down Expand Up @@ -293,12 +291,12 @@ DEPENDENCIES
sitemap_generator (~> 6.3)
sprockets-rails
stimulus-rails
syntax_tree (~> 6.1)
turbo-rails
tzinfo-data
view_component (~> 3.5)
web-console
yard (~> 0.9.34)
yarp (~> 0.6)

RUBY VERSION
ruby 3.2.2p53
Expand Down
2 changes: 1 addition & 1 deletion app/components/method_details.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<%= render Layout::Subheading.new(title: @object.code.signature) %>
</div>

<% comment = @object.comments.each.map { |comment| comment.value.strip.gsub("#", "").strip+"<br>" }.join("\n") %>
<% comment = @object.comments.each.map { |comment| "#{comment}<br>" }.join("\n") %>
<%#== YARD::Templates::Helpers::Markup::RDocMarkup.new(comment).to_html %>
Expand Down
10 changes: 5 additions & 5 deletions app/controllers/gems_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,14 @@ def search

def nodule
@module = find_module!(params[:module])
@classes = @gem.classes.select { |klass| klass.namespace == @module.qualified_name }
@modules = @gem.modules.select { |nodule| nodule.namespace == @module.qualified_name }
@classes = @gem.classes.select { |klass| klass.qualified_namespace == @module.qualified_name }
@modules = @gem.modules.select { |nodule| nodule.qualified_namespace == @module.qualified_name }
end

def klass
@klass = find_class!(params[:class])
@namespace = find_namespace(@klass.namespace)
@classes = @gem.classes.select { |klass| klass.namespace == @klass.qualified_name }
@namespace = find_namespace(@klass.qualified_namespace)
@classes = @gem.classes.select { |klass| klass.qualified_namespace == @klass.qualified_name }
end

def instance_method
Expand Down Expand Up @@ -90,7 +90,7 @@ def set_gem
def set_target
if params[:class]
@target = find_class!(params[:class])
@namespace = find_namespace(@target.namespace)
@namespace = find_namespace(@target.qualified_namespace)
elsif params[:module]
@target = find_module!(params[:module])
else
Expand Down

0 comments on commit 8a02fb3

Please sign in to comment.