solargraph 0.42.1 → 0.42.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1099281670bd5cacd480624f66b36d7ce8fb6b69b4486f080d0c0d6436c0f36c
4
- data.tar.gz: 4b1e028bc357204b953c31916845a7f12caefc07d733dc90cfb5bc142401f2d4
3
+ metadata.gz: d4cd4acd35a7ce8242976cdd2b23d583bbd01392e3d79a16e3b4e181443e4858
4
+ data.tar.gz: 4cb4f369d97681a43d24a8fc3de14a454721c4334426655e23fffafceeb242c7
5
5
  SHA512:
6
- metadata.gz: 771c40ddff0a11757d1e9c4487802afc9f5b992840383f525643957d92516e735dc7328a8d23ed1ff4f0e55ceb09e3792eb24818758e4b217927bf4ba9708b5a
7
- data.tar.gz: 948101863fc7f3f167dee00139f07ccdf5711afd12125aa2a18b708ed4ba6edaffbc7ba0c1a7a7dd09ad51460a0827546841cf2dbcd223198247fd86d8b0841b
6
+ metadata.gz: 5918eb0b9797ed3bed1fe97a702761889b4fb5b8280de655820d8a4319eefd651f4958e420b32468aac2ab197f657b8cb1386029654dcbd9b3a30bbdd2ca521b
7
+ data.tar.gz: 649a461beb8b23b69ae40bb347389602e20b42d0a689752d805beb2c08000a863c24d9e45b39d00ee544d37802be0762d9933a6d4e27b2617249d1443ca582f4
data/CHANGELOG.md CHANGED
@@ -1,3 +1,9 @@
1
+ ## 0.42.2 - June 14, 2021
2
+ - Improve download-core command output
3
+ - Ignore missing requests to client responses
4
+ - Add automatically required gems to YardMap
5
+ - Use closures to identify local variables
6
+
1
7
  ## 0.42.1 - June 11, 2021
2
8
  - YardMap#change sets new directory (#445)
3
9
 
@@ -9,7 +9,7 @@ module Solargraph
9
9
  # @param directory [String]
10
10
  # @return [Hash]
11
11
  def require_from_bundle directory
12
- @require_from_bundle ||= begin
12
+ begin
13
13
  Solargraph.logger.info "Loading gems for bundler/require"
14
14
  Documentor.specs_from_bundle(directory)
15
15
  rescue BundleNotFoundError => e
@@ -17,11 +17,6 @@ module Solargraph
17
17
  {}
18
18
  end
19
19
  end
20
-
21
- # @return [void]
22
- def reset_require_from_bundle
23
- @require_from_bundle = nil
24
- end
25
20
  end
26
21
  end
27
22
  end
@@ -3,7 +3,7 @@
3
3
  require 'set'
4
4
 
5
5
  module Solargraph
6
- # A container of source maps and gem specs to be cataloged in an ApiMap.
6
+ # A container of source maps and workspace data to be cataloged in an ApiMap.
7
7
  #
8
8
  class Bench
9
9
  # @return [Set<SourceMap>]
@@ -31,7 +31,7 @@ module Solargraph
31
31
  @cancel = []
32
32
  @buffer = String.new
33
33
  @stopped = true
34
- @next_request_id = 0
34
+ @next_request_id = 1
35
35
  @dynamic_capabilities = Set.new
36
36
  @registered_capabilities = Set.new
37
37
  end
@@ -113,6 +113,7 @@ module Solargraph
113
113
  requests.delete request['id']
114
114
  else
115
115
  logger.warn "Discarding client response to unrecognized message #{request['id']}"
116
+ nil
116
117
  end
117
118
  else
118
119
  logger.warn "Invalid message received."
@@ -42,9 +42,7 @@ module Solargraph
42
42
  # @return [void]
43
43
  def process request
44
44
  message = @host.receive(request)
45
- message.send_response
46
- # tmp = @host.flush
47
- # write tmp unless tmp.empty?
45
+ message && message.send_response
48
46
  end
49
47
 
50
48
  def shutdown
@@ -46,7 +46,7 @@ module Solargraph
46
46
  # @return [void]
47
47
  def attach source
48
48
  mutex.synchronize do
49
- if @current && @current.filename != source.filename && source_map_hash.key?(@current.filename) && !workspace.has_file?(@current.filename)
49
+ if @current && (!source || @current.filename != source.filename) && source_map_hash.key?(@current.filename) && !workspace.has_file?(@current.filename)
50
50
  source_map_hash.delete @current.filename
51
51
  source_map_external_require_hash.delete @current.filename
52
52
  @external_requires = nil
@@ -511,6 +511,7 @@ module Solargraph
511
511
  end
512
512
 
513
513
  def maybe_map source
514
+ return unless source
514
515
  if source_map_hash.key?(source.filename)
515
516
  return if source_map_hash[source.filename].code == source.code &&
516
517
  source_map_hash[source.filename].source.synchronized? &&
@@ -3,7 +3,8 @@
3
3
  module Solargraph
4
4
  module Pin
5
5
  class LocalVariable < BaseVariable
6
- include Localized
6
+ # @return [Range]
7
+ attr_reader :presence
7
8
 
8
9
  def initialize assignment: nil, presence: nil, **splat
9
10
  super(**splat)
@@ -16,6 +17,51 @@ module Solargraph
16
17
  @presence = pin.presence
17
18
  true
18
19
  end
20
+
21
+ # @param other [Pin::Base] The caller's block
22
+ # @param position [Position, Array(Integer, Integer)] The caller's position
23
+ # @return [Boolean]
24
+ def visible_from?(other, position)
25
+ position = Position.normalize(position)
26
+ other.filename == filename &&
27
+ match_tags(other.full_context.tag, full_context.tag) &&
28
+ (other == closure ||
29
+ (closure.location.range.contain?(other.location.range.start) && closure.location.range.contain?(other.location.range.ending))
30
+ ) &&
31
+ presence.contain?(position)
32
+ end
33
+
34
+ # @param other_loc [Location]
35
+ def visible_at?(other_closure, other_loc)
36
+ return true if location.filename == other_loc.filename &&
37
+ presence.include?(other_loc.range.start) &&
38
+ match_named_closure(other_closure, closure)
39
+ end
40
+
41
+ private
42
+
43
+ # @param tag1 [String]
44
+ # @param tag2 [String]
45
+ # @return [Boolean]
46
+ def match_tags tag1, tag2
47
+ # @todo This is an unfortunate hack made necessary by a discrepancy in
48
+ # how tags indicate the root namespace. The long-term solution is to
49
+ # standardize it, whether it's `Class<>`, an empty string, or
50
+ # something else.
51
+ tag1 == tag2 ||
52
+ (['', 'Class<>'].include?(tag1) && ['', 'Class<>'].include?(tag2))
53
+ end
54
+
55
+ def match_named_closure needle, haystack
56
+ return true if needle == haystack
57
+ cursor = haystack
58
+ until cursor.nil?
59
+ return true if needle.path == cursor.path
60
+ return false if cursor.path && !cursor.path.empty?
61
+ cursor = cursor.closure
62
+ end
63
+ false
64
+ end
19
65
  end
20
66
  end
21
67
  end
@@ -76,12 +76,12 @@ module Solargraph
76
76
  ver = version || Solargraph::YardMap::CoreDocs.best_download
77
77
  if RUBY_VERSION != ver
78
78
  puts "Documentation for #{RUBY_VERSION} is not available. Reverting to closest match..."
79
- else
80
- puts "Downloading docs for #{ver}..."
81
79
  end
80
+ puts "Downloading docs for #{ver}..."
82
81
  Solargraph::YardMap::CoreDocs.download ver
83
82
  # Clear cached documentation if it exists
84
83
  FileUtils.rm_rf Dir.glob(File.join(Solargraph::YardMap::CoreDocs.cache_dir, ver, '*.ser'))
84
+ puts "Download complete."
85
85
  rescue ArgumentError => e
86
86
  STDERR.puts "ERROR: #{e.message}"
87
87
  STDERR.puts "Run `solargraph available-cores` for a list."
@@ -77,6 +77,7 @@ module Solargraph
77
77
  end
78
78
  if match
79
79
  type = extra_return_type(ol, context)
80
+ break if type
80
81
  type = ComplexType.try_parse(*ol.tag(:return).types).self_to(context.to_s).qualify(api_map, context.namespace) if ol.has_tag?(:return) && ol.tag(:return).types && !ol.tag(:return).types.empty? && (type.nil? || type.undefined?)
81
82
  type ||= ComplexType::UNDEFINED
82
83
  end
@@ -170,8 +171,8 @@ module Solargraph
170
171
  # @param context [ComplexType]
171
172
  # @return [ComplexType]
172
173
  def extra_return_type docstring, context
173
- if docstring.has_tag?(:return_single_parameter) && context.subtypes.one?
174
- return context.subtypes.first
174
+ if docstring.has_tag?(:return_single_parameter) #&& context.subtypes.one?
175
+ return context.subtypes.first || ComplexType::UNDEFINED
175
176
  elsif docstring.has_tag?(:return_value_parameter) && context.value_types.one?
176
177
  return context.value_types.first
177
178
  end
@@ -131,7 +131,8 @@ module Solargraph
131
131
  # @return [Array<Pin::LocalVariable>]
132
132
  def locals_at(location)
133
133
  return [] if location.filename != filename
134
- locals.select { |pin| pin.visible_at?(location) }
134
+ closure = locate_named_path_pin(location.range.start.line, location.range.start.character)
135
+ locals.select { |pin| pin.visible_at?(closure, location) }
135
136
  end
136
137
 
137
138
  class << self
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Solargraph
4
- VERSION = '0.42.1'
4
+ VERSION = '0.42.2'
5
5
  end
@@ -156,12 +156,12 @@ module Solargraph
156
156
  @base_required ||= Set.new
157
157
  end
158
158
 
159
- private
160
-
161
159
  def directory
162
160
  @directory ||= ''
163
161
  end
164
162
 
163
+ private
164
+
165
165
  # @return [YardMap::Cache]
166
166
  def cache
167
167
  @cache ||= YardMap::Cache.new
@@ -190,11 +190,8 @@ module Solargraph
190
190
 
191
191
  # @return [void]
192
192
  def process_requires
193
- @gemset = if required.include?('bundler/require')
194
- require_from_bundle(directory)
195
- else
196
- {}
197
- end
193
+ @gemset = process_gemsets
194
+ required.merge @gemset.keys if required.include?('bundler/require')
198
195
  pins.replace core_pins
199
196
  unresolved_requires.clear
200
197
  stdlib_pins.clear
@@ -254,6 +251,11 @@ module Solargraph
254
251
  pins.concat environ.pins
255
252
  end
256
253
 
254
+ def process_gemsets
255
+ return {} if directory.empty? || !File.file?(File.join(directory, 'Gemfile'))
256
+ require_from_bundle(directory)
257
+ end
258
+
257
259
  # @param spec [Gem::Specification]
258
260
  # @return [void]
259
261
  def add_gem_dependencies spec
@@ -82,6 +82,18 @@ module Solargraph
82
82
  Override.method_return('Class#allocate', 'self'),
83
83
  Override.method_return('Class.allocate', 'Class<Object>'),
84
84
 
85
+ Override.from_comment('Enumerable#detect', %(
86
+ @overload detect(&block)
87
+ @return_single_parameter
88
+ @overload detect()
89
+ @return [Enumerator]
90
+ )),
91
+ Override.from_comment('Enumerable#find', %(
92
+ @overload find(&block)
93
+ @return_single_parameter
94
+ @overload find()
95
+ @return [Enumerator]
96
+ )),
85
97
  Override.method_return('Enumerable#select', 'self'),
86
98
 
87
99
  Override.method_return('File.absolute_path', 'String'),
@@ -111,7 +123,12 @@ module Solargraph
111
123
  @param y [Numeric]
112
124
  @return [Numeric]
113
125
  )),
114
- Override.method_return('Integer#times', 'Enumerator', delete: [:overload]),
126
+ Override.from_comment('Integer#times', %(
127
+ @overload times(&block)
128
+ @return [Integer]
129
+ @overload times()
130
+ @return [Enumerator]
131
+ )),
115
132
 
116
133
  Override.method_return('Kernel#puts', 'nil'),
117
134
 
data/solargraph.gemspec CHANGED
@@ -19,7 +19,7 @@ Gem::Specification.new do |s|
19
19
 
20
20
  s.required_ruby_version = '>= 2.4'
21
21
 
22
- s.add_runtime_dependency 'backport', '~> 1.1'
22
+ s.add_runtime_dependency 'backport', '~> 1.2'
23
23
  s.add_runtime_dependency 'benchmark'
24
24
  s.add_runtime_dependency 'bundler', '>= 1.17.2'
25
25
  s.add_runtime_dependency 'diff-lcs', '~> 1.4'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: solargraph
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.42.1
4
+ version: 0.42.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Fred Snyder
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-06-11 00:00:00.000000000 Z
11
+ date: 2021-06-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: backport
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '1.1'
19
+ version: '1.2'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '1.1'
26
+ version: '1.2'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: benchmark
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -477,7 +477,6 @@ files:
477
477
  - lib/solargraph/pin/keyword.rb
478
478
  - lib/solargraph/pin/keyword_param.rb
479
479
  - lib/solargraph/pin/local_variable.rb
480
- - lib/solargraph/pin/localized.rb
481
480
  - lib/solargraph/pin/method.rb
482
481
  - lib/solargraph/pin/method_alias.rb
483
482
  - lib/solargraph/pin/namespace.rb
@@ -1,43 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Solargraph
4
- module Pin
5
- module Localized
6
- # @return [Range]
7
- attr_reader :presence
8
-
9
- # @param other [Pin::Base] The caller's block
10
- # @param position [Position, Array(Integer, Integer)] The caller's position
11
- # @return [Boolean]
12
- def visible_from?(other, position)
13
- position = Position.normalize(position)
14
- other.filename == filename &&
15
- match_tags(other.full_context.tag, full_context.tag) &&
16
- (other == closure ||
17
- (closure.location.range.contain?(other.location.range.start) && closure.location.range.contain?(other.location.range.ending))
18
- ) &&
19
- presence.contain?(position)
20
- end
21
-
22
- # @param other_loc [Location]
23
- def visible_at?(other_loc)
24
- return false if location.filename != other_loc.filename
25
- presence.include?(other_loc.range.start)
26
- end
27
-
28
- private
29
-
30
- # @param tag1 [String]
31
- # @param tag2 [String]
32
- # @return [Boolean]
33
- def match_tags tag1, tag2
34
- # @todo This is an unfortunate hack made necessary by a discrepancy in
35
- # how tags indicate the root namespace. The long-term solution is to
36
- # standardize it, whether it's `Class<>`, an empty string, or
37
- # something else.
38
- tag1 == tag2 ||
39
- (['', 'Class<>'].include?(tag1) && ['', 'Class<>'].include?(tag2))
40
- end
41
- end
42
- end
43
- end