Permalink
Browse files

Fix in-memory cache issue and add some nice minor utilities (#57)

* Add `rake console` and `rake spec` commands

Running `rake console` will automatically start an IRB session with the
library loaded.

Running `rake spec` will run all the specs in the project.

* By default do not process the `.bundle` 

It's a common HUGE directoy that we have in big codebases using `bundler` and can slow everything down.

* Fix initialization of maps and stores inside Solargraph::ApiMap

It seems like they are not playing nice with autoload.

After this change I was able to achieve close-to-instantenous Go To Definition on a very big Rails project using Solargraph's VSCode extension.

* Improve the `rake console` task to use Pry instead of IRB

Pry is a much better Ruby REPL! :D
  • Loading branch information...
douglascamata authored and castwide committed May 15, 2018
1 parent c20268d commit c85f287f790163fb1b5d37552a8f19f71e5a4815
Showing with 30 additions and 16 deletions.
  1. +11 −0 Rakefile
  2. +16 −14 lib/solargraph/api_map.rb
  3. +2 −2 lib/solargraph/workspace/config.rb
  4. +1 −0 solargraph.gemspec
@@ -1,3 +1,14 @@
require 'rake'
require 'rspec/core/rake_task'
require 'bundler/gem_tasks'

begin
require 'rspec/core/rake_task'
RSpec::Core::RakeTask.new(:spec)
rescue LoadError
end

desc "Open a Pry session preloaded with this library"
task :console do
sh "pry -I lib -r solargraph.rb"
end
@@ -20,6 +20,14 @@ class ApiMap
# @return [Solargraph::Workspace]
attr_reader :workspace

# @return [ApiMap::Store]
attr_reader :store

# Get a LiveMap associated with the current workspace.
#
# @return [Solargraph::LiveMap]
attr_reader :live_map

# @param workspace [Solargraph::Workspace]
def initialize workspace = Solargraph::Workspace.new(nil)
@workspace = workspace
@@ -28,7 +36,7 @@ def initialize workspace = Solargraph::Workspace.new(nil)
@yard_stale = true
# process_maps
@sources = workspace.sources
yard_map
refresh_store_and_maps
end

# Create an ApiMap with a workspace in the specified directory.
@@ -38,11 +46,6 @@ def self.load directory
self.new(Solargraph::Workspace.new(directory))
end

# @return [ApiMap::Store]
def store
@store ||= ApiMap::Store.new(@sources)
end

def pins
store.pins
end
@@ -68,19 +71,12 @@ def required
# @return [Solargraph::YardMap]
def yard_map
# refresh
if @yard_map.nil? || @yard_map.required.to_set != required.to_set
if @yard_map.required.to_set != required.to_set
@yard_map = Solargraph::YardMap.new(required: required, workspace: workspace)
end
@yard_map
end

# Get a LiveMap associated with the current workspace.
#
# @return [Solargraph::LiveMap]
def live_map
@live_map ||= Solargraph::LiveMap.new(self)
end

# Declare a virtual source that will be included in the map regardless of
# whether it's in the workspace.
#
@@ -426,6 +422,12 @@ def probe

private

def refresh_store_and_maps
@store = ApiMap::Store.new(@sources)
@live_map = Solargraph::LiveMap.new(self)
@yard_map = Solargraph::YardMap.new(required: required, workspace: workspace)
end

def process_virtual
unless @virtual_source.nil?
map_source @virtual_source
@@ -13,7 +13,7 @@ class Config
def initialize workspace = nil
@workspace = workspace
include_globs = ['**/*.rb']
exclude_globs = ['spec/**/*', 'test/**/*', 'vendor/**/*']
exclude_globs = ['spec/**/*', 'test/**/*', 'vendor/**/*', '.bundle/**/*']
unless @workspace.nil?
sfile = File.join(@workspace, '.solargraph.yml')
if File.file?(sfile)
@@ -44,7 +44,7 @@ def included
end

# An array of files excluded from the workspace.
#
#
# @return [Array<String>]
def excluded
return [] if workspace.nil?
@@ -30,4 +30,5 @@ Gem::Specification.new do |s|

s.add_development_dependency 'rspec', '~> 3.5', '>= 3.5.0'
s.add_development_dependency 'simplecov', '~> 0.14'
s.add_development_dependency 'pry', '~> 0.11.3'
end

0 comments on commit c85f287

Please sign in to comment.