Skip to content

DocMap logging #825

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Mar 25, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion lib/solargraph.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

Encoding.default_external = 'UTF-8'

require 'set'
require 'yard-solargraph'
require 'solargraph/yard_tags'
require 'solargraph/version'
Expand Down Expand Up @@ -42,7 +43,6 @@ class InvalidRubocopVersionError < RuntimeError; end
autoload :TypeChecker, 'solargraph/type_checker'
autoload :Environ, 'solargraph/environ'
autoload :Convention, 'solargraph/convention'
autoload :Documentor, 'solargraph/documentor'
autoload :Parser, 'solargraph/parser'
autoload :RbsMap, 'solargraph/rbs_map'
autoload :GemPins, 'solargraph/gem_pins'
Expand Down
2 changes: 0 additions & 2 deletions lib/solargraph/api_map.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
# frozen_string_literal: true

require 'rubygems'
require 'set'
require 'pathname'
require 'yard'
require 'solargraph/yard_tags'
Expand Down
1 change: 0 additions & 1 deletion lib/solargraph/api_map/store.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# frozen_string_literal: true

require 'set'

module Solargraph
class ApiMap
Expand Down
1 change: 0 additions & 1 deletion lib/solargraph/bench.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# frozen_string_literal: true

require 'set'

module Solargraph
# A container of source maps and workspace data to be cataloged in an ApiMap.
Expand Down
1 change: 0 additions & 1 deletion lib/solargraph/convention.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# frozen_string_literal: true

require 'set'

module Solargraph
# Conventions provide a way to modify an ApiMap based on expectations about
Expand Down
14 changes: 9 additions & 5 deletions lib/solargraph/doc_map.rb
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,13 @@ def try_cache gemspec
# @return [void]
def try_stdlib_map path
map = RbsMap::StdlibMap.load(path)
return unless map.resolved?

Solargraph.logger.debug "Loading stdlib pins for #{path}"
@pins.concat map.pins
if map.resolved?
Solargraph.logger.debug "Loading stdlib pins for #{path}"
@pins.concat map.pins
else
# @todo Temporarily ignoring unresolved `require 'set'`
Solargraph.logger.warn "Require path #{path} could not be resolved" unless path == 'set'
end
end

# @param gemspec [Gem::Specification]
Expand Down Expand Up @@ -114,7 +117,8 @@ def resolve_path_to_gemspec path
file = "lib/#{path}.rb"
gemspec = potential_gemspec if potential_gemspec.files.any? { |gemspec_file| file == gemspec_file }
rescue Gem::MissingSpecError
Solargraph.logger.warn "require path #{path} could not be resolved to a gem via find_by_path or guess of #{gem_name_guess}"
Solargraph.logger.debug "Require path #{path} could not be resolved to a gem via find_by_path or guess of #{gem_name_guess}"
nil
end
end
return gemspec if dependencies.empty? || gemspec.nil?
Expand Down
1 change: 0 additions & 1 deletion lib/solargraph/language_server/host.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
require 'diff/lcs'
require 'observer'
require 'securerandom'
require 'set'

module Solargraph
module LanguageServer
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# frozen_string_literal: true

require 'rubygems'

# @todo PR the RBS gem to add this
# @!parse
Expand Down
1 change: 0 additions & 1 deletion lib/solargraph/language_server/message/text_document.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ module TextDocument
autoload :DidSave, 'solargraph/language_server/message/text_document/did_save'
autoload :Hover, 'solargraph/language_server/message/text_document/hover'
autoload :SignatureHelp, 'solargraph/language_server/message/text_document/signature_help'
autoload :DiagnosticsQueue, 'solargraph/language_server/message/text_document/diagnostics_queue'
autoload :OnTypeFormatting, 'solargraph/language_server/message/text_document/on_type_formatting'
autoload :Definition, 'solargraph/language_server/message/text_document/definition'
autoload :TypeDefinition, 'solargraph/language_server/message/text_document/type_definition'
Expand Down
1 change: 0 additions & 1 deletion lib/solargraph/library.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# frozen_string_literal: true

require 'pathname'
require 'set'

module Solargraph
# A Library handles coordination between a Workspace and an ApiMap.
Expand Down
1 change: 0 additions & 1 deletion lib/solargraph/parser/parser_gem/node_processors.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ module NodeProcessors
autoload :SendNode, 'solargraph/parser/parser_gem/node_processors/send_node'
autoload :NamespaceNode, 'solargraph/parser/parser_gem/node_processors/namespace_node'
autoload :SclassNode, 'solargraph/parser/parser_gem/node_processors/sclass_node'
autoload :ModuleNode, 'solargraph/parser/parser_gem/node_processors/module_node'
autoload :IvasgnNode, 'solargraph/parser/parser_gem/node_processors/ivasgn_node'
autoload :CvasgnNode, 'solargraph/parser/parser_gem/node_processors/cvasgn_node'
autoload :LvasgnNode, 'solargraph/parser/parser_gem/node_processors/lvasgn_node'
Expand Down
1 change: 0 additions & 1 deletion lib/solargraph/pin.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ module Pin
autoload :Reference, 'solargraph/pin/reference'
autoload :Documenting, 'solargraph/pin/documenting'
autoload :Block, 'solargraph/pin/block'
autoload :Localized, 'solargraph/pin/localized'
autoload :ProxyType, 'solargraph/pin/proxy_type'
autoload :DuckMethod, 'solargraph/pin/duck_method'
autoload :Singleton, 'solargraph/pin/singleton'
Expand Down
1 change: 0 additions & 1 deletion lib/solargraph/rbs_map.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# frozen_string_literal: true

require 'rbs'
require 'set'

module Solargraph
class RbsMap
Expand Down
1 change: 0 additions & 1 deletion lib/solargraph/rbs_map/stdlib_map.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# frozen_string_literal: true

require 'rbs'
require 'set'

module Solargraph
class RbsMap
Expand Down
1 change: 0 additions & 1 deletion lib/solargraph/source.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ module Solargraph
class Source
autoload :Updater, 'solargraph/source/updater'
autoload :Change, 'solargraph/source/change'
autoload :Mapper, 'solargraph/source/mapper'
autoload :EncodingFixes, 'solargraph/source/encoding_fixes'
autoload :Cursor, 'solargraph/source/cursor'
autoload :Chain, 'solargraph/source/chain'
Expand Down
1 change: 0 additions & 1 deletion lib/solargraph/source_map.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

require 'yard'
require 'solargraph/yard_tags'
require 'set'

module Solargraph
# An index of pins and other ApiMap-related data for a Source.
Expand Down
1 change: 0 additions & 1 deletion lib/solargraph/workspace.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# frozen_string_literal: true

require 'open3'
require 'rubygems'
require 'json'

module Solargraph
Expand Down
2 changes: 0 additions & 2 deletions lib/solargraph/yard_map.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

require 'yard'
require 'solargraph/yard_tags'
require 'rubygems/package'
require 'set'

module Solargraph
# The YardMap provides access to YARD documentation for the Ruby core, the
Expand Down
8 changes: 8 additions & 0 deletions spec/doc_map_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,12 @@
doc_map = Solargraph::DocMap.new(['not_a_gem'], [gemspec])
expect(doc_map.uncached_gemspecs).to eq([gemspec])
end

# @todo This test fails on CI for some reason
xit 'does not warn for redundant requires' do
# Requiring 'set' is unnecessary because it's already included in core. It
# might make sense to log redundant requires, but a warning is overkill.
expect(Solargraph.logger).not_to receive(:warn)
Solargraph::DocMap.new(['set'], [])
end
end
67 changes: 32 additions & 35 deletions spec/pin/parameter_spec.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
describe Solargraph::Pin::Parameter do
it "detects block parameter return types from @yieldparam tags" do
it 'detects block parameter return types from @yieldparam tags' do
api_map = Solargraph::ApiMap.new
source = Solargraph::Source.load_string(%(
# @yieldparam [Array]
Expand Down Expand Up @@ -62,7 +62,7 @@ def baz
expect(clip.infer.tag).to eq('generic')
end

it "detects block parameter return types from core methods" do
it 'detects block parameter return types from core methods' do
api_map = Solargraph::ApiMap.new
source = Solargraph::Source.load_string(%(
String.new.split.each do |str|
Expand All @@ -74,7 +74,7 @@ def baz
expect(clip.infer.tag).to eq('String')
end

it "detects block parameter return self from core methods" do
it 'detects block parameter return self from core methods' do
api_map = Solargraph::ApiMap.new
source = Solargraph::Source.load_string(%(
String.new.tap do |str|
Expand All @@ -86,9 +86,8 @@ def baz
expect(clip.infer.tag).to eq('String')
end

it "gets return types from param type tags" do
it 'gets return types from param type tags' do
map = Solargraph::SourceMap.load_string(%(
require 'set'
# @yieldparam [Array]
def yielder
Expand All @@ -102,9 +101,8 @@ def yielder
expect(map.locals.first.return_type.tag).to eq('Set')
end

it "gets return types from yieldreturn type tags" do
it 'gets return types from yieldreturn type tags' do
map = Solargraph::SourceMap.load_string(%(
require 'set'
# @yieldparam [Array]
# @yieldreturn [Integer]
Expand All @@ -118,16 +116,15 @@ def yielder(&blk)
123
end
))
expect(map.pins.size).to eq(4)
expect(map.pins.map(&:class)).
to eq([
Solargraph::Pin::Namespace,
Solargraph::Pin::Reference::Require,
Solargraph::Pin::Method,
Solargraph::Pin::Block
])

method = map.pins[2]
expect(map.pins.size).to eq(3)
expect(map.pins.map(&:class))
.to eq([
Solargraph::Pin::Namespace,
Solargraph::Pin::Method,
Solargraph::Pin::Block
])

method = map.pins[1]
expect(method.signatures.size).to eq(1)

method_signature = method.signatures.first
Expand All @@ -143,26 +140,26 @@ def yielder(&blk)
expect(method.return_type.tag).to eq('Integer')

expect(map.locals.map(&:to_s)).to eq(['blk Proc', 'things Set'])
expect(map.locals.map(&:return_type).map(&:to_s)).to eq(['Proc', 'Set'])
expect(map.locals.map(&:decl)).to eq([:blockarg, :arg])
expect(map.locals.map(&:return_type).map(&:to_s)).to eq(%w[Proc Set])
expect(map.locals.map(&:decl)).to eq(%i[blockarg arg])
end

it "detects near equivalents" do
it 'detects near equivalents' do
map1 = Solargraph::SourceMap.load_string(%(
strings.each do |foo|
end
))
pin1 = map1.locals.select{|p| p.name == 'foo'}.first
pin1 = map1.locals.select { |p| p.name == 'foo' }.first
map2 = Solargraph::SourceMap.load_string(%(
# A minor comment change
strings.each do |foo|
end
))
pin2 = map2.locals.select{|p| p.name == 'foo'}.first
pin2 = map2.locals.select { |p| p.name == 'foo' }.first
expect(pin1.nearly?(pin2)).to be(true)
end

it "infers fully qualified namespaces" do
it 'infers fully qualified namespaces' do
source = Solargraph::Source.load_string(%(
class Foo
class Bar
Expand All @@ -175,20 +172,20 @@ def baz; end
), 'test.rb')
api_map = Solargraph::ApiMap.new
api_map.map source
pin = api_map.source_map('test.rb').locals.select{|p| p.name == 'par'}.first
pin = api_map.source_map('test.rb').locals.select { |p| p.name == 'par' }.first
type = pin.typify(api_map)
expect(type.namespace).to eq('Foo::Bar')
end

it "merges near equivalents" do
it 'merges near equivalents' do
loc = Solargraph::Location.new('test.rb', Solargraph::Range.from_to(0, 0, 0, 0))
block = Solargraph::Pin::Block.new(location: loc, name: 'Foo')
pin1 = Solargraph::Pin::Parameter.new(closure: block, name: 'bar')
pin2 = Solargraph::Pin::Parameter.new(closure: block, name: 'bar', comments: 'a comment')
expect(pin1.try_merge!(pin2)).to be(true)
end

it "does not merge block parameters from different blocks" do
it 'does not merge block parameters from different blocks' do
loc = Solargraph::Location.new('test.rb', Solargraph::Range.from_to(0, 0, 0, 0))
block1 = Solargraph::Pin::Block.new(location: loc, name: 'Foo')
block2 = Solargraph::Pin::Block.new(location: loc, name: 'Bar')
Expand All @@ -197,20 +194,20 @@ def baz; end
expect(pin1.try_merge!(pin2)).to be(false)
end

it "infers undefined types by default" do
it 'infers undefined types by default' do
source = Solargraph::Source.load_string(%(
func do |foo|
end
), 'test.rb')
api_map = Solargraph::ApiMap.new
api_map.map source
pin = api_map.source_map('test.rb').locals.select{|p| p.is_a?(Solargraph::Pin::Parameter)}.first
pin = api_map.source_map('test.rb').locals.select { |p| p.is_a?(Solargraph::Pin::Parameter) }.first
# expect(pin.infer(api_map)).to be_undefined
expect(pin.typify(api_map)).to be_undefined
expect(pin.probe(api_map)).to be_undefined
end

it "detects method parameter return types from @param tags" do
it 'detects method parameter return types from @param tags' do
source = Solargraph::Source.load_string(%(
# @param bar [String]
def foo bar
Expand All @@ -222,22 +219,22 @@ def foo bar
expect(map.locals.first.return_type.tag).to eq('String')
end

it "tracks its index" do
it 'tracks its index' do
smap = Solargraph::SourceMap.load_string(%(
def foo bar
end
))
pin = smap.locals.select{|p| p.name == 'bar'}.first
pin = smap.locals.select { |p| p.name == 'bar' }.first
expect(pin.index).to eq(0)
end

it "detects unnamed @param tag types" do
it 'detects unnamed @param tag types' do
smap = Solargraph::SourceMap.load_string(%(
# @param [String]
def foo bar
end
))
pin = smap.locals.select{|p| p.name == 'bar'}.first
pin = smap.locals.select { |p| p.name == 'bar' }.first
expect(pin.return_type.tag).to eq('String')
end

Expand Down Expand Up @@ -338,7 +335,7 @@ def bar baz
expect(pin.documentation).not_to include('The bar method')
end

it "typifies from generic yield params" do
it 'typifies from generic yield params' do
# This test depends on RBS definitions for Array#each with generic yield params
source = Solargraph::Source.load_string(%(
# @return [Array<String>]
Expand All @@ -357,7 +354,7 @@ def use_string str
), 'test.rb')
api_map = Solargraph::ApiMap.new
api_map.map source
pin = api_map.get_path_pins('Array#each').first
api_map.get_path_pins('Array#each').first
clip = api_map.clip_at('test.rb', [10, 23])
pin = clip.define.first
type = pin.typify(api_map)
Expand Down
1 change: 0 additions & 1 deletion spec/source_map/mapper_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -607,7 +607,6 @@ def bar; end
map = Solargraph::SourceMap.load_string(%(
require 'set'
))
# expect(map.requires.map(&:name)).to include('set')
pin = map.pins.select{|p| p.is_a?(Solargraph::Pin::Reference::Require)}.first
expect(pin.name).to eq('set')
end
Expand Down