Skip to content

Commit

Permalink
Merge branch 'master' into remove-e2mmap
Browse files Browse the repository at this point in the history
  • Loading branch information
castwide authored Jan 8, 2025
2 parents b07b345 + 9440f13 commit 0e165be
Show file tree
Hide file tree
Showing 23 changed files with 119 additions and 60 deletions.
10 changes: 4 additions & 6 deletions .github/workflows/rspec.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,17 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
ruby-version: ['2.6', '2.7', '3.0', '3.1']
ruby-version: ['2.6', '2.7', '3.0', '3.3', '3.4', 'head']

steps:
- uses: actions/checkout@v3
- name: Set up Ruby
# To automatically get bug fixes and new Ruby versions for ruby/setup-ruby,
# change this to (see https://github.com/ruby/setup-ruby#versioning):
# uses: ruby/setup-ruby@v1
uses: ruby/setup-ruby@2b019609e2b0f1ea1a2bc8ca11cb82ab46ada124
uses: ruby/setup-ruby@v1
with:
ruby-version: ${{ matrix.ruby-version }}
bundler-cache: false
- run: bundle install
- name: Install gems
run: bundle install
- name: Set up yardocs
run: bundle exec yard gems
- name: Run tests
Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 0.50.1
- Resolve self in yieldself tags
- Include absolute paths in config (#674)

## 0.50.0 - December 5, 2023
- Remove .travis.yml as its not longer used (#627)
- Fix empty string case when processing requires (#644)
Expand Down
1 change: 0 additions & 1 deletion SPONSORS.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ The following people and organizations provide funding or other resources. [Beco
## Linked Sponsors

- **[Calyptix Security](https://www.calyptix.com/)**
- **[Lightward](https://lightward.com)**

## Named Sponsors

Expand Down
2 changes: 1 addition & 1 deletion lib/solargraph/cache.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ def base_dir
# The directory is not stored in a variable so it can be overridden
# in specs.
ENV['SOLARGRAPH_CACHE'] ||
ENV['XDG_CACHE_HOME'] ? File.join(ENV['XDG_CACHE_HOME'], 'solargraph') :
(ENV['XDG_CACHE_HOME'] ? File.join(ENV['XDG_CACHE_HOME'], 'solargraph') : nil) ||
File.join(Dir.home, '.cache', 'solargraph')
end

Expand Down
2 changes: 0 additions & 2 deletions lib/solargraph/convention.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ module Solargraph
module Convention
autoload :Base, 'solargraph/convention/base'
autoload :Gemfile, 'solargraph/convention/gemfile'
autoload :Rspec, 'solargraph/convention/rspec'
autoload :Gemspec, 'solargraph/convention/gemspec'
autoload :Rakefile, 'solargraph/convention/rakefile'

Expand Down Expand Up @@ -43,7 +42,6 @@ def self.for_global(yard_map)

register Gemfile
register Gemspec
register Rspec
register Rakefile
end
end
30 changes: 0 additions & 30 deletions lib/solargraph/convention/rspec.rb

This file was deleted.

2 changes: 1 addition & 1 deletion lib/solargraph/language_server/host.rb
Original file line number Diff line number Diff line change
Expand Up @@ -633,7 +633,7 @@ def default_configuration
'rename' => true,
'references' => true,
'autoformat' => false,
'diagnostics' => false,
'diagnostics' => true,
'formatting' => false,
'folding' => true,
'highlights' => true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ class Solargraph::LanguageServer::Message::TextDocument::DocumentSymbol < Solarg
def process
pins = host.document_symbols params['textDocument']['uri']
info = pins.map do |pin|
next nil unless pin.location&.filename

result = {
name: pin.name,
containerName: pin.namespace,
Expand All @@ -17,7 +19,8 @@ def process
deprecated: pin.deprecated?
}
result
end
end.compact

set_result info
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def config_for(file_uri)
def cli_args file_uri, config
file = UriHelpers.uri_to_file(file_uri)
args = [
config['cops'] == 'all' ? '--autocorrect-all' : '--autocorrect',
config['cops'] == 'all' ? '-A' : '-a',
'--cache', 'false',
'--format', formatter_class(config).name,
]
Expand Down
4 changes: 4 additions & 0 deletions lib/solargraph/parser/rubyvm/class_methods.rb
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,13 @@ def is_ast_node? node
end

def node_range node
if node.nil?
nil
else
st = Position.new(node.first_lineno - 1, node.first_column)
en = Position.new(node.last_lineno - 1, node.last_column)
Range.new(st, en)
end
end

def recipient_node tree
Expand Down
2 changes: 1 addition & 1 deletion lib/solargraph/pin/block.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def binder_or_nil api_map
if receiver_pin && receiver_pin.docstring
ys = receiver_pin.docstring.tag(:yieldself)
if ys && ys.types && !ys.types.empty?
return ComplexType.try_parse(*ys.types).qualify(api_map, receiver_pin.context.namespace)
return ComplexType.try_parse(*ys.types).qualify(api_map, receiver_pin.context.namespace).self_to(receiver_pin.full_context.namespace)
end
end
nil
Expand Down
2 changes: 1 addition & 1 deletion lib/solargraph/pin/search.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def do_query
# @return [Float]
def fuzzy_string_match str1, str2
return (1.0 + (str2.length.to_f / str1.length.to_f)) if str1.downcase.include?(str2.downcase)
JaroWinkler.distance(str1, str2, ignore_case: true)
JaroWinkler.similarity(str1, str2, ignore_case: true)
end
end
end
Expand Down
17 changes: 15 additions & 2 deletions lib/solargraph/source_map.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ def initialize source, pins, locals
@pins = pins
@locals = locals
environ.merge Convention.for_local(self) unless filename.nil?
self.convention_pins = environ.pins
@pin_class_hash = pins.to_set.classify(&:class).transform_values(&:to_a)
@pin_select_cache = {}
end
Expand Down Expand Up @@ -65,11 +66,12 @@ def environ
@environ ||= Environ.new
end

# all pins except Solargraph::Pin::Reference::Reference
# @return [Array<Pin::Base>]
def document_symbols
@document_symbols ||= pins.select { |pin|
@document_symbols ||= (pins + convention_pins).select do |pin|
pin.path && !pin.path.empty?
}
end
end

# @param query [String]
Expand Down Expand Up @@ -159,6 +161,17 @@ def map source

private

# @return [Array<Pin::Base>]
def convention_pins
@convention_pins || []
end

def convention_pins=(pins)
# unmemoizing the document_symbols in case it was called from any of convnetions
@document_symbols = nil
@convention_pins = pins
end

# @param line [Integer]
# @param character [Integer]
# @param klasses [Array<Class>]
Expand Down
2 changes: 1 addition & 1 deletion lib/solargraph/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# frozen_string_literal: true

module Solargraph
VERSION = '0.50.0'
VERSION = '0.50.1'
end
11 changes: 6 additions & 5 deletions lib/solargraph/workspace/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class Config

# @param directory [String]
def initialize directory = ''
@directory = directory
@directory = File.absolute_path(directory)
@raw_data = config_data
included
excluded
Expand All @@ -42,7 +42,8 @@ def excluded
end

def allow? filename
filename.start_with?(directory) &&
filename = File.absolute_path(filename, directory)
filename.start_with?(directory) &&
!excluded.include?(filename) &&
excluded_directories.none? { |d| filename.start_with?(d) }
end
Expand Down Expand Up @@ -171,7 +172,7 @@ def default_config
# @return [Array<String>]
def process_globs globs
result = globs.flat_map do |glob|
Dir[File.join directory, glob]
Dir[File.absolute_path(glob, directory)]
.map{ |f| f.gsub(/\\/, '/') }
.select { |f| File.file?(f) }
end
Expand All @@ -186,7 +187,7 @@ def process_globs globs
def process_exclusions globs
remainder = globs.select do |glob|
if glob_is_directory?(glob)
exdir = File.join(directory, glob_to_directory(glob))
exdir = File.absolute_path(glob_to_directory(glob), directory)
included.delete_if { |file| file.start_with?(exdir) }
false
else
Expand Down Expand Up @@ -224,7 +225,7 @@ def glob_to_directory glob
def excluded_directories
@raw_data['exclude']
.select { |g| glob_is_directory?(g) }
.map { |g| File.join(directory, glob_to_directory(g)) }
.map { |g| File.absolute_path(glob_to_directory(g), directory) }
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/solargraph/yard_map.rb
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ def spec_for_require path
# Avoid loading the spec again if it's going to be skipped anyway
return spec if @source_gems.include?(spec.name)
# Avoid loading the spec again if it's already the correct version
if @gemset[spec.name] && @gemset[spec.name] != spec.version
if @gemset[spec.name] && spec.version != @gemset[spec.name]
begin
return Gem::Specification.find_by_name(spec.name, "= #{@gemset[spec.name]}")
rescue Gem::LoadError
Expand Down
Binary file added solargraph-0.50.0.gem
Binary file not shown.
6 changes: 5 additions & 1 deletion solargraph.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,12 @@ Gem::Specification.new do |s|
s.add_runtime_dependency 'benchmark'
s.add_runtime_dependency 'bundler', '~> 2.0'
s.add_runtime_dependency 'diff-lcs', '~> 1.4'
s.add_runtime_dependency 'jaro_winkler', '~> 1.5'
s.add_runtime_dependency 'jaro_winkler', '~> 1.6'
s.add_runtime_dependency 'kramdown', '~> 2.3'
s.add_runtime_dependency 'kramdown-parser-gfm', '~> 1.1'
s.add_runtime_dependency 'logger', '~> 1.6'
s.add_runtime_dependency 'observer', '~> 0.1'
s.add_runtime_dependency 'ostruct', '~> 0.6'
s.add_runtime_dependency 'parser', '~> 3.0'
s.add_runtime_dependency 'rbs', '~> 2.0'
s.add_runtime_dependency 'reverse_markdown', '~> 2.0'
Expand All @@ -40,6 +43,7 @@ Gem::Specification.new do |s|

s.add_development_dependency 'pry'
s.add_development_dependency 'public_suffix', '~> 3.1'
s.add_development_dependency 'rake', '~> 13.2'
s.add_development_dependency 'rspec', '~> 3.5'
s.add_development_dependency 'simplecov', '~> 0.14'
s.add_development_dependency 'webmock', '~> 3.6'
Expand Down
2 changes: 1 addition & 1 deletion spec/api_map_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -432,7 +432,7 @@ class Sup

it "loads workspaces from directories" do
api_map = Solargraph::ApiMap.load('spec/fixtures/workspace')
expect(api_map.source_map('spec/fixtures/workspace/app.rb')).to be_a(Solargraph::SourceMap)
expect(api_map.source_map(File.absolute_path('spec/fixtures/workspace/app.rb'))).to be_a(Solargraph::SourceMap)
end

it "finds constants from included modules" do
Expand Down
6 changes: 4 additions & 2 deletions spec/language_server/message/text_document/definition_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@
host.prepare('spec/fixtures/workspace')
sleep 0.1 until host.libraries.all?(&:mapped?)
host.catalog
file_uri = Solargraph::LanguageServer::UriHelpers.file_to_uri(File.absolute_path('spec/fixtures/workspace/lib/other.rb'))
other_uri = Solargraph::LanguageServer::UriHelpers.file_to_uri(File.absolute_path('spec/fixtures/workspace/lib/thing.rb'))
message = Solargraph::LanguageServer::Message::TextDocument::Definition.new(host, {
'params' => {
'textDocument' => {
'uri' => 'file://spec/fixtures/workspace/lib/other.rb'
'uri' => file_uri
},
'position' => {
'line' => 4,
Expand All @@ -16,7 +18,7 @@
}
})
message.process
expect(message.result.first[:uri]).to eq('file://spec/fixtures/workspace/lib/thing.rb')
expect(message.result.first[:uri]).to eq(other_uri)
end

it 'finds definitions of require paths' do
Expand Down
22 changes: 22 additions & 0 deletions spec/source_map/clip_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -496,6 +496,28 @@ def bar; end
expect(clip.complete.pins.map(&:path)).to include('Par#hidden')
end

it 'infers self in @yieldself' do
source = Solargraph::Source.load_string(%(
class Par
def action; end
private
def hidden; end
end
class Foo < Par
# @yieldself [self]
def bar; end
end
Foo.new.bar do
x
end
), 'file.rb')
api_map = Solargraph::ApiMap.new
api_map.map source
clip = api_map.clip_at('file.rb', [11, 8])
expect(clip.complete.pins.map(&:path)).to include('Par#action')
expect(clip.complete.pins.map(&:path)).to include('Par#hidden')
end

it "processes @yieldpublic tags in completions" do
source = Solargraph::Source.load_string(%(
class Par
Expand Down
Loading

0 comments on commit 0e165be

Please sign in to comment.