Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
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
94 changes: 86 additions & 8 deletions .github/workflows/plugins.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ permissions:
contents: read

jobs:
regression:
rails_and_rspec_typechecking:
runs-on: ubuntu-latest

steps:
Expand Down Expand Up @@ -44,9 +44,36 @@ jobs:
run: bundle exec rbs collection update
- name: Ensure typechecking still works
run: bundle exec solargraph typecheck --level strong
rails_and_rspec_specs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- name: Set up Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: 3.4 # keep same as typecheck.yml
bundler-cache: true
- uses: awalsh128/cache-apt-pkgs-action@latest
with:
packages: yq
version: 1.0
- name: Install gems
run: |
echo 'gem "solargraph-rails"' > .Gemfile
echo 'gem "solargraph-rspec"' >> .Gemfile
bundle install
bundle update --pre rbs
- name: Configure to use plugins
run: |
bundle exec solargraph config
yq -yi '.plugins += ["solargraph-rails"]' .solargraph.yml
yq -yi '.plugins += ["solargraph-rspec"]' .solargraph.yml
- name: Install gem types
run: bundle exec rbs collection update
- name: Ensure specs still run
run: bundle exec rake spec
rails:
rails_typechecking:
runs-on: ubuntu-latest

steps:
Expand All @@ -57,7 +84,7 @@ jobs:
ruby-version: 3.4 # keep same as typecheck.yml
# See https://github.com/castwide/solargraph/actions/runs/19000135777/job/54265647107?pr=1119
rubygems: latest
bundler-cache: false
bundler-cache: true
- uses: awalsh128/cache-apt-pkgs-action@latest
with:
packages: yq
Expand All @@ -75,9 +102,36 @@ jobs:
run: bundle exec rbs collection update
- name: Ensure typechecking still works
run: bundle exec solargraph typecheck --level strong
rails_specs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- name: Set up Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: 3.4 # keep same as typecheck.yml
# See https://github.com/castwide/solargraph/actions/runs/19000135777/job/54265647107?pr=1119
rubygems: latest
bundler-cache: true
- uses: awalsh128/cache-apt-pkgs-action@latest
with:
packages: yq
version: 1.0
- name: Install gems
run: |
echo 'gem "solargraph-rails"' > .Gemfile
bundle install
bundle update --pre rbs
- name: Configure to use plugins
run: |
bundle exec solargraph config
yq -yi '.plugins += ["solargraph-rails"]' .solargraph.yml
- name: Install gem types
run: bundle exec rbs collection update
- name: Ensure specs still run
run: bundle exec rake spec
rspec:
rspec_typechecking:
runs-on: ubuntu-latest

steps:
Expand All @@ -86,7 +140,7 @@ jobs:
uses: ruby/setup-ruby@v1
with:
ruby-version: 3.4 # keep same as typecheck.yml
bundler-cache: false
bundler-cache: true
- uses: awalsh128/cache-apt-pkgs-action@latest
with:
packages: yq
Expand All @@ -104,9 +158,33 @@ jobs:
run: bundle exec rbs collection update
- name: Ensure typechecking still works
run: bundle exec solargraph typecheck --level strong
rspec_specs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- name: Set up Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: 3.4 # keep same as typecheck.yml
bundler-cache: true
- uses: awalsh128/cache-apt-pkgs-action@latest
with:
packages: yq
version: 1.0
- name: Install gems
run: |
echo 'gem "solargraph-rspec"' >> .Gemfile
bundle install
bundle update --pre rbs
- name: Configure to use plugins
run: |
bundle exec solargraph config
yq -yi '.plugins += ["solargraph-rspec"]' .solargraph.yml
- name: Install gem types
run: bundle exec rbs collection update
- name: Ensure specs still run
run: bundle exec rake spec

run_solargraph_rspec_specs:
# check out solargraph-rspec as well as this project, and point the former to use the latter as a local gem
runs-on: ubuntu-latest
Expand All @@ -129,7 +207,7 @@ jobs:
with:
ruby-version: 3.4
rubygems: latest
bundler-cache: false
bundler-cache: true
- name: Install gems
run: |
set -x
Expand Down Expand Up @@ -184,7 +262,7 @@ jobs:
with:
# solargraph-rails supports Ruby 3.0+
ruby-version: '3.0'
bundler-cache: false
bundler-cache: true
# https://github.com/apiology/solargraph/actions/runs/19400815835/job/55508092473?pr=17
rubygems: latest
bundler: latest
Expand Down
15 changes: 14 additions & 1 deletion .github/workflows/rspec.yml
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,10 @@ jobs:
with:
ruby-version: ${{ matrix.ruby-version }}
bundler-cache: true
# see https://github.com/castwide/solargraph/actions/runs/19391419903/job/55485410493?pr=1119
#
# match version in Gemfile.lock and use same version below
bundler: 2.5.23
- name: Set rbs version
run: echo "gem 'rbs', '${{ matrix.rbs-version }}'" >> .Gemfile
# /home/runner/.rubies/ruby-head/lib/ruby/gems/3.5.0+2/gems/rbs-3.9.4/lib/rbs.rb:11:
Expand Down Expand Up @@ -98,9 +102,18 @@ jobs:
uses: ruby/setup-ruby@v1
with:
ruby-version: '3.4'
# see https://github.com/castwide/solargraph/actions/runs/19391419903/job/55485410493?pr=1119
#
# match version in Gemfile.lock and use same version below
bundler: 2.5.23
bundler-cache: true
- name: Install gems
run: |
bundle _2.5.23_ install
bundle update rbs # use latest available for this Ruby version
- name: Update types
run: bundle exec rbs collection update
run: |
bundle exec rbs collection update
- name: Run tests
run: bundle exec rake spec
- name: Check PR coverage
Expand Down
7 changes: 7 additions & 0 deletions lib/solargraph/api_map.rb
Original file line number Diff line number Diff line change
Expand Up @@ -754,6 +754,13 @@ def qualify_superclass fq_sub_tag
store.qualify_superclass fq_sub_tag
end

# @param require_path [String]
#
# @return [Array<Gem::Specification>, nil]
def resolve_require require_path
workspace.resolve_require require_path
end

private

# A hash of source maps with filename keys.
Expand Down
3 changes: 2 additions & 1 deletion lib/solargraph/diagnostics/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@ def initialize *args
#
# @param source [Solargraph::Source]
# @param api_map [Solargraph::ApiMap]
# @param workspace [Solargraph::Workspace, nil]
# @return [Array<Hash>]
def diagnose source, api_map
def diagnose source, api_map, workspace: nil
[]
end
end
Expand Down
4 changes: 2 additions & 2 deletions lib/solargraph/diagnostics/type_check.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ module Diagnostics
#
class TypeCheck < Base
# @return [Array<Hash>]
def diagnose source, api_map
def diagnose source, api_map, workspace: nil
# return [] unless args.include?('always') || api_map.workspaced?(source.filename)
severity = Diagnostics::Severities::ERROR
level = args.reverse.find { |a| %w[normal typed strict strong].include?(a) } || :normal
# @sg-ignore sensitive typing needs to handle || on nil types
checker = Solargraph::TypeChecker.new(source.filename, api_map: api_map, level: level.to_sym)
checker = Solargraph::TypeChecker.new(source.filename, api_map: api_map, level: level.to_sym, workspace: workspace)
checker.problems
.sort { |a, b| a.location.range.start.line <=> b.location.range.start.line }
.map do |problem|
Expand Down
12 changes: 10 additions & 2 deletions spec/api_map_method_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -118,14 +118,17 @@ class B
end

describe '#get_method_stack' do
let(:out) { StringIO.new }
let(:api_map) { described_class.load_with_cache(Dir.pwd, out) }
let(:api_map) { described_class.load('') }

context 'with stdlib that has vital dependencies' do
let(:external_requires) { ['yaml'] }
let(:method_stack) { api_map.get_method_stack('YAML', 'safe_load', scope: :class) }

it 'handles the YAML gem aliased to Psych' do
specs = api_map.resolve_require('yaml')
specs.each { |spec| api_map.cache_gem(spec) }
api_map.catalog bench

expect(method_stack).not_to be_empty
end
end
Expand All @@ -135,6 +138,11 @@ class B
let(:method_stack) { api_map.get_method_stack('Thor', 'desc', scope: :class) }

it 'handles finding Thor.desc' do
specs = api_map.resolve_require('thor')
specs.each { |spec| api_map.cache_gem(spec) }
api_map.catalog bench

# if this fails you may not have an rbs collection installed
expect(method_stack).not_to be_empty
end
end
Expand Down
4 changes: 3 additions & 1 deletion spec/doc_map_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,9 @@
context 'with require as bundle/require' do
it 'imports all gems when bundler/require used' do
doc_map_with_bundler_require = described_class.new(['bundler/require'], workspace, out: nil)
doc_map_with_bundler_require.cache_doc_map_gems!(nil)
if doc_map_with_bundler_require.pins.length <= plain_doc_map.pins.length
doc_map_with_bundler_require.cache_doc_map_gems!(nil)
end
expect(doc_map_with_bundler_require.pins.length - plain_doc_map.pins.length).to be_positive
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@
end

it 'responds to update actions' do
status = instance_double(Process::Status)
allow(status).to receive(:==).with(0).and_return(true)
allow(Open3).to receive(:capture2).with('gem update solargraph').and_return(['', status])

host = Solargraph::LanguageServer::Host.new
message = described_class.new(host, {}, current: Gem::Version.new('0.0.1'))
message.process
Expand All @@ -52,6 +56,7 @@
}
host.receive action
end.not_to raise_error
expect(Open3).to have_received(:capture2).with('gem update solargraph')
end

it 'uses bundler' do
Expand Down
2 changes: 1 addition & 1 deletion spec/library_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def foo(adapter)
end

it 'returns a Completion' do
library = described_class.new(Solargraph::Workspace.new(Dir.pwd,
library = described_class.new(Solargraph::Workspace.new('',
Solargraph::Workspace::Config.new))
library.attach Solargraph::Source.load_string(%(
require 'backport'
Expand Down
10 changes: 8 additions & 2 deletions spec/pin/base_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,14 @@
end

it 'deals well with known closure combination issue' do
Solargraph::Shell.new.uncache('yard')
api_map = Solargraph::ApiMap.load_with_cache('.', $stderr)
# if this fails you might not have an rbs collection installed
api_map = Solargraph::ApiMap.load ''

spec = Gem::Specification.find_by_name('yard')
api_map.cache_gem(spec)

bench = Solargraph::Bench.new(external_requires: ['yard'])
api_map.catalog bench
pins = api_map.get_method_stack('YARD::Docstring', 'parser', scope: :class)
expect(pins.length).to eq(1)
parser_method_pin = pins.first
Expand Down
4 changes: 3 additions & 1 deletion spec/pin/method_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -550,7 +550,9 @@ class Foo
# on type. Let's make sure we combine those with anything else
# found (e.g., additions from the BigDecimal RBS collection)
# without collapsing signatures
api_map = Solargraph::ApiMap.load_with_cache(Dir.pwd, nil)
api_map = Solargraph::ApiMap.load(Dir.pwd)
bench = Solargraph::Bench.new external_requires: ['bigdecimal']
api_map.catalog(bench)
method = api_map.get_method_stack('Integer', '+', scope: :instance).first
expect(method.signatures.count).to be > 3
end
Expand Down
2 changes: 0 additions & 2 deletions spec/position_spec.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# frozen_string_literal: true

describe Solargraph::Position do
it 'normalizes arrays into positions' do
pos = described_class.normalize([0, 1])
Expand Down
11 changes: 9 additions & 2 deletions spec/rbs_map/conversions_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,12 @@ def bar: () -> untyped

context 'with standard loads for solargraph project' do
before :all do # rubocop:disable RSpec/BeforeAfterAll
@api_map = Solargraph::ApiMap.load_with_cache('.')
@api_map = Solargraph::ApiMap.load('.')
gems = %w[parser ast open3]
bench = Solargraph::Bench.new(workspace: @api_map.workspace, external_requires: gems)
@api_map.catalog(bench)
@api_map.cache_all_for_doc_map!
@api_map.catalog(bench)
end

let(:api_map) { @api_map }
Expand Down Expand Up @@ -151,7 +156,9 @@ class Sub < Hash[Symbol, untyped]
if Gem::Version.new(RBS::VERSION) >= Gem::Version.new('3.9.1')
context 'with method pin for Open3.capture2e' do
it 'accepts chdir kwarg' do
api_map = Solargraph::ApiMap.load_with_cache('.', $stdout)
api_map = Solargraph::ApiMap.load('.')
bench = Solargraph::Bench.new(external_requires: ['open3'])
api_map.catalog(bench)

method_pin = api_map.pins.find do |pin|
pin.is_a?(Solargraph::Pin::Method) && pin.path == 'Open3.capture2e'
Expand Down
11 changes: 6 additions & 5 deletions spec/yard_map/mapper_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
end

def pins_with require
doc_map = Solargraph::DocMap.new([require], @api_map.workspace, out: nil)
doc_map.cache_doc_map_gems!(nil)
doc_map = Solargraph::DocMap.new([require], @api_map.workspace, out: $stderr)
doc_map.cache_doc_map_gems!($stderr)
doc_map.pins
end

Expand Down Expand Up @@ -39,9 +39,10 @@ def pins_with require

it 'marks correct return type from RuboCop::Options.new' do
# Using rubocop because it's a known dependency
pins = pins_with('rubocop').select { |pin| pin.path == 'RuboCop::Options.new' }
expect(pins.map(&:return_type).uniq.map(&:to_s)).to eq(['self'])
expect(pins.flat_map(&:signatures).map(&:return_type).uniq.map(&:to_s)).to eq(['self'])
all_pins = pins_with('open3')
pins = all_pins.select { |pin| pin.path == 'Open3.capture2e' }
expect(pins.map(&:return_type).uniq.map(&:to_s)).to eq(['Array(String, Process::Status)'])
expect(pins.flat_map(&:signatures).map(&:return_type).uniq.map(&:to_s)).to eq(['Array(String, Process::Status)'])
end

it 'marks non-explicit methods' do
Expand Down
Loading
Loading