solargraph 0.23.6 → 0.24.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/solargraph.rb +1 -0
- data/lib/solargraph/api_map.rb +30 -7
- data/lib/solargraph/api_map/probe.rb +15 -2
- data/lib/solargraph/complex_type.rb +90 -0
- data/lib/solargraph/diagnostics.rb +2 -0
- data/lib/solargraph/diagnostics/base.rb +5 -2
- data/lib/solargraph/diagnostics/type_not_defined.rb +110 -0
- data/lib/solargraph/language_server/host.rb +9 -3
- data/lib/solargraph/language_server/message/exit_notification.rb +0 -1
- data/lib/solargraph/language_server/message/shutdown.rb +1 -1
- data/lib/solargraph/library.rb +12 -3
- data/lib/solargraph/pin.rb +1 -0
- data/lib/solargraph/pin/attribute.rb +12 -5
- data/lib/solargraph/pin/base.rb +47 -3
- data/lib/solargraph/pin/base_variable.rb +25 -4
- data/lib/solargraph/pin/block_parameter.rb +20 -11
- data/lib/solargraph/pin/duck_method.rb +15 -0
- data/lib/solargraph/pin/method.rb +16 -26
- data/lib/solargraph/pin/method_parameter.rb +12 -9
- data/lib/solargraph/pin/namespace.rb +2 -2
- data/lib/solargraph/pin/proxy_method.rb +5 -6
- data/lib/solargraph/pin/yard_object.rb +6 -2
- data/lib/solargraph/source.rb +26 -3
- data/lib/solargraph/source/change.rb +6 -0
- data/lib/solargraph/source/fragment.rb +31 -7
- data/lib/solargraph/source/location.rb +7 -0
- data/lib/solargraph/source/mapper.rb +28 -3
- data/lib/solargraph/source/position.rb +5 -0
- data/lib/solargraph/source/range.rb +5 -0
- data/lib/solargraph/version.rb +1 -1
- data/lib/solargraph/yard_map.rb +26 -0
- metadata +5 -2
@@ -36,6 +36,12 @@ module Solargraph
|
|
36
36
|
break
|
37
37
|
end
|
38
38
|
commit text, "#{new_text[0..-2]} "
|
39
|
+
elsif nullable and !range.nil? and new_text.empty?
|
40
|
+
offset = Position.to_offset(text, range.start)
|
41
|
+
if offset > 0 and text[offset - 1] == '.'
|
42
|
+
text = text[0..offset - 1] + ' ' + text[offset..-1]
|
43
|
+
end
|
44
|
+
commit text, new_text
|
39
45
|
elsif range.nil?
|
40
46
|
new_text
|
41
47
|
else
|
@@ -1,5 +1,10 @@
|
|
1
1
|
module Solargraph
|
2
2
|
class Source
|
3
|
+
# Information about a location in a source, including the location's word
|
4
|
+
# and signature, literal values at the base of signatures, and whether the
|
5
|
+
# location is inside a string or comment. ApiMaps use Fragments to provide
|
6
|
+
# results for completion and definition queries.
|
7
|
+
#
|
3
8
|
class Fragment
|
4
9
|
include NodeMethods
|
5
10
|
|
@@ -189,8 +194,7 @@ module Solargraph
|
|
189
194
|
#
|
190
195
|
# @return [Boolean]
|
191
196
|
def comment?
|
192
|
-
@comment
|
193
|
-
@comment
|
197
|
+
@comment ||= check_comment(line, column)
|
194
198
|
end
|
195
199
|
|
196
200
|
# Get the range of the word up to the current offset.
|
@@ -291,7 +295,8 @@ module Solargraph
|
|
291
295
|
index -=1
|
292
296
|
in_whitespace = false
|
293
297
|
while index >= 0
|
294
|
-
|
298
|
+
pos = Position.from_offset(@code, index)
|
299
|
+
break if index > 0 and check_comment(pos.line, pos.character)
|
295
300
|
unless !in_whitespace and string?
|
296
301
|
break if brackets > 0 or parens > 0 or squares > 0
|
297
302
|
char = @code[index, 1]
|
@@ -359,18 +364,29 @@ module Solargraph
|
|
359
364
|
[index + 1, signature]
|
360
365
|
end
|
361
366
|
|
362
|
-
# Determine if the specified
|
367
|
+
# Determine if the specified location is inside a comment.
|
363
368
|
#
|
369
|
+
# @param lin [Integer]
|
370
|
+
# @param col [Integer]
|
364
371
|
# @return [Boolean]
|
365
|
-
def
|
366
|
-
|
367
|
-
# line, col = get_position_at(index)
|
372
|
+
def check_comment(lin, col)
|
373
|
+
index = Position.line_char_to_offset(source_from_parser, lin, col)
|
368
374
|
@source.comments.each do |c|
|
369
375
|
return true if index > c.location.expression.begin_pos and index <= c.location.expression.end_pos
|
370
376
|
end
|
371
377
|
false
|
372
378
|
end
|
373
379
|
|
380
|
+
# True if the line and column are inside the specified range.
|
381
|
+
#
|
382
|
+
# @param location [Parser::Source::Range]
|
383
|
+
def compare_range line, column, location
|
384
|
+
return true if line == location.first_line and line == location.last_line and column >= location.column and column < location.last_column
|
385
|
+
return true if line > location.first_line and line < location.last_line
|
386
|
+
return true if line == location.last_line and column >= location.last_column and column < location.last_column
|
387
|
+
false
|
388
|
+
end
|
389
|
+
|
374
390
|
# Select the word that directly precedes the specified index.
|
375
391
|
# A word can only consist of letters, numbers, and underscores.
|
376
392
|
#
|
@@ -457,6 +473,14 @@ module Solargraph
|
|
457
473
|
end
|
458
474
|
@signature_position
|
459
475
|
end
|
476
|
+
|
477
|
+
# Range tests that depend on positions identified from parsed code, such
|
478
|
+
# as comment ranges, need to normalize EOLs to \n.
|
479
|
+
#
|
480
|
+
# @return [String]
|
481
|
+
def source_from_parser
|
482
|
+
@source_from_parser ||= @source.code.gsub(/\r\n/, "\n")
|
483
|
+
end
|
460
484
|
end
|
461
485
|
end
|
462
486
|
end
|
@@ -7,10 +7,17 @@ module Solargraph
|
|
7
7
|
# @return [Solargraph::Source::Range]
|
8
8
|
attr_reader :range
|
9
9
|
|
10
|
+
# @param filename [String]
|
11
|
+
# @param range [Solargraph::Source::Range]
|
10
12
|
def initialize filename, range
|
11
13
|
@filename = filename
|
12
14
|
@range = range
|
13
15
|
end
|
16
|
+
|
17
|
+
def == other
|
18
|
+
return false unless other.is_a?(Location)
|
19
|
+
filename == other.filename and range == other.range
|
20
|
+
end
|
14
21
|
end
|
15
22
|
end
|
16
23
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
require 'tempfile'
|
2
|
+
|
1
3
|
module Solargraph
|
2
4
|
class Source
|
3
5
|
# The Mapper generates pins and other data for Sources.
|
@@ -148,7 +150,8 @@ module Solargraph
|
|
148
150
|
if methpin.name == 'initialize' and methpin.scope == :instance
|
149
151
|
pins.push Solargraph::Pin::Method.new(methpin.location, methpin.namespace, 'new', methpin.docstring, :class, :public, methpin.parameters)
|
150
152
|
# @todo Smelly instance variable access.
|
151
|
-
pins.last.instance_variable_set(:@return_type, methpin.namespace)
|
153
|
+
# pins.last.instance_variable_set(:@return_type, methpin.namespace)
|
154
|
+
pins.last.instance_variable_set(:@return_complex_types, ComplexType.parse(methpin.namespace))
|
152
155
|
pins.push Solargraph::Pin::Method.new(methpin.location, methpin.namespace, methpin.name, methpin.docstring, methpin.scope, :private, methpin.parameters)
|
153
156
|
elsif visibility == :module_function
|
154
157
|
pins.push Solargraph::Pin::Method.new(methpin.location, methpin.namespace, methpin.name, methpin.docstring, :class, :public, methpin.parameters)
|
@@ -363,7 +366,8 @@ module Solargraph
|
|
363
366
|
ctxt += "#{p[num..-1]}\n"
|
364
367
|
end
|
365
368
|
}
|
366
|
-
parse =
|
369
|
+
parse = nil
|
370
|
+
suppress_stdout { parse = YARD::Docstring.parser.parse(ctxt) }
|
367
371
|
unless parse.directives.empty?
|
368
372
|
@directives[k] ||= []
|
369
373
|
@directives[k].concat parse.directives
|
@@ -382,7 +386,8 @@ module Solargraph
|
|
382
386
|
@directives.each_pair do |k, v|
|
383
387
|
v.each do |d|
|
384
388
|
ns = namespace_for(k.node)
|
385
|
-
docstring =
|
389
|
+
docstring = nil
|
390
|
+
suppress_stdout { docstring = YARD::Docstring.parser.parse(d.tag.text).to_docstring }
|
386
391
|
if d.tag.tag_name == 'attribute'
|
387
392
|
t = (d.tag.types.nil? || d.tag.types.empty?) ? nil : d.tag.types.flatten.join('')
|
388
393
|
if t.nil? or t.include?('r')
|
@@ -448,6 +453,26 @@ module Solargraph
|
|
448
453
|
}
|
449
454
|
args
|
450
455
|
end
|
456
|
+
|
457
|
+
# Suppress writing data to STDOUT during execution of a block.
|
458
|
+
#
|
459
|
+
# @example
|
460
|
+
# suppress_stdout { puts 'This will not get printed' }
|
461
|
+
#
|
462
|
+
def suppress_stdout
|
463
|
+
original_stdout = STDOUT.clone
|
464
|
+
# @todo It would be better to redirect to /dev/null or StringIO if
|
465
|
+
# there's a cross-platform solution for it.
|
466
|
+
tempfile = Tempfile.new('tmp')
|
467
|
+
STDOUT.reopen tempfile
|
468
|
+
begin
|
469
|
+
yield
|
470
|
+
ensure
|
471
|
+
STDOUT.reopen original_stdout
|
472
|
+
tempfile.close
|
473
|
+
tempfile.unlink
|
474
|
+
end
|
475
|
+
end
|
451
476
|
end
|
452
477
|
end
|
453
478
|
end
|
@@ -46,6 +46,11 @@ module Solargraph
|
|
46
46
|
def self.from_to l1, c1, l2, c2
|
47
47
|
Range.new(Position.new(l1, c1), Position.new(l2, c2))
|
48
48
|
end
|
49
|
+
|
50
|
+
def == other
|
51
|
+
return false unless other.is_a?(Range)
|
52
|
+
start == other.start and ending == other.ending
|
53
|
+
end
|
49
54
|
end
|
50
55
|
end
|
51
56
|
end
|
data/lib/solargraph/version.rb
CHANGED
data/lib/solargraph/yard_map.rb
CHANGED
@@ -52,10 +52,13 @@ module Solargraph
|
|
52
52
|
@yardocs ||= []
|
53
53
|
end
|
54
54
|
|
55
|
+
# @return [Array<String>]
|
55
56
|
def unresolved_requires
|
56
57
|
@unresolved_requires ||= []
|
57
58
|
end
|
58
59
|
|
60
|
+
# @param y [String]
|
61
|
+
# @return [YARD::Registry]
|
59
62
|
def load_yardoc y
|
60
63
|
begin
|
61
64
|
if y.kind_of?(Array)
|
@@ -71,6 +74,7 @@ module Solargraph
|
|
71
74
|
end
|
72
75
|
|
73
76
|
# @param query [String]
|
77
|
+
# @return [Array<String>]
|
74
78
|
def search query
|
75
79
|
found = []
|
76
80
|
(yardocs + [@@stdlib_yardoc]).each { |y|
|
@@ -87,6 +91,7 @@ module Solargraph
|
|
87
91
|
end
|
88
92
|
|
89
93
|
# @param query [String]
|
94
|
+
# @return [YARD::CodeObjects::Base]
|
90
95
|
def document query
|
91
96
|
found = []
|
92
97
|
(yardocs + [@@stdlib_yardoc]).each { |y|
|
@@ -99,6 +104,8 @@ module Solargraph
|
|
99
104
|
found
|
100
105
|
end
|
101
106
|
|
107
|
+
# @param namespace [String]
|
108
|
+
# @param scope [String]
|
102
109
|
# @return [Array<Solargraph::Pin::Base>]
|
103
110
|
def get_constants namespace , scope = ''
|
104
111
|
cached = cache.get_constants(namespace, scope)
|
@@ -139,6 +146,9 @@ module Solargraph
|
|
139
146
|
result
|
140
147
|
end
|
141
148
|
|
149
|
+
# @param namespace [String]
|
150
|
+
# @param scope [String]
|
151
|
+
# @param visibility [Array<Symbol>]
|
142
152
|
# @return [Array<Solargraph::Pin::Base>]
|
143
153
|
def get_methods namespace, scope = '', visibility: [:public]
|
144
154
|
return [] if namespace == '' and scope == ''
|
@@ -178,6 +188,9 @@ module Solargraph
|
|
178
188
|
meths
|
179
189
|
end
|
180
190
|
|
191
|
+
# @param namespace [String]
|
192
|
+
# @param scope [String]
|
193
|
+
# @param visibility [Array<Symbol>]
|
181
194
|
# @return [Array<Solargraph::Pin::Base>]
|
182
195
|
def get_instance_methods namespace, scope = '', visibility: [:public]
|
183
196
|
return [] if namespace == '' and scope == ''
|
@@ -222,6 +235,9 @@ module Solargraph
|
|
222
235
|
meths
|
223
236
|
end
|
224
237
|
|
238
|
+
# @param namespace [String]
|
239
|
+
# @param scope [String]
|
240
|
+
# @return [String]
|
225
241
|
def find_fully_qualified_namespace namespace, scope
|
226
242
|
unless scope.nil? or scope.empty?
|
227
243
|
parts = scope.split('::')
|
@@ -237,6 +253,9 @@ module Solargraph
|
|
237
253
|
nil
|
238
254
|
end
|
239
255
|
|
256
|
+
# @param path [String]
|
257
|
+
# @param space [String]
|
258
|
+
# @return [Array<Pin::YardObject>]
|
240
259
|
def objects path, space = ''
|
241
260
|
cached = cache.get_objects(path, space)
|
242
261
|
return cached unless cached.nil?
|
@@ -257,6 +276,7 @@ module Solargraph
|
|
257
276
|
result
|
258
277
|
end
|
259
278
|
|
279
|
+
# @param fqns [String]
|
260
280
|
# @return [Symbol] :class, :module, or nil
|
261
281
|
def get_namespace_type(fqns)
|
262
282
|
yardocs_documenting(fqns).each do |y|
|
@@ -323,6 +343,7 @@ module Solargraph
|
|
323
343
|
end
|
324
344
|
end
|
325
345
|
|
346
|
+
# @param spec [Gem::Specification]
|
326
347
|
def add_gem_dependencies spec
|
327
348
|
(spec.dependencies - spec.development_dependencies).each do |dep|
|
328
349
|
spec = Gem::Specification.find_by_name(dep.name)
|
@@ -336,6 +357,9 @@ module Solargraph
|
|
336
357
|
end
|
337
358
|
end
|
338
359
|
|
360
|
+
# @param namespace [String]
|
361
|
+
# @param scope [String]
|
362
|
+
# @return [Array<String>]
|
339
363
|
def combined_namespaces namespace, scope = ''
|
340
364
|
combined = [namespace]
|
341
365
|
unless scope.empty?
|
@@ -348,6 +372,8 @@ module Solargraph
|
|
348
372
|
combined
|
349
373
|
end
|
350
374
|
|
375
|
+
# @param namespace [String]
|
376
|
+
# @return [Array<String>]
|
351
377
|
def yardocs_documenting namespace
|
352
378
|
result = []
|
353
379
|
if namespace == ''
|
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.
|
4
|
+
version: 0.24.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-08-
|
11
|
+
date: 2018-08-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: parser
|
@@ -241,12 +241,14 @@ files:
|
|
241
241
|
- lib/solargraph/api_map/source_to_yard.rb
|
242
242
|
- lib/solargraph/api_map/store.rb
|
243
243
|
- lib/solargraph/api_map/type_methods.rb
|
244
|
+
- lib/solargraph/complex_type.rb
|
244
245
|
- lib/solargraph/core_fills.rb
|
245
246
|
- lib/solargraph/diagnostics.rb
|
246
247
|
- lib/solargraph/diagnostics/base.rb
|
247
248
|
- lib/solargraph/diagnostics/require_not_found.rb
|
248
249
|
- lib/solargraph/diagnostics/rubocop.rb
|
249
250
|
- lib/solargraph/diagnostics/severities.rb
|
251
|
+
- lib/solargraph/diagnostics/type_not_defined.rb
|
250
252
|
- lib/solargraph/language_server.rb
|
251
253
|
- lib/solargraph/language_server/completion_item_kinds.rb
|
252
254
|
- lib/solargraph/language_server/error_codes.rb
|
@@ -311,6 +313,7 @@ files:
|
|
311
313
|
- lib/solargraph/pin/constant.rb
|
312
314
|
- lib/solargraph/pin/conversions.rb
|
313
315
|
- lib/solargraph/pin/documenting.rb
|
316
|
+
- lib/solargraph/pin/duck_method.rb
|
314
317
|
- lib/solargraph/pin/global_variable.rb
|
315
318
|
- lib/solargraph/pin/helper.rb
|
316
319
|
- lib/solargraph/pin/instance_variable.rb
|