solargraph 0.56.0 → 0.57.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.
- checksums.yaml +4 -4
- data/.github/workflows/linting.yml +125 -0
- data/.github/workflows/plugins.yml +148 -6
- data/.github/workflows/rspec.yml +39 -4
- data/.github/workflows/typecheck.yml +5 -2
- data/.gitignore +5 -0
- data/.overcommit.yml +72 -0
- data/.rspec +1 -0
- data/.rubocop.yml +66 -0
- data/.rubocop_todo.yml +2627 -0
- data/.yardopts +1 -0
- data/CHANGELOG.md +56 -1
- data/README.md +8 -4
- data/Rakefile +125 -13
- data/lib/solargraph/api_map/cache.rb +3 -2
- data/lib/solargraph/api_map/constants.rb +218 -0
- data/lib/solargraph/api_map/index.rb +20 -26
- data/lib/solargraph/api_map/source_to_yard.rb +10 -4
- data/lib/solargraph/api_map/store.rb +126 -18
- data/lib/solargraph/api_map.rb +212 -234
- data/lib/solargraph/bench.rb +1 -0
- data/lib/solargraph/complex_type/type_methods.rb +1 -0
- data/lib/solargraph/complex_type/unique_type.rb +7 -7
- data/lib/solargraph/complex_type.rb +5 -1
- data/lib/solargraph/convention/active_support_concern.rb +111 -0
- data/lib/solargraph/convention/base.rb +17 -0
- data/lib/solargraph/convention/data_definition/data_assignment_node.rb +61 -0
- data/lib/solargraph/convention/data_definition/data_definition_node.rb +91 -0
- data/lib/solargraph/convention/data_definition.rb +105 -0
- data/lib/solargraph/convention/gemspec.rb +3 -2
- data/lib/solargraph/convention/struct_definition/struct_assignment_node.rb +2 -1
- data/lib/solargraph/convention/struct_definition/struct_definition_node.rb +4 -2
- data/lib/solargraph/convention/struct_definition.rb +87 -24
- data/lib/solargraph/convention.rb +32 -2
- data/lib/solargraph/diagnostics/rubocop.rb +6 -1
- data/lib/solargraph/diagnostics/rubocop_helpers.rb +1 -1
- data/lib/solargraph/doc_map.rb +48 -17
- data/lib/solargraph/environ.rb +9 -2
- data/lib/solargraph/gem_pins.rb +17 -11
- data/lib/solargraph/language_server/host/dispatch.rb +2 -0
- data/lib/solargraph/language_server/host/message_worker.rb +3 -0
- data/lib/solargraph/language_server/host.rb +2 -1
- data/lib/solargraph/language_server/message/base.rb +2 -1
- data/lib/solargraph/language_server/message/extended/check_gem_version.rb +1 -1
- data/lib/solargraph/language_server/message/text_document/definition.rb +2 -0
- data/lib/solargraph/language_server/message/text_document/formatting.rb +16 -2
- data/lib/solargraph/language_server/message/text_document/type_definition.rb +1 -0
- data/lib/solargraph/language_server/message/workspace/did_change_workspace_folders.rb +2 -0
- data/lib/solargraph/language_server/progress.rb +8 -0
- data/lib/solargraph/language_server/request.rb +1 -0
- data/lib/solargraph/library.rb +47 -30
- data/lib/solargraph/location.rb +2 -0
- data/lib/solargraph/logging.rb +11 -2
- data/lib/solargraph/page.rb +4 -0
- data/lib/solargraph/parser/comment_ripper.rb +8 -1
- data/lib/solargraph/parser/flow_sensitive_typing.rb +32 -4
- data/lib/solargraph/parser/node_methods.rb +2 -2
- data/lib/solargraph/parser/node_processor/base.rb +10 -5
- data/lib/solargraph/parser/node_processor.rb +24 -8
- data/lib/solargraph/parser/parser_gem/class_methods.rb +1 -1
- data/lib/solargraph/parser/parser_gem/flawed_builder.rb +1 -0
- data/lib/solargraph/parser/parser_gem/node_chainer.rb +3 -1
- data/lib/solargraph/parser/parser_gem/node_methods.rb +4 -2
- data/lib/solargraph/parser/parser_gem/node_processors/block_node.rb +3 -2
- data/lib/solargraph/parser/parser_gem/node_processors/casgn_node.rb +1 -21
- data/lib/solargraph/parser/parser_gem/node_processors/if_node.rb +2 -0
- data/lib/solargraph/parser/parser_gem/node_processors/masgn_node.rb +7 -1
- data/lib/solargraph/parser/parser_gem/node_processors/namespace_node.rb +0 -22
- data/lib/solargraph/parser/parser_gem/node_processors/opasgn_node.rb +1 -0
- data/lib/solargraph/parser/parser_gem/node_processors/orasgn_node.rb +1 -0
- data/lib/solargraph/parser/parser_gem/node_processors/resbody_node.rb +1 -0
- data/lib/solargraph/parser/parser_gem/node_processors/send_node.rb +35 -14
- data/lib/solargraph/parser/parser_gem/node_processors/sym_node.rb +1 -0
- data/lib/solargraph/parser/parser_gem/node_processors.rb +4 -0
- data/lib/solargraph/parser/region.rb +3 -0
- data/lib/solargraph/parser/snippet.rb +2 -0
- data/lib/solargraph/pin/base.rb +65 -8
- data/lib/solargraph/pin/base_variable.rb +1 -2
- data/lib/solargraph/pin/callable.rb +9 -0
- data/lib/solargraph/pin/closure.rb +2 -0
- data/lib/solargraph/pin/common.rb +6 -2
- data/lib/solargraph/pin/constant.rb +2 -0
- data/lib/solargraph/pin/delegated_method.rb +1 -0
- data/lib/solargraph/pin/local_variable.rb +4 -1
- data/lib/solargraph/pin/method.rb +12 -7
- data/lib/solargraph/pin/method_alias.rb +3 -0
- data/lib/solargraph/pin/parameter.rb +18 -8
- data/lib/solargraph/pin/proxy_type.rb +1 -0
- data/lib/solargraph/pin/reference/override.rb +15 -1
- data/lib/solargraph/pin/reference/superclass.rb +5 -0
- data/lib/solargraph/pin/reference.rb +26 -0
- data/lib/solargraph/pin/search.rb +3 -1
- data/lib/solargraph/pin/signature.rb +2 -0
- data/lib/solargraph/pin/symbol.rb +5 -0
- data/lib/solargraph/pin_cache.rb +64 -4
- data/lib/solargraph/position.rb +2 -0
- data/lib/solargraph/range.rb +1 -0
- data/lib/solargraph/rbs_map/conversions.rb +47 -18
- data/lib/solargraph/rbs_map/core_map.rb +3 -0
- data/lib/solargraph/rbs_map.rb +15 -2
- data/lib/solargraph/shell.rb +3 -0
- data/lib/solargraph/source/chain/link.rb +10 -1
- data/lib/solargraph/source/chain.rb +9 -2
- data/lib/solargraph/source/change.rb +2 -2
- data/lib/solargraph/source/cursor.rb +2 -3
- data/lib/solargraph/source/source_chainer.rb +1 -1
- data/lib/solargraph/source.rb +5 -2
- data/lib/solargraph/source_map/clip.rb +1 -1
- data/lib/solargraph/source_map/data.rb +4 -0
- data/lib/solargraph/source_map/mapper.rb +4 -2
- data/lib/solargraph/source_map.rb +21 -14
- data/lib/solargraph/type_checker/param_def.rb +2 -0
- data/lib/solargraph/type_checker/rules.rb +8 -0
- data/lib/solargraph/type_checker.rb +173 -120
- data/lib/solargraph/version.rb +1 -1
- data/lib/solargraph/workspace/config.rb +1 -3
- data/lib/solargraph/workspace/require_paths.rb +98 -0
- data/lib/solargraph/workspace.rb +24 -48
- data/lib/solargraph/yard_map/helpers.rb +29 -1
- data/lib/solargraph/yard_map/mapper/to_constant.rb +5 -5
- data/lib/solargraph/yard_map/mapper/to_method.rb +3 -8
- data/lib/solargraph/yard_map/mapper/to_namespace.rb +7 -7
- data/lib/solargraph/yardoc.rb +18 -3
- data/lib/solargraph.rb +15 -0
- data/rbs/fills/tuple.rbs +2 -3
- data/sig/shims/parser/3.2.0.1/builders/default.rbs +195 -0
- data/sig/shims/thor/1.2.0.1/.rbs_meta.yaml +9 -0
- data/sig/shims/thor/1.2.0.1/manifest.yaml +7 -0
- data/sig/shims/thor/1.2.0.1/thor.rbs +17 -0
- data/solargraph.gemspec +14 -4
- metadata +128 -11
- data/lib/.rubocop.yml +0 -22
@@ -22,12 +22,14 @@ module Solargraph
|
|
22
22
|
end
|
23
23
|
end
|
24
24
|
|
25
|
+
# @param loader [RBS::EnvironmentLoader]
|
25
26
|
def initialize(loader:)
|
26
27
|
@loader = loader
|
27
28
|
@pins = []
|
28
29
|
load_environment_to_pins(loader)
|
29
30
|
end
|
30
31
|
|
32
|
+
# @return [RBS::EnvironmentLoader]
|
31
33
|
attr_reader :loader
|
32
34
|
|
33
35
|
# @return [Array<Pin::Base>]
|
@@ -106,14 +108,14 @@ module Solargraph
|
|
106
108
|
# @param closure [Pin::Namespace]
|
107
109
|
# @return [void]
|
108
110
|
def convert_members_to_pins decl, closure
|
109
|
-
context = Context.new
|
111
|
+
context = Conversions::Context.new
|
110
112
|
decl.members.each { |m| context = convert_member_to_pin(m, closure, context) }
|
111
113
|
end
|
112
114
|
|
113
115
|
# @param member [RBS::AST::Members::Base,RBS::AST::Declarations::Base]
|
114
116
|
# @param closure [Pin::Namespace]
|
115
117
|
# @param context [Context]
|
116
|
-
# @return [
|
118
|
+
# @return [Context]
|
117
119
|
def convert_member_to_pin member, closure, context
|
118
120
|
case member
|
119
121
|
when RBS::AST::Members::MethodDefinition
|
@@ -161,9 +163,10 @@ module Solargraph
|
|
161
163
|
generic_defaults[param.name.to_s] = ComplexType.parse(tag).force_rooted
|
162
164
|
end
|
163
165
|
end
|
166
|
+
class_name = decl.name.relative!.to_s
|
164
167
|
class_pin = Solargraph::Pin::Namespace.new(
|
165
168
|
type: :class,
|
166
|
-
name:
|
169
|
+
name: class_name,
|
167
170
|
closure: Solargraph::Pin::ROOT_PIN,
|
168
171
|
comments: decl.comment&.string,
|
169
172
|
type_location: location_decl_to_pin_location(decl.location),
|
@@ -178,11 +181,12 @@ module Solargraph
|
|
178
181
|
if decl.super_class
|
179
182
|
type = build_type(decl.super_class.name, decl.super_class.args)
|
180
183
|
generic_values = type.all_params.map(&:to_s)
|
184
|
+
superclass_name = decl.super_class.name.to_s
|
181
185
|
pins.push Solargraph::Pin::Reference::Superclass.new(
|
182
186
|
type_location: location_decl_to_pin_location(decl.super_class.location),
|
183
187
|
closure: class_pin,
|
184
188
|
generic_values: generic_values,
|
185
|
-
name:
|
189
|
+
name: superclass_name,
|
186
190
|
source: :rbs
|
187
191
|
)
|
188
192
|
end
|
@@ -295,6 +299,7 @@ module Solargraph
|
|
295
299
|
name: name,
|
296
300
|
closure: closure,
|
297
301
|
comments: decl.comment&.string,
|
302
|
+
type_location: location_decl_to_pin_location(decl.location),
|
298
303
|
source: :rbs
|
299
304
|
)
|
300
305
|
rooted_tag = ComplexType.parse(other_type_to_tag(decl.type)).force_rooted.rooted_tags
|
@@ -316,6 +321,7 @@ module Solargraph
|
|
316
321
|
# related overrides
|
317
322
|
# @todo externalize remaining overrides into yaml file, then
|
318
323
|
# allow that to be extended via .solargraph.yml
|
324
|
+
# @type [Hash{Array(String, Symbol, String) => Symbol}
|
319
325
|
VISIBILITY_OVERRIDE = {
|
320
326
|
["Rails::Engine", :instance, "run_tasks_blocks"] => :protected,
|
321
327
|
# Should have been marked as both instance and class method in module -e.g., 'module_function'
|
@@ -340,6 +346,13 @@ module Solargraph
|
|
340
346
|
["Rainbow::Presenter", :instance, "wrap_with_sgr"] => :private,
|
341
347
|
}
|
342
348
|
|
349
|
+
# @param decl [RBS::AST::Members::MethodDefinition, RBS::AST::Members::AttrReader, RBS::AST::Members::AttrAccessor]
|
350
|
+
# @param closure [Pin::Closure]
|
351
|
+
# @param context [Context]
|
352
|
+
# @param scope [Symbol] :instance or :class
|
353
|
+
# @param name [String] The name of the method
|
354
|
+
# @sg-ignore
|
355
|
+
# @return [Symbol]
|
343
356
|
def calculate_method_visibility(decl, context, closure, scope, name)
|
344
357
|
override_key = [closure.path, scope, name]
|
345
358
|
visibility = VISIBILITY_OVERRIDE[override_key]
|
@@ -414,15 +427,16 @@ module Solargraph
|
|
414
427
|
# @return [void]
|
415
428
|
def method_def_to_sigs decl, pin
|
416
429
|
decl.overloads.map do |overload|
|
430
|
+
type_location = location_decl_to_pin_location(overload.method_type.location)
|
417
431
|
generics = overload.method_type.type_params.map(&:name).map(&:to_s)
|
418
432
|
signature_parameters, signature_return_type = parts_of_function(overload.method_type, pin)
|
419
433
|
block = if overload.method_type.block
|
420
434
|
block_parameters, block_return_type = parts_of_function(overload.method_type.block, pin)
|
421
|
-
Pin::Signature.new(generics: generics, parameters: block_parameters, return_type: block_return_type,
|
422
|
-
|
435
|
+
Pin::Signature.new(generics: generics, parameters: block_parameters, return_type: block_return_type, source: :rbs,
|
436
|
+
type_location: type_location, closure: pin)
|
423
437
|
end
|
424
|
-
Pin::Signature.new(generics: generics, parameters: signature_parameters, return_type: signature_return_type, block: block,
|
425
|
-
|
438
|
+
Pin::Signature.new(generics: generics, parameters: signature_parameters, return_type: signature_return_type, block: block, source: :rbs,
|
439
|
+
type_location: type_location, closure: pin)
|
426
440
|
end
|
427
441
|
end
|
428
442
|
|
@@ -441,44 +455,52 @@ module Solargraph
|
|
441
455
|
# @param pin [Pin::Method]
|
442
456
|
# @return [Array(Array<Pin::Parameter>, ComplexType)]
|
443
457
|
def parts_of_function type, pin
|
444
|
-
|
458
|
+
type_location = pin.type_location
|
459
|
+
if defined?(RBS::Types::UntypedFunction) && type.type.is_a?(RBS::Types::UntypedFunction)
|
460
|
+
return [
|
461
|
+
[Solargraph::Pin::Parameter.new(decl: :restarg, name: 'arg', closure: pin, source: :rbs, type_location: type_location)],
|
462
|
+
ComplexType.try_parse(method_type_to_tag(type)).force_rooted
|
463
|
+
]
|
464
|
+
end
|
445
465
|
|
446
466
|
parameters = []
|
447
467
|
arg_num = -1
|
448
468
|
type.type.required_positionals.each do |param|
|
449
469
|
name = param.name ? param.name.to_s : "arg_#{arg_num += 1}"
|
450
|
-
parameters.push Solargraph::Pin::Parameter.new(decl: :arg, name: name, closure: pin, return_type: ComplexType.try_parse(other_type_to_tag(param.type)).force_rooted, source: :rbs)
|
470
|
+
parameters.push Solargraph::Pin::Parameter.new(decl: :arg, name: name, closure: pin, return_type: ComplexType.try_parse(other_type_to_tag(param.type)).force_rooted, source: :rbs, type_location: type_location)
|
451
471
|
end
|
452
472
|
type.type.optional_positionals.each do |param|
|
453
473
|
name = param.name ? param.name.to_s : "arg_#{arg_num += 1}"
|
454
474
|
parameters.push Solargraph::Pin::Parameter.new(decl: :optarg, name: name, closure: pin,
|
455
475
|
return_type: ComplexType.try_parse(other_type_to_tag(param.type)).force_rooted,
|
476
|
+
type_location: type_location,
|
456
477
|
source: :rbs)
|
457
478
|
end
|
458
479
|
if type.type.rest_positionals
|
459
480
|
name = type.type.rest_positionals.name ? type.type.rest_positionals.name.to_s : "arg_#{arg_num += 1}"
|
460
|
-
parameters.push Solargraph::Pin::Parameter.new(decl: :restarg, name: name, closure: pin, source: :rbs)
|
481
|
+
parameters.push Solargraph::Pin::Parameter.new(decl: :restarg, name: name, closure: pin, source: :rbs, type_location: type_location)
|
461
482
|
end
|
462
483
|
type.type.trailing_positionals.each do |param|
|
463
484
|
name = param.name ? param.name.to_s : "arg_#{arg_num += 1}"
|
464
|
-
parameters.push Solargraph::Pin::Parameter.new(decl: :arg, name: name, closure: pin, source: :rbs)
|
485
|
+
parameters.push Solargraph::Pin::Parameter.new(decl: :arg, name: name, closure: pin, source: :rbs, type_location: type_location)
|
465
486
|
end
|
466
487
|
type.type.required_keywords.each do |orig, param|
|
467
488
|
name = orig ? orig.to_s : "arg_#{arg_num += 1}"
|
468
489
|
parameters.push Solargraph::Pin::Parameter.new(decl: :kwarg, name: name, closure: pin,
|
469
490
|
return_type: ComplexType.try_parse(other_type_to_tag(param.type)).force_rooted,
|
470
|
-
source: :rbs)
|
491
|
+
source: :rbs, type_location: type_location)
|
471
492
|
end
|
472
493
|
type.type.optional_keywords.each do |orig, param|
|
473
494
|
name = orig ? orig.to_s : "arg_#{arg_num += 1}"
|
474
495
|
parameters.push Solargraph::Pin::Parameter.new(decl: :kwoptarg, name: name, closure: pin,
|
475
496
|
return_type: ComplexType.try_parse(other_type_to_tag(param.type)).force_rooted,
|
497
|
+
type_location: type_location,
|
476
498
|
source: :rbs)
|
477
499
|
end
|
478
500
|
if type.type.rest_keywords
|
479
501
|
name = type.type.rest_keywords.name ? type.type.rest_keywords.name.to_s : "arg_#{arg_num += 1}"
|
480
502
|
parameters.push Solargraph::Pin::Parameter.new(decl: :kwrestarg, name: type.type.rest_keywords.name.to_s, closure: pin,
|
481
|
-
source: :rbs)
|
503
|
+
source: :rbs, type_location: type_location)
|
482
504
|
end
|
483
505
|
|
484
506
|
rooted_tag = method_type_to_tag(type)
|
@@ -488,6 +510,7 @@ module Solargraph
|
|
488
510
|
|
489
511
|
# @param decl [RBS::AST::Members::AttrReader,RBS::AST::Members::AttrAccessor]
|
490
512
|
# @param closure [Pin::Namespace]
|
513
|
+
# @param context [Context]
|
491
514
|
# @return [void]
|
492
515
|
def attr_reader_to_pin(decl, closure, context)
|
493
516
|
name = decl.name.to_s
|
@@ -511,14 +534,16 @@ module Solargraph
|
|
511
534
|
|
512
535
|
# @param decl [RBS::AST::Members::AttrWriter, RBS::AST::Members::AttrAccessor]
|
513
536
|
# @param closure [Pin::Namespace]
|
537
|
+
# @param context [Context]
|
514
538
|
# @return [void]
|
515
539
|
def attr_writer_to_pin(decl, closure, context)
|
516
540
|
final_scope = decl.kind == :instance ? :instance : :class
|
517
541
|
name = "#{decl.name.to_s}="
|
518
542
|
visibility = calculate_method_visibility(decl, context, closure, final_scope, name)
|
543
|
+
type_location = location_decl_to_pin_location(decl.location)
|
519
544
|
pin = Solargraph::Pin::Method.new(
|
520
545
|
name: name,
|
521
|
-
type_location:
|
546
|
+
type_location: type_location,
|
522
547
|
closure: closure,
|
523
548
|
parameters: [],
|
524
549
|
comments: decl.comment&.string,
|
@@ -532,7 +557,8 @@ module Solargraph
|
|
532
557
|
name: 'value',
|
533
558
|
return_type: ComplexType.try_parse(other_type_to_tag(decl.type)).force_rooted,
|
534
559
|
source: :rbs,
|
535
|
-
closure: pin
|
560
|
+
closure: pin,
|
561
|
+
type_location: type_location
|
536
562
|
)
|
537
563
|
rooted_tag = ComplexType.parse(other_type_to_tag(decl.type)).force_rooted.rooted_tags
|
538
564
|
pin.docstring.add_tag(YARD::Tags::Tag.new(:return, '', rooted_tag))
|
@@ -541,6 +567,7 @@ module Solargraph
|
|
541
567
|
|
542
568
|
# @param decl [RBS::AST::Members::AttrAccessor]
|
543
569
|
# @param closure [Pin::Namespace]
|
570
|
+
# @param context [Context]
|
544
571
|
# @return [void]
|
545
572
|
def attr_accessor_to_pin(decl, closure, context)
|
546
573
|
attr_reader_to_pin(decl, closure, context)
|
@@ -572,6 +599,7 @@ module Solargraph
|
|
572
599
|
name: name,
|
573
600
|
closure: closure,
|
574
601
|
comments: decl.comment&.string,
|
602
|
+
type_location: location_decl_to_pin_location(decl.location),
|
575
603
|
source: :rbs
|
576
604
|
)
|
577
605
|
rooted_tag = ComplexType.parse(other_type_to_tag(decl.type)).force_rooted.rooted_tags
|
@@ -588,6 +616,7 @@ module Solargraph
|
|
588
616
|
name: name,
|
589
617
|
closure: closure,
|
590
618
|
comments: decl.comment&.string,
|
619
|
+
type_location: location_decl_to_pin_location(decl.location),
|
591
620
|
source: :rbs
|
592
621
|
)
|
593
622
|
rooted_tag = ComplexType.parse(other_type_to_tag(decl.type)).force_rooted.rooted_tags
|
@@ -672,13 +701,13 @@ module Solargraph
|
|
672
701
|
# @return [ComplexType::UniqueType]
|
673
702
|
def build_type(type_name, type_args = [])
|
674
703
|
base = RBS_TO_YARD_TYPE[type_name.relative!.to_s] || type_name.relative!.to_s
|
675
|
-
params = type_args.map { |a| other_type_to_tag(a) }.
|
704
|
+
params = type_args.map { |a| other_type_to_tag(a) }.map do |t|
|
676
705
|
ComplexType.try_parse(t).force_rooted
|
677
706
|
end
|
678
707
|
if base == 'Hash' && params.length == 2
|
679
708
|
ComplexType::UniqueType.new(base, [params.first], [params.last], rooted: true, parameters_type: :hash)
|
680
709
|
else
|
681
|
-
ComplexType::UniqueType.new(base, [], params, rooted: true, parameters_type: :list)
|
710
|
+
ComplexType::UniqueType.new(base, [], params.reject(&:undefined?), rooted: true, parameters_type: :list)
|
682
711
|
end
|
683
712
|
end
|
684
713
|
|
@@ -14,6 +14,7 @@ module Solargraph
|
|
14
14
|
|
15
15
|
def initialize; end
|
16
16
|
|
17
|
+
# @return [Enumerable<Pin::Base>]
|
17
18
|
def pins
|
18
19
|
return @pins if @pins
|
19
20
|
|
@@ -39,10 +40,12 @@ module Solargraph
|
|
39
40
|
|
40
41
|
private
|
41
42
|
|
43
|
+
# @return [RBS::EnvironmentLoader]
|
42
44
|
def loader
|
43
45
|
@loader ||= RBS::EnvironmentLoader.new(repository: RBS::Repository.new(no_stdlib: false))
|
44
46
|
end
|
45
47
|
|
48
|
+
# @return [Conversions]
|
46
49
|
def conversions
|
47
50
|
@conversions ||= Conversions.new(loader: loader)
|
48
51
|
end
|
data/lib/solargraph/rbs_map.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require 'digest'
|
3
4
|
require 'pathname'
|
4
5
|
require 'rbs'
|
5
6
|
|
@@ -22,7 +23,8 @@ module Solargraph
|
|
22
23
|
attr_reader :rbs_collection_config_path
|
23
24
|
|
24
25
|
# @param library [String]
|
25
|
-
# @param version [String, nil
|
26
|
+
# @param version [String, nil
|
27
|
+
# @param rbs_collection_config_path [String, Pathname, nil]
|
26
28
|
# @param rbs_collection_paths [Array<Pathname, String>]
|
27
29
|
def initialize library, version = nil, rbs_collection_config_path: nil, rbs_collection_paths: []
|
28
30
|
if rbs_collection_config_path.nil? && !rbs_collection_paths.empty?
|
@@ -35,16 +37,18 @@ module Solargraph
|
|
35
37
|
add_library loader, library, version
|
36
38
|
end
|
37
39
|
|
40
|
+
# @return [RBS::EnvironmentLoader]
|
38
41
|
def loader
|
39
42
|
@loader ||= RBS::EnvironmentLoader.new(core_root: nil, repository: repository)
|
40
43
|
end
|
41
44
|
|
42
|
-
# @return
|
45
|
+
# @return [String] representing the version of the RBS info fetched
|
43
46
|
# for the given library. Must change when the RBS info is
|
44
47
|
# updated upstream for the same library and version. May change
|
45
48
|
# if the config for where information comes form changes.
|
46
49
|
def cache_key
|
47
50
|
@hextdigest ||= begin
|
51
|
+
# @type [String, nil]
|
48
52
|
data = nil
|
49
53
|
if rbs_collection_config_path
|
50
54
|
lockfile_path = RBS::Collection::Config.to_lockfile_path(Pathname.new(rbs_collection_config_path))
|
@@ -68,6 +72,10 @@ module Solargraph
|
|
68
72
|
end
|
69
73
|
end
|
70
74
|
|
75
|
+
# @param gemspec [Gem::Specification]
|
76
|
+
# @param rbs_collection_path [String, Pathname, nil]
|
77
|
+
# @param rbs_collection_config_path [String, Pathname, nil]
|
78
|
+
# @return [RbsMap]
|
71
79
|
def self.from_gemspec gemspec, rbs_collection_path, rbs_collection_config_path
|
72
80
|
rbs_map = RbsMap.new(gemspec.name, gemspec.version,
|
73
81
|
rbs_collection_paths: [rbs_collection_path].compact,
|
@@ -80,6 +88,7 @@ module Solargraph
|
|
80
88
|
rbs_collection_config_path: rbs_collection_config_path)
|
81
89
|
end
|
82
90
|
|
91
|
+
# @return [Array<Pin::Base>]
|
83
92
|
def pins
|
84
93
|
@pins ||= resolved? ? conversions.pins : []
|
85
94
|
end
|
@@ -103,6 +112,7 @@ module Solargraph
|
|
103
112
|
@resolved
|
104
113
|
end
|
105
114
|
|
115
|
+
# @return [RBS::Repository]
|
106
116
|
def repository
|
107
117
|
@repository ||= RBS::Repository.new(no_stdlib: false).tap do |repo|
|
108
118
|
@rbs_collection_paths.each do |dir|
|
@@ -120,16 +130,19 @@ module Solargraph
|
|
120
130
|
|
121
131
|
private
|
122
132
|
|
133
|
+
# @return [RBS::EnvironmentLoader]
|
123
134
|
def loader
|
124
135
|
@loader ||= RBS::EnvironmentLoader.new(core_root: nil, repository: repository)
|
125
136
|
end
|
126
137
|
|
138
|
+
# @return [Conversions]
|
127
139
|
def conversions
|
128
140
|
@conversions ||= Conversions.new(loader: loader)
|
129
141
|
end
|
130
142
|
|
131
143
|
# @param loader [RBS::EnvironmentLoader]
|
132
144
|
# @param library [String]
|
145
|
+
# @param version [String, nil]
|
133
146
|
# @return [Boolean] true if adding the library succeeded
|
134
147
|
def add_library loader, library, version
|
135
148
|
@resolved = if loader.has_library?(library: library, version: version)
|
data/lib/solargraph/shell.rb
CHANGED
@@ -36,6 +36,7 @@ module Solargraph
|
|
36
36
|
Signal.trap("TERM") do
|
37
37
|
Backport.stop
|
38
38
|
end
|
39
|
+
# @sg-ignore Wrong argument type for Backport.prepare_tcp_server: adapter expected Backport::Adapter, received Module<Solargraph::LanguageServer::Transport::Adapter>
|
39
40
|
Backport.prepare_tcp_server host: options[:host], port: port, adapter: Solargraph::LanguageServer::Transport::Adapter
|
40
41
|
STDERR.puts "Solargraph is listening PORT=#{port} PID=#{Process.pid}"
|
41
42
|
end
|
@@ -52,6 +53,7 @@ module Solargraph
|
|
52
53
|
Signal.trap("TERM") do
|
53
54
|
Backport.stop
|
54
55
|
end
|
56
|
+
# @sg-ignore Wrong argument type for Backport.prepare_stdio_server: adapter expected Backport::Adapter, received Module<Solargraph::LanguageServer::Transport::Adapter>
|
55
57
|
Backport.prepare_stdio_server adapter: Solargraph::LanguageServer::Transport::Adapter
|
56
58
|
STDERR.puts "Solargraph is listening on stdio PID=#{Process.pid}"
|
57
59
|
end
|
@@ -258,6 +260,7 @@ module Solargraph
|
|
258
260
|
end
|
259
261
|
|
260
262
|
# @param gemspec [Gem::Specification]
|
263
|
+
# @param api_map [ApiMap]
|
261
264
|
# @return [void]
|
262
265
|
def do_cache gemspec, api_map
|
263
266
|
# @todo if the rebuild: option is passed as a positional arg,
|
@@ -17,7 +17,13 @@ module Solargraph
|
|
17
17
|
@word = word
|
18
18
|
end
|
19
19
|
|
20
|
-
# @sg-ignore
|
20
|
+
# @sg-ignore two problems - Declared return type
|
21
|
+
# ::Solargraph::Source::Chain::Array does not match inferred
|
22
|
+
# type ::Array(::Class<::Solargraph::Source::Chain::Link>,
|
23
|
+
# ::String) for
|
24
|
+
# Solargraph::Source::Chain::Link#equality_fields
|
25
|
+
# and
|
26
|
+
# Not enough arguments to Module#protected
|
21
27
|
protected def equality_fields
|
22
28
|
[self.class, word]
|
23
29
|
end
|
@@ -39,6 +45,7 @@ module Solargraph
|
|
39
45
|
end
|
40
46
|
|
41
47
|
# debugging description of contents; not for machine use
|
48
|
+
# @return [String]
|
42
49
|
def desc
|
43
50
|
word
|
44
51
|
end
|
@@ -74,6 +81,8 @@ module Solargraph
|
|
74
81
|
end
|
75
82
|
|
76
83
|
# debugging description of contents; not for machine use
|
84
|
+
#
|
85
|
+
# @return [String]
|
77
86
|
def desc
|
78
87
|
word
|
79
88
|
end
|
@@ -15,6 +15,7 @@ module Solargraph
|
|
15
15
|
#
|
16
16
|
class Chain
|
17
17
|
include Equality
|
18
|
+
include Logging
|
18
19
|
|
19
20
|
autoload :Link, 'solargraph/source/chain/link'
|
20
21
|
autoload :Call, 'solargraph/source/chain/call'
|
@@ -75,7 +76,9 @@ module Solargraph
|
|
75
76
|
|
76
77
|
# Determine potential Pins returned by this chain of words
|
77
78
|
#
|
78
|
-
# @param api_map [ApiMap]
|
79
|
+
# @param api_map [ApiMap]
|
80
|
+
#
|
81
|
+
# @param name_pin [Pin::Base] A pin
|
79
82
|
# representing the place in which expression is evaluated (e.g.,
|
80
83
|
# a Method pin, or a Module or Class pin if not run within a
|
81
84
|
# method - both in terms of the closure around the chain, as well
|
@@ -192,6 +195,7 @@ module Solargraph
|
|
192
195
|
|
193
196
|
include Logging
|
194
197
|
|
198
|
+
# @return [String]
|
195
199
|
def desc
|
196
200
|
links.map(&:desc).to_s
|
197
201
|
end
|
@@ -265,7 +269,10 @@ module Solargraph
|
|
265
269
|
else
|
266
270
|
ComplexType.new(types)
|
267
271
|
end
|
268
|
-
|
272
|
+
if context.nil? || context.return_type.undefined?
|
273
|
+
# up to downstream to resolve self type
|
274
|
+
return type
|
275
|
+
end
|
269
276
|
|
270
277
|
type.self_to_type(context.return_type)
|
271
278
|
end
|
@@ -28,7 +28,7 @@ module Solargraph
|
|
28
28
|
# syntax errors will be repaired.
|
29
29
|
# @return [String] The updated text.
|
30
30
|
def write text, nullable = false
|
31
|
-
if nullable and !range.nil? and new_text.match(/[
|
31
|
+
if nullable and !range.nil? and new_text.match(/[.\[{(@$:]$/)
|
32
32
|
[':', '@'].each do |dupable|
|
33
33
|
next unless new_text == dupable
|
34
34
|
offset = Position.to_offset(text, range.start)
|
@@ -59,7 +59,7 @@ module Solargraph
|
|
59
59
|
else
|
60
60
|
result = commit text, fixed
|
61
61
|
off = Position.to_offset(text, range.start)
|
62
|
-
match = result[0, off].match(/[
|
62
|
+
match = result[0, off].match(/[.:]+\z/)
|
63
63
|
if match
|
64
64
|
result = result[0, off].sub(/#{match[0]}\z/, ' ' * match[0].length) + result[off..-1]
|
65
65
|
end
|
@@ -35,7 +35,6 @@ module Solargraph
|
|
35
35
|
# The part of the word before the current position. Given the text
|
36
36
|
# `foo.bar`, the start_of_word at position(0, 6) is `ba`.
|
37
37
|
#
|
38
|
-
# @sg-ignore Improve resolution of String#match below
|
39
38
|
# @return [String]
|
40
39
|
def start_of_word
|
41
40
|
@start_of_word ||= begin
|
@@ -125,7 +124,7 @@ module Solargraph
|
|
125
124
|
def node_position
|
126
125
|
@node_position ||= begin
|
127
126
|
if start_of_word.empty?
|
128
|
-
match = source.code[0, offset].match(
|
127
|
+
match = source.code[0, offset].match(/\s*(\.|:+)\s*$/)
|
129
128
|
if match
|
130
129
|
Position.from_offset(source.code, offset - match[0].length)
|
131
130
|
else
|
@@ -160,7 +159,7 @@ module Solargraph
|
|
160
159
|
#
|
161
160
|
# @return [Regexp]
|
162
161
|
def end_word_pattern
|
163
|
-
/^([a-z0-9_]|[^\u0000-\u007F])*[
|
162
|
+
/^([a-z0-9_]|[^\u0000-\u007F])*[?!]?/i
|
164
163
|
end
|
165
164
|
end
|
166
165
|
end
|
data/lib/solargraph/source.rb
CHANGED
@@ -30,7 +30,7 @@ module Solargraph
|
|
30
30
|
@node
|
31
31
|
end
|
32
32
|
|
33
|
-
# @return [Hash{Integer =>
|
33
|
+
# @return [Hash{Integer => Solargraph::Parser::Snippet}]
|
34
34
|
def comments
|
35
35
|
finalize
|
36
36
|
@comments
|
@@ -235,6 +235,7 @@ module Solargraph
|
|
235
235
|
# @return [Hash{Integer => String}]
|
236
236
|
def associated_comments
|
237
237
|
@associated_comments ||= begin
|
238
|
+
# @type [Hash{Integer => String}]
|
238
239
|
result = {}
|
239
240
|
buffer = String.new('')
|
240
241
|
# @type [Integer, nil]
|
@@ -317,7 +318,7 @@ module Solargraph
|
|
317
318
|
@string_nodes ||= string_nodes_in(node)
|
318
319
|
end
|
319
320
|
|
320
|
-
# @return [Array<Range>]
|
321
|
+
# @return [Array<Solargraph::Range>]
|
321
322
|
def comment_ranges
|
322
323
|
@comment_ranges ||= comments.values.map(&:range)
|
323
324
|
end
|
@@ -386,6 +387,7 @@ module Solargraph
|
|
386
387
|
# @return [Integer]
|
387
388
|
attr_writer :version
|
388
389
|
|
390
|
+
# @return [void]
|
389
391
|
def finalize
|
390
392
|
return if @finalized && changes.empty?
|
391
393
|
|
@@ -440,6 +442,7 @@ module Solargraph
|
|
440
442
|
# @return [String]
|
441
443
|
attr_writer :repaired
|
442
444
|
|
445
|
+
# @return [String]
|
443
446
|
def repaired
|
444
447
|
finalize
|
445
448
|
@repaired
|
@@ -65,7 +65,7 @@ module Solargraph
|
|
65
65
|
# position. Locals can be local variables, method parameters, or block
|
66
66
|
# parameters. The array starts with the nearest local pin.
|
67
67
|
#
|
68
|
-
# @return [::Array<Solargraph::Pin::
|
68
|
+
# @return [::Array<Solargraph::Pin::LocalVariable>]
|
69
69
|
def locals
|
70
70
|
@locals ||= source_map.locals_at(location)
|
71
71
|
end
|
@@ -3,15 +3,18 @@
|
|
3
3
|
module Solargraph
|
4
4
|
class SourceMap
|
5
5
|
class Data
|
6
|
+
# @param source [Solargraph::Source]
|
6
7
|
def initialize source
|
7
8
|
@source = source
|
8
9
|
end
|
9
10
|
|
11
|
+
# @return [Array<Solargraph::Pin::Base>]
|
10
12
|
def pins
|
11
13
|
generate
|
12
14
|
@pins || []
|
13
15
|
end
|
14
16
|
|
17
|
+
# @return [Array<Solargraph::LocalVariable>]
|
15
18
|
def locals
|
16
19
|
generate
|
17
20
|
@locals || []
|
@@ -19,6 +22,7 @@ module Solargraph
|
|
19
22
|
|
20
23
|
private
|
21
24
|
|
25
|
+
# @return [void]
|
22
26
|
def generate
|
23
27
|
return if @generated
|
24
28
|
|
@@ -70,6 +70,7 @@ module Solargraph
|
|
70
70
|
# @param comment [String]
|
71
71
|
# @return [void]
|
72
72
|
def process_comment source_position, comment_position, comment
|
73
|
+
# @sg-ignore Wrong argument type for String#=~: object expected String::_MatchAgainst<String, undefined>, received Regexp
|
73
74
|
return unless comment.encode('UTF-8', invalid: :replace, replace: '?') =~ DIRECTIVE_REGEXP
|
74
75
|
cmnt = remove_inline_comment_hashes(comment)
|
75
76
|
parse = Solargraph::Source.parse_docstring(cmnt)
|
@@ -163,7 +164,7 @@ module Solargraph
|
|
163
164
|
end
|
164
165
|
end
|
165
166
|
when 'visibility'
|
166
|
-
|
167
|
+
|
167
168
|
kind = directive.tag.text&.to_sym
|
168
169
|
return unless [:private, :protected, :public].include?(kind)
|
169
170
|
|
@@ -182,7 +183,7 @@ module Solargraph
|
|
182
183
|
pin.instance_variable_set(:@visibility, kind)
|
183
184
|
end
|
184
185
|
end
|
185
|
-
|
186
|
+
|
186
187
|
when 'parse'
|
187
188
|
begin
|
188
189
|
ns = closure_at(source_position)
|
@@ -244,6 +245,7 @@ module Solargraph
|
|
244
245
|
|
245
246
|
# @return [void]
|
246
247
|
def process_comment_directives
|
248
|
+
# @sg-ignore Wrong argument type for String#=~: object expected String::_MatchAgainst<String, undefined>, received Regexp
|
247
249
|
return unless @code.encode('UTF-8', invalid: :replace, replace: '?') =~ DIRECTIVE_REGEXP
|
248
250
|
code_lines = @code.lines
|
249
251
|
@source.associated_comments.each do |line, comments|
|