solargraph 0.27.1 → 0.28.0

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.
Files changed (44) hide show
  1. checksums.yaml +4 -4
  2. data/lib/solargraph.rb +8 -17
  3. data/lib/solargraph/api_map.rb +4 -3
  4. data/lib/solargraph/api_map/cache.rb +5 -5
  5. data/lib/solargraph/api_map/source_to_yard.rb +3 -2
  6. data/lib/solargraph/api_map/store.rb +25 -13
  7. data/lib/solargraph/complex_type.rb +3 -0
  8. data/lib/solargraph/diagnostics/update_errors.rb +21 -1
  9. data/lib/solargraph/language_server/host.rb +4 -3
  10. data/lib/solargraph/language_server/message/text_document/rename.rb +1 -1
  11. data/lib/solargraph/library.rb +12 -4
  12. data/lib/solargraph/pin.rb +5 -1
  13. data/lib/solargraph/pin/base.rb +0 -10
  14. data/lib/solargraph/pin/conversions.rb +1 -1
  15. data/lib/solargraph/pin/documenting.rb +0 -9
  16. data/lib/solargraph/pin/duck_method.rb +1 -1
  17. data/lib/solargraph/pin/keyword.rb +0 -5
  18. data/lib/solargraph/pin/namespace.rb +3 -16
  19. data/lib/solargraph/pin/reference.rb +13 -26
  20. data/lib/solargraph/pin/reference/extend.rb +11 -0
  21. data/lib/solargraph/pin/reference/include.rb +11 -0
  22. data/lib/solargraph/pin/reference/require.rb +15 -0
  23. data/lib/solargraph/pin/reference/superclass.rb +11 -0
  24. data/lib/solargraph/pin/symbol.rb +0 -4
  25. data/lib/solargraph/pin/yard_pin/namespace.rb +14 -14
  26. data/lib/solargraph/pin/yard_pin/yard_mixin.rb +0 -4
  27. data/lib/solargraph/position.rb +7 -0
  28. data/lib/solargraph/source.rb +7 -28
  29. data/lib/solargraph/source/chain.rb +0 -1
  30. data/lib/solargraph/source/chain/call.rb +1 -1
  31. data/lib/solargraph/source/chain/constant.rb +13 -4
  32. data/lib/solargraph/source/change.rb +7 -1
  33. data/lib/solargraph/source/cursor.rb +1 -5
  34. data/lib/solargraph/source/node_chainer.rb +5 -6
  35. data/lib/solargraph/source/source_chainer.rb +14 -12
  36. data/lib/solargraph/source_map.rb +5 -6
  37. data/lib/solargraph/source_map/clip.rb +16 -29
  38. data/lib/solargraph/source_map/mapper.rb +26 -21
  39. data/lib/solargraph/version.rb +1 -1
  40. data/lib/solargraph/workspace.rb +1 -2
  41. data/lib/solargraph/workspace/config.rb +10 -5
  42. data/lib/solargraph/yard_map.rb +3 -1
  43. metadata +6 -3
  44. data/lib/solargraph/source/chain/definition.rb +0 -20
@@ -25,8 +25,6 @@ module Solargraph
25
25
  end
26
26
  @node_comments = associate_comments(node, comments)
27
27
  @pins = []
28
- @requires = []
29
- @symbols = []
30
28
  @locals = []
31
29
  @strings = []
32
30
 
@@ -34,17 +32,17 @@ module Solargraph
34
32
  root = AST::Node.new(:source, [filename])
35
33
  root = root.append node
36
34
  # @todo Is the root namespace a class or a module? Assuming class for now.
37
- @pins.push Pin::Namespace.new(get_node_location(nil), '', '', nil, :class, :public, nil)
35
+ @pins.push Pin::Namespace.new(get_node_location(nil), '', '', nil, :class, :public)
38
36
  process root
39
37
  process_comment_directives
40
- [@pins, @locals, @requires, @symbols]
38
+ [@pins, @locals]
41
39
  end
42
40
 
43
41
  def unmap filename, code
44
42
  s = Position.new(0, 0)
45
43
  e = Position.from_offset(code, code.length)
46
44
  location = Location.new(filename, Range.new(s, e))
47
- [[Pin::Namespace.new(location, '', '', '', :class, :public, nil)], [], [], []]
45
+ [[Pin::Namespace.new(location, '', '', '', :class, :public)], []]
48
46
  end
49
47
 
50
48
  class << self
@@ -99,7 +97,8 @@ module Solargraph
99
97
  if node.type == :class and !node.children[1].nil?
100
98
  sc = unpack_name(node.children[1])
101
99
  end
102
- pins.push Solargraph::Pin::Namespace.new(get_node_location(node), tree[0..-2].join('::') || '', pack_name(node.children[0]).last.to_s, comments_for(node), node.type, visibility, sc)
100
+ pins.push Solargraph::Pin::Namespace.new(get_node_location(node), tree[0..-2].join('::') || '', pack_name(node.children[0]).last.to_s, comments_for(node), node.type, visibility)
101
+ pins.push Pin::Reference::Superclass.new(pins.last.location, pins.last.path, sc) unless sc.nil?
103
102
  end
104
103
  file = filename
105
104
  node.children.each do |c|
@@ -131,10 +130,10 @@ module Solargraph
131
130
  ora = find_parent(stack, :or_asgn)
132
131
  unless ora.nil?
133
132
  u = c.updated(:cvasgn, c.children + ora.children[1..-1], nil)
134
- pins.push Solargraph::Pin::ClassVariable.new(get_node_location(u), fqn || '', c.children[0].to_s, comments_for(u), u.children[1], infer_literal_node_type(u.children[1]), context)
133
+ pins.push Solargraph::Pin::ClassVariable.new(get_node_location(u), fqn || '', c.children[0].to_s, comments_for(u), u.children[1], infer_literal_node_type(u.children[1]), context.context)
135
134
  end
136
135
  else
137
- pins.push Solargraph::Pin::ClassVariable.new(get_node_location(c), fqn || '', c.children[0].to_s, comments_for(c), c.children[1], infer_literal_node_type(c.children[1]), context)
136
+ pins.push Solargraph::Pin::ClassVariable.new(get_node_location(c), fqn || '', c.children[0].to_s, comments_for(c), c.children[1], infer_literal_node_type(c.children[1]), context.context)
138
137
  end
139
138
  elsif c.type == :lvasgn
140
139
  here = get_node_start_position(c)
@@ -145,27 +144,27 @@ module Solargraph
145
144
  ora = find_parent(stack, :or_asgn)
146
145
  unless ora.nil?
147
146
  u = c.updated(:lvasgn, c.children + ora.children[1..-1], nil)
148
- @locals.push Solargraph::Pin::LocalVariable.new(get_node_location(u), fqn, u.children[0].to_s, comments_for(ora), u.children[1], infer_literal_node_type(c.children[1]), context, block, presence)
147
+ @locals.push Solargraph::Pin::LocalVariable.new(get_node_location(u), fqn, u.children[0].to_s, comments_for(ora), u.children[1], infer_literal_node_type(c.children[1]), context.context, block, presence)
149
148
  end
150
149
  else
151
- @locals.push Solargraph::Pin::LocalVariable.new(get_node_location(c), fqn, c.children[0].to_s, comments_for(c), c.children[1], infer_literal_node_type(c.children[1]), context, block, presence)
150
+ @locals.push Solargraph::Pin::LocalVariable.new(get_node_location(c), fqn, c.children[0].to_s, comments_for(c), c.children[1], infer_literal_node_type(c.children[1]), context.context, block, presence)
152
151
  end
153
152
  elsif c.type == :gvasgn
154
153
  if c.children[1].nil?
155
154
  ora = find_parent(stack, :or_asgn)
156
155
  unless ora.nil?
157
156
  u = c.updated(:gvasgn, c.children + ora.children[1..-1], nil)
158
- pins.push Solargraph::Pin::GlobalVariable.new(get_node_location(c), fqn, u.children[0].to_s, comments_for(c), u.children[1], infer_literal_node_type(c.children[1]), @pins.first)
157
+ pins.push Solargraph::Pin::GlobalVariable.new(get_node_location(c), fqn, u.children[0].to_s, comments_for(c), u.children[1], infer_literal_node_type(c.children[1]), @pins.first.context)
159
158
  end
160
159
  else
161
- pins.push Solargraph::Pin::GlobalVariable.new(get_node_location(c), fqn, c.children[0].to_s, comments_for(c), c.children[1], infer_literal_node_type(c.children[1]), @pins.first)
160
+ pins.push Solargraph::Pin::GlobalVariable.new(get_node_location(c), fqn, c.children[0].to_s, comments_for(c), c.children[1], infer_literal_node_type(c.children[1]), @pins.first.context)
162
161
  end
163
162
  elsif c.type == :sym
164
- @symbols.push Solargraph::Pin::Symbol.new(get_node_location(c), ":#{c.children[0]}")
163
+ pins.push Solargraph::Pin::Symbol.new(get_node_location(c), ":#{c.children[0]}")
165
164
  elsif c.type == :casgn
166
165
  here = get_node_start_position(c)
167
166
  block = get_block_pin(here)
168
- pins.push Solargraph::Pin::Constant.new(get_node_location(c), fqn, c.children[1].to_s, comments_for(c), c.children[2], infer_literal_node_type(c.children[2]), block, :public)
167
+ pins.push Solargraph::Pin::Constant.new(get_node_location(c), fqn, c.children[1].to_s, comments_for(c), c.children[2], infer_literal_node_type(c.children[2]), block.context, :public)
169
168
  elsif c.type == :def
170
169
  methpin = Solargraph::Pin::Method.new(get_node_location(c), fqn || '', c.children[(c.type == :def ? 0 : 1)].to_s, comments_for(c), scope, visibility, get_method_args(c))
171
170
  if methpin.name == 'initialize' and methpin.scope == :instance
@@ -216,7 +215,8 @@ module Solargraph
216
215
  if ref.kind == Pin::CONSTANT
217
216
  pins.push ref.class.new(ref.location, ref.namespace, ref.name, ref.comments, ref.signature, ref.return_type, ref.context, :private)
218
217
  else
219
- pins.push ref.class.new(ref.location, ref.namespace, ref.name, ref.comments, ref.type, :private, (ref.superclass_reference.nil? ? nil : ref.superclass_reference.name))
218
+ # pins.push ref.class.new(ref.location, ref.namespace, ref.name, ref.comments, ref.type, :private, (ref.superclass_reference.nil? ? nil : ref.superclass_reference.name))
219
+ pins.push ref.class.new(ref.location, ref.namespace, ref.name, ref.comments, ref.type, :private)
220
220
  end
221
221
  end
222
222
  end
@@ -253,8 +253,9 @@ module Solargraph
253
253
  c.children[2..-1].each do |i|
254
254
  nspin = @pins.select{|pin| pin.kind == Pin::NAMESPACE and pin.path == fqn}.last
255
255
  unless nspin.nil?
256
- iref = Pin::Reference.new(get_node_location(c), nspin.path, unpack_name(i))
257
- nspin.include_references.push(iref)
256
+ # iref = Pin::Reference.new(get_node_location(c), nspin.path, unpack_name(i))
257
+ # nspin.include_references.push(iref)
258
+ pins.push Pin::Reference::Include.new(get_node_location(c), nspin.path, unpack_name(i))
258
259
  end
259
260
  end
260
261
  end
@@ -267,11 +268,14 @@ module Solargraph
267
268
  unless nspin.nil?
268
269
  ref = nil
269
270
  if i.type == :self
270
- ref = Pin::Reference.new(get_node_location(c), nspin.path, nspin.path)
271
+ # ref = Pin::Reference.new(get_node_location(c), nspin.path, nspin.path)
272
+ ref = Pin::Reference::Extend.new(get_node_location(c), nspin.path, nspin.path)
271
273
  elsif i.type == :const
272
- ref = Pin::Reference.new(get_node_location(c), nspin.path, unpack_name(i))
274
+ # ref = Pin::Reference.new(get_node_location(c), nspin.path, unpack_name(i))
275
+ ref = Pin::Reference::Extend.new(get_node_location(c), nspin.path, unpack_name(i))
273
276
  end
274
- nspin.extend_references.push(ref) unless ref.nil?
277
+ # nspin.extend_references.push(ref) unless ref.nil?
278
+ pins.push ref unless ref.nil?
275
279
  end
276
280
  end
277
281
  end
@@ -289,7 +293,8 @@ module Solargraph
289
293
  next
290
294
  elsif c.type == :send and c.children[1] == :require
291
295
  if c.children[2].kind_of?(AST::Node) and c.children[2].type == :str
292
- @requires.push Solargraph::Pin::Reference.new(get_node_location(c), fqn, c.children[2].children[0].to_s)
296
+ # @requires.push Solargraph::Pin::Reference.new(get_node_location(c), fqn, c.children[2].children[0].to_s)
297
+ pins.push Pin::Reference::Require.new(get_node_location(c), c.children[2].children[0].to_s)
293
298
  end
294
299
  elsif c.type == :args
295
300
  if @node_stack.first.type == :block
@@ -1,3 +1,3 @@
1
1
  module Solargraph
2
- VERSION = '0.27.1'
2
+ VERSION = '0.28.0'
3
3
  end
@@ -130,8 +130,7 @@ module Solargraph
130
130
  source_hash.clear
131
131
  unless directory.nil?
132
132
  size = config.calculated.length
133
- raise WorkspaceTooLargeError.new(size, config.max_files) if config.max_files > 0 and size > config.max_files
134
-
133
+ raise WorkspaceTooLargeError, "The workspace is too large to index (#{size} files, #{config.max_files} max)" if config.max_files > 0 and size > config.max_files
135
134
  config.calculated.each do |filename|
136
135
  source_hash[filename] = Solargraph::Source.load(filename)
137
136
  end
@@ -2,6 +2,8 @@ require 'yaml'
2
2
 
3
3
  module Solargraph
4
4
  class Workspace
5
+ # Configuration data for a workspace.
6
+ #
5
7
  class Config
6
8
  # The maximum number of files that can be added to a workspace.
7
9
  # The workspace's .solargraph.yml can override this value.
@@ -21,10 +23,9 @@ module Solargraph
21
23
  unless @workspace.nil?
22
24
  sfile = File.join(@workspace, '.solargraph.yml')
23
25
  if File.file?(sfile)
24
- @raw_data = YAML.load(File.read(sfile))
25
- conf = YAML.load(File.read(sfile))
26
- include_globs = conf['include'] || include_globs
27
- exclude_globs = conf['exclude'] || []
26
+ @raw_data = YAML.safe_load(File.read(sfile))
27
+ include_globs = @raw_data['include'] || include_globs
28
+ exclude_globs = @raw_data['exclude'] || []
28
29
  end
29
30
  end
30
31
  @raw_data ||= {}
@@ -34,6 +35,7 @@ module Solargraph
34
35
  @raw_data['domains'] ||= []
35
36
  @raw_data['reporters'] ||= %w[rubocop require_not_found]
36
37
  @raw_data['plugins'] ||= []
38
+ @raw_data['require_paths'] ||= []
37
39
  @raw_data['max_files'] ||= MAX_FILES
38
40
  included
39
41
  excluded
@@ -78,6 +80,9 @@ module Solargraph
78
80
  raw_data['require']
79
81
  end
80
82
 
83
+ # An array of load paths for required paths.
84
+ #
85
+ # @return [Array<String>]
81
86
  def require_paths
82
87
  raw_data['require_paths'] || []
83
88
  end
@@ -146,7 +151,7 @@ module Solargraph
146
151
  # @param glob [String]
147
152
  # @return [Boolean]
148
153
  def glob_is_directory? glob
149
- File.directory?(glob) or File.directory?(glob_to_directory(glob))
154
+ File.directory?(glob) || File.directory?(glob_to_directory(glob))
150
155
  end
151
156
 
152
157
  # Translate a glob to a base directory if applicable
@@ -140,8 +140,10 @@ module Solargraph
140
140
  pins.clear
141
141
  unresolved_requires.clear
142
142
  stdnames = {}
143
+ done = []
143
144
  required.each do |r|
144
- next if r.nil? or r.empty?
145
+ next if r.nil? || r.empty? || done.include?(r)
146
+ done.push r
145
147
  cached = cache.get_path_pins(r)
146
148
  unless cached.nil?
147
149
  pins.concat cached
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.27.1
4
+ version: 0.28.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Fred Snyder
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-09-10 00:00:00.000000000 Z
11
+ date: 2018-09-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: parser
@@ -330,6 +330,10 @@ files:
330
330
  - lib/solargraph/pin/plugin/method.rb
331
331
  - lib/solargraph/pin/proxy_type.rb
332
332
  - lib/solargraph/pin/reference.rb
333
+ - lib/solargraph/pin/reference/extend.rb
334
+ - lib/solargraph/pin/reference/include.rb
335
+ - lib/solargraph/pin/reference/require.rb
336
+ - lib/solargraph/pin/reference/superclass.rb
333
337
  - lib/solargraph/pin/symbol.rb
334
338
  - lib/solargraph/pin/yard_pin.rb
335
339
  - lib/solargraph/pin/yard_pin/constant.rb
@@ -350,7 +354,6 @@ files:
350
354
  - lib/solargraph/source/chain/call.rb
351
355
  - lib/solargraph/source/chain/class_variable.rb
352
356
  - lib/solargraph/source/chain/constant.rb
353
- - lib/solargraph/source/chain/definition.rb
354
357
  - lib/solargraph/source/chain/global_variable.rb
355
358
  - lib/solargraph/source/chain/head.rb
356
359
  - lib/solargraph/source/chain/instance_variable.rb
@@ -1,20 +0,0 @@
1
- module Solargraph
2
- class Source
3
- class Chain
4
- class Definition < Link
5
- # @param location [Solargraph::Location]
6
- def initialize location
7
- @location = location
8
- end
9
-
10
- # @param api_map [ApiMap]
11
- def resolve api_map, name_pin, locals
12
- result = api_map.locate_pin(@location)
13
- # result = api_map.source_map(@location.filename).locate_named_path_pin(@location.range.start.line, @location.range.start.column)
14
- return [] if result.nil?
15
- [result]
16
- end
17
- end
18
- end
19
- end
20
- end