From 3f0f8f6f953e7ba68bb6530335494fc155a9f093 Mon Sep 17 00:00:00 2001 From: Fred Snyder Date: Fri, 23 Feb 2024 13:33:16 -0500 Subject: [PATCH 01/12] Remove debug output --- spec/type_checker/levels/strict_spec.rb | 2 -- 1 file changed, 2 deletions(-) diff --git a/spec/type_checker/levels/strict_spec.rb b/spec/type_checker/levels/strict_spec.rb index 22bbd3631..5e8c801ae 100644 --- a/spec/type_checker/levels/strict_spec.rb +++ b/spec/type_checker/levels/strict_spec.rb @@ -300,7 +300,6 @@ def bar baz h['foo'] = 'bar' h[100] = [] )) - puts checker.problems.map(&:message) expect(checker.problems).to be_empty end @@ -473,7 +472,6 @@ def bar alias baz bar end )) - puts checker.problems.map(&:message) expect(checker.problems).to be_empty end From e781533af1b98cf287ccb5d9fb57e0f08104227e Mon Sep 17 00:00:00 2001 From: Jane Davis <61095764+janie314@users.noreply.github.com> Date: Tue, 7 Jan 2025 04:54:49 -0600 Subject: [PATCH 02/12] Update test matrix versions (#736) Co-authored-by: 12ball --- .github/workflows/rspec.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/rspec.yml b/.github/workflows/rspec.yml index cbc69c804..487ab3bef 100644 --- a/.github/workflows/rspec.yml +++ b/.github/workflows/rspec.yml @@ -22,7 +22,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - ruby-version: ['2.6', '2.7', '3.0', '3.1'] + ruby-version: ['2.6', '2.7', '3.3', '3.4', 'HEAD'] steps: - uses: actions/checkout@v3 From d0934b8fbd8173aee8a52af3b7f94ff24078dfbc Mon Sep 17 00:00:00 2001 From: Jane Davis <61095764+janie314@users.noreply.github.com> Date: Tue, 7 Jan 2025 04:55:42 -0600 Subject: [PATCH 03/12] Ruby 3.4.1 compatability (#735) * Add logger and observer as explicit dependencies * Add explicit rake dependency * Add nil handling to node_range method * Add explicit ostruct dependency * Update deprecated JaroWinkler distance method --------- Co-authored-by: 12ball --- lib/solargraph/parser/rubyvm/class_methods.rb | 4 ++++ lib/solargraph/pin/search.rb | 2 +- solargraph.gemspec | 4 ++++ 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/lib/solargraph/parser/rubyvm/class_methods.rb b/lib/solargraph/parser/rubyvm/class_methods.rb index a208f4e8e..2533eb79e 100644 --- a/lib/solargraph/parser/rubyvm/class_methods.rb +++ b/lib/solargraph/parser/rubyvm/class_methods.rb @@ -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 diff --git a/lib/solargraph/pin/search.rb b/lib/solargraph/pin/search.rb index 5564fac7c..da1de116d 100644 --- a/lib/solargraph/pin/search.rb +++ b/lib/solargraph/pin/search.rb @@ -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 diff --git a/solargraph.gemspec b/solargraph.gemspec index 7be8dcb73..31a80b4c9 100755 --- a/solargraph.gemspec +++ b/solargraph.gemspec @@ -29,8 +29,11 @@ Gem::Specification.new do |s| s.add_runtime_dependency 'diff-lcs', '~> 1.4' s.add_runtime_dependency 'e2mmap' s.add_runtime_dependency 'jaro_winkler', '~> 1.5' + s.add_runtime_dependency 'logger', '~> 1.6' s.add_runtime_dependency 'kramdown', '~> 2.3' s.add_runtime_dependency 'kramdown-parser-gfm', '~> 1.1' + 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' @@ -41,6 +44,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' From d8e70dccc14f262cc837da27411b2a9eb2ce1bd4 Mon Sep 17 00:00:00 2001 From: Fred Snyder Date: Tue, 7 Jan 2025 06:01:22 -0500 Subject: [PATCH 04/12] Remove HEAD from matrix --- .github/workflows/rspec.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/rspec.yml b/.github/workflows/rspec.yml index 487ab3bef..9306bc07d 100644 --- a/.github/workflows/rspec.yml +++ b/.github/workflows/rspec.yml @@ -22,7 +22,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - ruby-version: ['2.6', '2.7', '3.3', '3.4', 'HEAD'] + ruby-version: ['2.6', '2.7', '3.3', '3.4'] steps: - uses: actions/checkout@v3 From b200695e3f43903a6ec3dade8a90c22db03b4b41 Mon Sep 17 00:00:00 2001 From: Stephen Sugden Date: Tue, 7 Jan 2025 12:26:52 +0100 Subject: [PATCH 05/12] Fix spec version comparison (#661) The return type of spec.version is a Gem::Version, which can be compared to a string, but not the other way around. --- lib/solargraph/yard_map.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/solargraph/yard_map.rb b/lib/solargraph/yard_map.rb index 89208a2bb..04be84aac 100755 --- a/lib/solargraph/yard_map.rb +++ b/lib/solargraph/yard_map.rb @@ -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 From b64bf5bd2084369aa6e72d222f95a384b17e0ecd Mon Sep 17 00:00:00 2001 From: Geremia Taglialatela Date: Tue, 7 Jan 2025 12:31:51 +0100 Subject: [PATCH 06/12] Bump jaro_winkler dependency to remove deprecation (#731) Require 'jaro_winkler', '~> 1.6', in order to use `JaroWinkler.similarity` instead of `JaroWinkler.distance` to fix a deprecation message while running specs. Co-authored-by: Fred Snyder --- solargraph.gemspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/solargraph.gemspec b/solargraph.gemspec index 31a80b4c9..25dc02db0 100755 --- a/solargraph.gemspec +++ b/solargraph.gemspec @@ -28,7 +28,7 @@ Gem::Specification.new do |s| s.add_runtime_dependency 'bundler', '~> 2.0' s.add_runtime_dependency 'diff-lcs', '~> 1.4' s.add_runtime_dependency 'e2mmap' - s.add_runtime_dependency 'jaro_winkler', '~> 1.5' + s.add_runtime_dependency 'jaro_winkler', '~> 1.6' s.add_runtime_dependency 'logger', '~> 1.6' s.add_runtime_dependency 'kramdown', '~> 2.3' s.add_runtime_dependency 'kramdown-parser-gfm', '~> 1.1' From 3bbd03f2e8bf75fe3d8bb7702ca554586532d1c9 Mon Sep 17 00:00:00 2001 From: Fred Snyder Date: Tue, 7 Jan 2025 06:36:57 -0500 Subject: [PATCH 07/12] Order dependencies --- solargraph.gemspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/solargraph.gemspec b/solargraph.gemspec index 25dc02db0..b6724500b 100755 --- a/solargraph.gemspec +++ b/solargraph.gemspec @@ -29,9 +29,9 @@ Gem::Specification.new do |s| s.add_runtime_dependency 'diff-lcs', '~> 1.4' s.add_runtime_dependency 'e2mmap' s.add_runtime_dependency 'jaro_winkler', '~> 1.6' - s.add_runtime_dependency 'logger', '~> 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' From 0d74c1187097c8f228e3a678194c9bb71a270b5b Mon Sep 17 00:00:00 2001 From: Fred Snyder Date: Wed, 8 Jan 2025 06:26:05 -0500 Subject: [PATCH 08/12] Matrix versions --- .github/workflows/rspec.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/rspec.yml b/.github/workflows/rspec.yml index 9306bc07d..c3fdce6b8 100644 --- a/.github/workflows/rspec.yml +++ b/.github/workflows/rspec.yml @@ -22,7 +22,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - ruby-version: ['2.6', '2.7', '3.3', '3.4'] + ruby-version: ['2.6', '2.7', '3.0', '3.3', '3.4', 'head'] steps: - uses: actions/checkout@v3 From 9e6ae27929ce4aeeab1f7a665b5341ab94d819d5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lek=C3=AB=20Mula?= Date: Wed, 8 Jan 2025 12:31:52 +0100 Subject: [PATCH 09/12] Remove Rspec convention (#716) Replaced by https://github.com/lekemula/solargraph-rspec plugin --- lib/solargraph/convention.rb | 2 -- lib/solargraph/convention/rspec.rb | 30 ------------------------------ 2 files changed, 32 deletions(-) delete mode 100644 lib/solargraph/convention/rspec.rb diff --git a/lib/solargraph/convention.rb b/lib/solargraph/convention.rb index db0faa7cb..056d4013d 100644 --- a/lib/solargraph/convention.rb +++ b/lib/solargraph/convention.rb @@ -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' @@ -43,7 +42,6 @@ def self.for_global(yard_map) register Gemfile register Gemspec - register Rspec register Rakefile end end diff --git a/lib/solargraph/convention/rspec.rb b/lib/solargraph/convention/rspec.rb deleted file mode 100644 index 426e541a7..000000000 --- a/lib/solargraph/convention/rspec.rb +++ /dev/null @@ -1,30 +0,0 @@ -# frozen_string_literal: true - -module Solargraph - module Convention - class Rspec < Base - def local source_map - return EMPTY_ENVIRON unless File.basename(source_map.filename) =~ /_spec\.rb$/ - @environ ||= Environ.new( - requires: ['rspec'], - domains: ['RSpec::Matchers', 'RSpec::ExpectationGroups'], - pins: [ - # This override is necessary due to an erroneous @return tag in - # rspec's YARD documentation. - # @todo The return types have been fixed (https://github.com/rspec/rspec-expectations/pull/1121) - Solargraph::Pin::Reference::Override.method_return('RSpec::Matchers#expect', 'RSpec::Expectations::ExpectationTarget') - ].concat(extras) - ) - end - - private - - def extras - @@extras ||= SourceMap.load_string(%( - def describe(*args); end - def it(*args); end - )).pins - end - end - end -end From 9440f1362d50a2c8530ecc8bff42540cc784ec36 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lek=C3=AB=20Mula?= Date: Wed, 8 Jan 2025 12:35:05 +0100 Subject: [PATCH 10/12] Include convention pins in document_symbols (#724) --- .../message/text_document/document_symbol.rb | 5 ++- lib/solargraph/source_map.rb | 17 +++++++- spec/source_map_spec.rb | 43 +++++++++++++++++++ 3 files changed, 62 insertions(+), 3 deletions(-) diff --git a/lib/solargraph/language_server/message/text_document/document_symbol.rb b/lib/solargraph/language_server/message/text_document/document_symbol.rb index 670b99469..19a64cf93 100644 --- a/lib/solargraph/language_server/message/text_document/document_symbol.rb +++ b/lib/solargraph/language_server/message/text_document/document_symbol.rb @@ -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, @@ -17,7 +19,8 @@ def process deprecated: pin.deprecated? } result - end + end.compact + set_result info end end diff --git a/lib/solargraph/source_map.rb b/lib/solargraph/source_map.rb index 7c7ff9f6a..60cba47c1 100644 --- a/lib/solargraph/source_map.rb +++ b/lib/solargraph/source_map.rb @@ -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 @@ -65,11 +66,12 @@ def environ @environ ||= Environ.new end + # all pins except Solargraph::Pin::Reference::Reference # @return [Array] 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] @@ -159,6 +161,17 @@ def map source private + # @return [Array] + 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] diff --git a/spec/source_map_spec.rb b/spec/source_map_spec.rb index 8e623296b..db9789c6b 100644 --- a/spec/source_map_spec.rb +++ b/spec/source_map_spec.rb @@ -20,6 +20,49 @@ def baz_qux; end expect(map.query_symbols("bazqux")).to eq(map.document_symbols.select{ |pin_namespace| pin_namespace.name == "baz_qux" }) end + it 'returns all pins, except for references as document symbols' do + map = Solargraph::SourceMap.load_string(%( + class FooBar + require 'foo' + include SomeModule + extend SomeOtherModule + + def baz_qux; end + end + ), 'test.rb') + + expect(map.document_symbols.map(&:path)).to eq(['FooBar', 'FooBar#baz_qux']) + expect(map.document_symbols.map(&:class)).not_to include(an_instance_of(Solargraph::Pin::Reference)) + end + + it 'includes convention pins in document symbols' do + dummy_convention = Class.new(Solargraph::Convention::Base) do + def local(source_map) + source_map.document_symbols # call memoized method + + Solargraph::Environ.new( + pins: [ + Solargraph::Pin::Method.new( + closure: Solargraph::Pin::Namespace.new(name: 'FooBar', type: :class), + name: 'baz_convention', + scope: :instance + ) + ] + ) + end + end + + Solargraph::Convention.register dummy_convention + + map = Solargraph::SourceMap.load_string(%( + class FooBar + def baz_qux; end + end + ), 'test.rb') + + expect(map.document_symbols.map(&:path)).to include('FooBar#baz_convention') + end + it "locates block pins" do map = Solargraph::SourceMap.load_string(%( class Foo From 188577fa5bb339572498ea364d992dd792df2761 Mon Sep 17 00:00:00 2001 From: Earlopain <14981592+Earlopain@users.noreply.github.com> Date: Wed, 8 Jan 2025 12:37:44 +0100 Subject: [PATCH 11/12] Remove dependency on e2mmap (#699) Co-authored-by: Fred Snyder --- solargraph.gemspec | 1 - 1 file changed, 1 deletion(-) diff --git a/solargraph.gemspec b/solargraph.gemspec index b6724500b..938720dc0 100755 --- a/solargraph.gemspec +++ b/solargraph.gemspec @@ -27,7 +27,6 @@ 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 'e2mmap' s.add_runtime_dependency 'jaro_winkler', '~> 1.6' s.add_runtime_dependency 'kramdown', '~> 2.3' s.add_runtime_dependency 'kramdown-parser-gfm', '~> 1.1' From 74fece0a2a9405cbd9758a2a5594c0d08737cc76 Mon Sep 17 00:00:00 2001 From: Takeshi KOMIYA Date: Wed, 8 Jan 2025 20:39:49 +0900 Subject: [PATCH 12/12] deps: Update rbs to 3.0 (#662) * deps: Update rbs to 3.0 * spec: Use fileutils for testing Solargraph::Rbs::StdlibMap The "set" has been merged into the Ruby Core and RBS has been drop support since v3.0. So current spec implementation will not work with RBS-3.x. --- lib/solargraph/rbs_map/conversions.rb | 12 ++++++------ solargraph.gemspec | 2 +- spec/rbs_map/stdlib_map_spec.rb | 4 ++-- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/lib/solargraph/rbs_map/conversions.rb b/lib/solargraph/rbs_map/conversions.rb index ecd5322f2..e52c94923 100644 --- a/lib/solargraph/rbs_map/conversions.rb +++ b/lib/solargraph/rbs_map/conversions.rb @@ -40,7 +40,7 @@ def convert_decl_to_pin decl, closure when RBS::AST::Declarations::Interface # STDERR.puts "Skipping interface #{decl.name.relative!}" interface_decl_to_pin decl - when RBS::AST::Declarations::Alias + when RBS::AST::Declarations::TypeAlias type_aliases[decl.name.to_s] = decl when RBS::AST::Declarations::Module module_decl_to_pin decl @@ -222,12 +222,12 @@ def method_def_to_pin decl, closure # @param decl [RBS::AST::Members::MethodDefinition] # @param pin [Pin::Method] def method_def_to_sigs decl, pin - decl.types.map do |type| - parameters, return_type = parts_of_function(type, pin) - block = if type.block - Pin::Signature.new(*parts_of_function(type.block, pin)) + decl.overloads.map do |overload| + parameters, return_type = parts_of_function(overload.method_type, pin) + block = if overload.method_type.block + Pin::Signature.new(*parts_of_function(overload.method_type.block, pin)) end - return_type = ComplexType.try_parse(method_type_to_tag(type)) + return_type = ComplexType.try_parse(method_type_to_tag(overload.method_type)) Pin::Signature.new(parameters, return_type, block) end end diff --git a/solargraph.gemspec b/solargraph.gemspec index 938720dc0..5d1c31b57 100755 --- a/solargraph.gemspec +++ b/solargraph.gemspec @@ -34,7 +34,7 @@ Gem::Specification.new do |s| 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 'rbs', '~> 3.0' s.add_runtime_dependency 'reverse_markdown', '~> 2.0' s.add_runtime_dependency 'rubocop', '~> 1.38' s.add_runtime_dependency 'thor', '~> 1.0' diff --git a/spec/rbs_map/stdlib_map_spec.rb b/spec/rbs_map/stdlib_map_spec.rb index 80734530a..8a3347653 100644 --- a/spec/rbs_map/stdlib_map_spec.rb +++ b/spec/rbs_map/stdlib_map_spec.rb @@ -1,7 +1,7 @@ describe Solargraph::RbsMap::StdlibMap do it "finds stdlib require paths" do - rbs_map = Solargraph::RbsMap::StdlibMap.load('set') - pin = rbs_map.path_pin('Set#add') + rbs_map = Solargraph::RbsMap::StdlibMap.load('fileutils') + pin = rbs_map.path_pin('FileUtils#chdir') expect(pin).to be end