solargraph 0.56.2 → 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 +42 -0
- 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 +1 -0
- data/lib/solargraph/convention/data_definition/data_definition_node.rb +3 -1
- data/lib/solargraph/convention/data_definition.rb +2 -1
- data/lib/solargraph/convention/gemspec.rb +1 -1
- data/lib/solargraph/convention/struct_definition/struct_assignment_node.rb +1 -0
- data/lib/solargraph/convention/struct_definition/struct_definition_node.rb +3 -1
- data/lib/solargraph/convention/struct_definition.rb +36 -13
- data/lib/solargraph/convention.rb +31 -2
- data/lib/solargraph/diagnostics/rubocop.rb +6 -1
- data/lib/solargraph/diagnostics/rubocop_helpers.rb +1 -1
- data/lib/solargraph/doc_map.rb +40 -12
- 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 +8 -15
- 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 +1 -1
- data/lib/solargraph/parser/node_processor.rb +6 -2
- 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/if_node.rb +2 -0
- data/lib/solargraph/parser/parser_gem/node_processors/masgn_node.rb +3 -0
- data/lib/solargraph/parser/parser_gem/node_processors/send_node.rb +35 -14
- data/lib/solargraph/parser/region.rb +3 -0
- data/lib/solargraph/parser/snippet.rb +2 -0
- data/lib/solargraph/pin/base.rb +50 -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 +8 -5
- 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 +7 -5
- 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 +0 -2
- data/lib/solargraph/workspace/require_paths.rb +98 -0
- data/lib/solargraph/workspace.rb +16 -48
- data/lib/solargraph/yard_map/mapper/to_method.rb +2 -2
- data/lib/solargraph/yardoc.rb +16 -3
- data/lib/solargraph.rb +2 -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 +123 -9
- data/lib/.rubocop.yml +0 -22
data/.yardopts
CHANGED
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,45 @@
|
|
1
|
+
## 0.57.0 - September 16, 2025
|
2
|
+
- Support ActiveSupport::Concern pattern for class methods (#948)
|
3
|
+
- More CI checks (#996)
|
4
|
+
- Linting / type annotation fixes (#999)
|
5
|
+
- Avoid overlapping chdir calls in multiple threads (#1007)
|
6
|
+
- Fix kwarg generation in ApiMap::SourceToYard (#1003)
|
7
|
+
- Enable Steep typechecking of Solargraph code (#1004)
|
8
|
+
- Fix convention requires (#1008)
|
9
|
+
- Plugin Util: Add Combination Priority (#1010)
|
10
|
+
- [regression] Fix crash while typechecking files with Struct use (#1031)
|
11
|
+
- Remove yard reference from gemfile (#1033)
|
12
|
+
- Allow newer RBS gem versions, exclude incompatible ones (#995)
|
13
|
+
- Look for external requires before cataloging bench (#1021)
|
14
|
+
- Remove Library#folding_ranges (#904)
|
15
|
+
- Complain in strong type-checking if an @sg-ignore line is not needed (#1011)
|
16
|
+
- Document a log level env variable (#894)
|
17
|
+
- Fix hole in type checking evaluation (#1009)
|
18
|
+
- Improve typechecking error message (#1014)
|
19
|
+
- Internal strict type-checking fixes (#1013)
|
20
|
+
- Reproduce and fix a ||= (or-asgn) evaluation issue (#1017)
|
21
|
+
- Define closure for Pin::Symbol, for completeness (#1027)
|
22
|
+
- Fix 'all!' config to reporters (#1018)
|
23
|
+
- Fix DocMap.all_rbs_collection_gems_in_memory return type (#1037)
|
24
|
+
- Fix RuboCop linting errors in regular expressions (#1038)
|
25
|
+
- Resolve class aliases via Constant pins (#1029)
|
26
|
+
- Speed-up LSP completion response times (#1035)
|
27
|
+
- Revert "Resolve class aliases via Constant pins (#1029)" (#1041)
|
28
|
+
- Avoid stack errors when resolving method aliases (#1040)
|
29
|
+
- [regression] Refine order of object convention method pins (#1036)
|
30
|
+
- Fix crash while generating activesupport pins (#1043)
|
31
|
+
- Type annotation improvements (#1016)
|
32
|
+
- Resolve class aliases via Constant pins (#1048)
|
33
|
+
- Understand "Parser::AST::Node < AST::Node" in RBS (#1060)
|
34
|
+
- Factor out require_paths logic to its own class (#1062)
|
35
|
+
- Fix type errors found in strong typechecking (#1045)
|
36
|
+
- Run plugin specs separately for perf insights (#1046)
|
37
|
+
- Run specs from solargraph-rails configured against current code in CI (#892)
|
38
|
+
- Fix Convention/Plugin pins not being updated on file change (#1028)
|
39
|
+
- Fix solargraph-rails check (#1073)
|
40
|
+
- Flow sensitive typing handles x.is_a? without an argument (#1070)
|
41
|
+
- Refactor reference pin handling (#1058)
|
42
|
+
|
1
43
|
## 0.56.2 - July 29, 2025
|
2
44
|
- Add support for Ruby Data.define (#970)
|
3
45
|
- Ensure that pin locations are always populated (#965)
|
data/README.md
CHANGED
@@ -53,7 +53,7 @@ Solargraph's behavior can be controlled via optional [configuration](https://sol
|
|
53
53
|
|
54
54
|
### Plugins
|
55
55
|
|
56
|
-
Solargraph supports [plugins](https://solargraph.org/guides/plugins) that
|
56
|
+
Solargraph supports [plugins](https://solargraph.org/guides/plugins) that implement their own Solargraph features, such as diagnostics reporters and conventions to provide LSP features and type-checking, e.g. for frameworks which use metaprogramming and/or DSLs.
|
57
57
|
|
58
58
|
For better Rails support, please consider using [solargraph-rails](https://github.com/iftheshoefritz/solargraph-rails/)
|
59
59
|
|
@@ -65,7 +65,7 @@ The RSpec framework is supported via [solargraph-rspec](https://github.com/lekem
|
|
65
65
|
|
66
66
|
When editing code, a `require` call that references a gem will pull the documentation into the code maps and include the gem's API in code completion and intellisense. Solargraph automatically generates code maps from installed gems, based on the YARD or RBS type information inside the gem. You can also eagerly cache gem documentation with the `solargraph gems` command.
|
67
67
|
|
68
|
-
If your project automatically requires bundled
|
68
|
+
If your project automatically requires bundled gem with the `Bundler.require` statement, Solargraph will add all of the Gemfile's default dependencies to the map.
|
69
69
|
|
70
70
|
To ensure you have types for gems which contain neither RBS nor YARD
|
71
71
|
information, use
|
@@ -81,7 +81,7 @@ Once installed, you can also insert your own local overrides and definitions in
|
|
81
81
|
|
82
82
|
### Type Checking
|
83
83
|
|
84
|
-
As of version 0.33.0, Solargraph includes a [type checker](https://github.com/castwide/solargraph/issues/192) that uses a combination of YARD tags and code analysis to report missing type definitions. In strict mode, it performs type inference to determine whether the tags match the types it detects from code.
|
84
|
+
As of version 0.33.0, Solargraph includes a [type checker](https://github.com/castwide/solargraph/issues/192) that uses a combination of YARD tags and code analysis to report missing type definitions. In strict mode, it performs type inference to determine whether the tags match the types it detects from code. In strong mode it will ask you to clarify your intentions by adding annotations for better validation.
|
85
85
|
|
86
86
|
### The Documentation Cache
|
87
87
|
|
@@ -101,7 +101,7 @@ Run `bundle install` and optionally use `bundle exec solargraph gems` to generat
|
|
101
101
|
|
102
102
|
In order to make sure you're using the correct dependencies, you can start the language server with Bundler. In VS Code, there's a `solargraph.useBundler` option. Other clients will vary, but the command you probably want to run is `bundle exec solargraph socket` or `bundle exec solargraph stdio`.
|
103
103
|
|
104
|
-
###
|
104
|
+
### RuboCop Version
|
105
105
|
|
106
106
|
If you have multiple versions of [`rubocop`](https://rubygems.org/gems/rubocop) installed and you would like to choose a version other than the latest to use, this specific version can be configured.
|
107
107
|
|
@@ -132,6 +132,10 @@ See [https://solargraph.org/guides](https://solargraph.org/guides) for more tips
|
|
132
132
|
|
133
133
|
### Development
|
134
134
|
|
135
|
+
To see more logging when typechecking or running specs, set the
|
136
|
+
`SOLARGRAPH_LOG` environment variable to `debug` or `info`. `warn` is
|
137
|
+
the default value.
|
138
|
+
|
135
139
|
Code contributions are always appreciated. Feel free to fork the repo and submit pull requests. Check for open issues that could use help. Start new issues to discuss changes that have a major impact on the code or require large time commitments.
|
136
140
|
|
137
141
|
### Sponsorship and Donation
|
data/Rakefile
CHANGED
@@ -1,12 +1,7 @@
|
|
1
1
|
require 'rake'
|
2
|
-
require 'rspec/core/rake_task'
|
3
2
|
require 'bundler/gem_tasks'
|
4
|
-
|
5
|
-
|
6
|
-
require 'rspec/core/rake_task'
|
7
|
-
RSpec::Core::RakeTask.new(:spec)
|
8
|
-
rescue LoadError
|
9
|
-
end
|
3
|
+
require 'fileutils'
|
4
|
+
require 'open3'
|
10
5
|
|
11
6
|
desc "Open a Pry session preloaded with this library"
|
12
7
|
task :console do
|
@@ -14,12 +9,129 @@ task :console do
|
|
14
9
|
end
|
15
10
|
|
16
11
|
desc "Run the type checker"
|
17
|
-
task :
|
18
|
-
|
12
|
+
task typecheck: [:typecheck_typed]
|
13
|
+
|
14
|
+
desc "Run the type checker at typed level - return code issues provable without annotations being correct"
|
15
|
+
task :typecheck_typed do
|
16
|
+
sh "SOLARGRAPH_ASSERTS=on bundle exec solargraph typecheck --level typed"
|
17
|
+
end
|
18
|
+
|
19
|
+
desc "Run the type checker at strict level - report issues using type annotations"
|
20
|
+
task :typecheck_strict do
|
21
|
+
sh "SOLARGRAPH_ASSERTS=on bundle exec solargraph typecheck --level strict"
|
22
|
+
end
|
23
|
+
|
24
|
+
desc "Run the type checker at strong level - enforce that type annotations exist"
|
25
|
+
task :typecheck_strong do
|
26
|
+
sh "SOLARGRAPH_ASSERTS=on bundle exec solargraph typecheck --level strong"
|
27
|
+
end
|
28
|
+
|
29
|
+
desc "Run the type checker at alpha level - run high-false-alarm checks"
|
30
|
+
task :typecheck_alpha do
|
31
|
+
sh "SOLARGRAPH_ASSERTS=on bundle exec solargraph typecheck --level alpha"
|
32
|
+
end
|
33
|
+
|
34
|
+
desc "Run RSpec tests, starting with the ones that failed last time"
|
35
|
+
task spec: %i[spec_failed undercover_no_fail full_spec] do
|
36
|
+
undercover
|
37
|
+
end
|
38
|
+
|
39
|
+
desc "Run all RSpec tests"
|
40
|
+
task :full_spec do
|
41
|
+
warn 'starting spec'
|
42
|
+
sh 'TEST_COVERAGE_COMMAND_NAME=full-new bundle exec rspec' # --profile'
|
43
|
+
warn 'ending spec'
|
44
|
+
# move coverage/full-new to coverage/full on success so that we
|
45
|
+
# always have the last successful run's 'coverage info
|
46
|
+
FileUtils.rm_rf('coverage/full')
|
47
|
+
FileUtils.mv('coverage/full-new', 'coverage/full')
|
48
|
+
end
|
49
|
+
|
50
|
+
# @sg-ignore #undercover return type could not be inferred
|
51
|
+
# @return [Process::Status]
|
52
|
+
def undercover
|
53
|
+
simplecov_collate
|
54
|
+
cmd = 'bundle exec undercover ' \
|
55
|
+
'--simplecov coverage/combined/coverage.json ' \
|
56
|
+
'--exclude-files "Rakefile,spec/*,spec/**/*,lib/solargraph/version.rb" ' \
|
57
|
+
'--compare origin/master'
|
58
|
+
output, status = Bundler.with_unbundled_env do
|
59
|
+
Open3.capture2e(cmd)
|
60
|
+
end
|
61
|
+
puts output
|
62
|
+
$stdout.flush
|
63
|
+
status
|
64
|
+
rescue StandardError => e
|
65
|
+
warn "hit error: #{e.message}"
|
66
|
+
warn "Backtrace:\n#{e.backtrace.join("\n")}"
|
67
|
+
warn "output: #{output}"
|
68
|
+
puts "Flushing"
|
69
|
+
$stdout.flush
|
70
|
+
raise
|
71
|
+
end
|
72
|
+
|
73
|
+
desc "Check PR coverage"
|
74
|
+
task :undercover do
|
75
|
+
raise "Undercover failed" unless undercover.success?
|
76
|
+
end
|
77
|
+
|
78
|
+
desc "Branch-focused fast-feedback quality/spec/coverage checks"
|
79
|
+
task test: %i[overcommit spec typecheck] do
|
80
|
+
# do these in order
|
81
|
+
Rake::Task['typecheck_strict'].invoke
|
82
|
+
Rake::Task['typecheck_strong'].invoke
|
83
|
+
Rake::Task['typecheck_alpha'].invoke
|
84
|
+
end
|
85
|
+
|
86
|
+
desc "Re-run failed specs. Add --fail-fast in your .rspec-local file if desired."
|
87
|
+
task :spec_failed do
|
88
|
+
# allow user to check out any persistent failures while looking for
|
89
|
+
# more in the whole test suite
|
90
|
+
sh 'TEST_COVERAGE_COMMAND_NAME=next-failure bundle exec rspec --only-failures || true'
|
91
|
+
end
|
92
|
+
|
93
|
+
desc "Run undercover and show output without failing the task if it fails"
|
94
|
+
task :undercover_no_fail do
|
95
|
+
undercover
|
96
|
+
rescue StandardError
|
97
|
+
puts "Undercover failed, but continuing with other tasks."
|
98
|
+
end
|
99
|
+
|
100
|
+
# @return [void]
|
101
|
+
def simplecov_collate
|
102
|
+
require 'simplecov'
|
103
|
+
require 'simplecov-lcov'
|
104
|
+
require 'undercover/simplecov_formatter'
|
105
|
+
|
106
|
+
SimpleCov.collate(Dir["coverage/{next-failure,full,ad-hoc}/.resultset.json"]) do
|
107
|
+
cname = 'combined'
|
108
|
+
command_name cname
|
109
|
+
new_dir = File.join('coverage', cname)
|
110
|
+
coverage_dir new_dir
|
111
|
+
|
112
|
+
formatter \
|
113
|
+
SimpleCov::Formatter::MultiFormatter
|
114
|
+
.new([
|
115
|
+
SimpleCov::Formatter::HTMLFormatter,
|
116
|
+
SimpleCov::Formatter::Undercover,
|
117
|
+
SimpleCov::Formatter::LcovFormatter
|
118
|
+
])
|
119
|
+
SimpleCov::Formatter::LcovFormatter.config.report_with_single_file = true
|
120
|
+
end
|
121
|
+
puts "Simplecov collated results into coverage/combined/.resultset.json"
|
122
|
+
rescue StandardError => e
|
123
|
+
puts "Simplecov collate failed: #{e.message}"
|
124
|
+
ensure
|
125
|
+
$stdout.flush
|
126
|
+
end
|
127
|
+
|
128
|
+
desc 'Add incremental coverage for rapid iteration with undercover'
|
129
|
+
task :simplecov_collate do
|
130
|
+
simplecov_collate
|
19
131
|
end
|
20
132
|
|
21
|
-
desc "
|
22
|
-
task :
|
23
|
-
|
24
|
-
|
133
|
+
desc "Show quality checks on this development branch so far, including any staged files"
|
134
|
+
task :overcommit do
|
135
|
+
# OVERCOMMIT_DEBUG=1 will show more detail
|
136
|
+
sh 'SOLARGRAPH_ASSERTS=on bundle exec overcommit --run --diff origin/master'
|
25
137
|
end
|
@@ -4,9 +4,9 @@ module Solargraph
|
|
4
4
|
class ApiMap
|
5
5
|
class Cache
|
6
6
|
def initialize
|
7
|
-
# @type [Hash{
|
7
|
+
# @type [Hash{String => Array<Pin::Method>}]
|
8
8
|
@methods = {}
|
9
|
-
# @type [Hash{
|
9
|
+
# @type [Hash{String, Array<String> => Array<Pin::Base>}]
|
10
10
|
@constants = {}
|
11
11
|
# @type [Hash{String => String}]
|
12
12
|
@qualified_namespaces = {}
|
@@ -101,6 +101,7 @@ module Solargraph
|
|
101
101
|
|
102
102
|
private
|
103
103
|
|
104
|
+
# @return [Array<Object>]
|
104
105
|
def all_caches
|
105
106
|
[@methods, @constants, @qualified_namespaces, @receiver_definitions, @clips]
|
106
107
|
end
|
@@ -0,0 +1,218 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Solargraph
|
4
|
+
class ApiMap
|
5
|
+
# Methods for handling constants.
|
6
|
+
#
|
7
|
+
class Constants
|
8
|
+
# @param store [Store]
|
9
|
+
def initialize store
|
10
|
+
@store = store
|
11
|
+
end
|
12
|
+
|
13
|
+
# Resolve a name to a fully qualified namespace or constant.
|
14
|
+
#
|
15
|
+
# @param name [String]
|
16
|
+
# @param gates [Array<Array<String>, String>]
|
17
|
+
# @return [String, nil]
|
18
|
+
def resolve(name, *gates)
|
19
|
+
return store.get_path_pins(name[2..]).first&.path if name.start_with?('::')
|
20
|
+
|
21
|
+
flat = gates.flatten
|
22
|
+
flat.push '' if flat.empty?
|
23
|
+
cached_resolve[[name, flat]] || resolve_and_cache(name, flat)
|
24
|
+
end
|
25
|
+
|
26
|
+
# Get a fully qualified namespace from a reference pin.
|
27
|
+
#
|
28
|
+
# @param pin [Pin::Reference]
|
29
|
+
# @return [String, nil]
|
30
|
+
def dereference pin
|
31
|
+
resolve(pin.name, pin.reference_gates)
|
32
|
+
end
|
33
|
+
|
34
|
+
# Collect a list of all constants defined in the specified gates.
|
35
|
+
#
|
36
|
+
# @param gates [Array<Array<String>, String>]
|
37
|
+
# @return [Array<Pin::Base>]
|
38
|
+
def collect(*gates)
|
39
|
+
flat = gates.flatten
|
40
|
+
cached_collect[flat] || collect_and_cache(flat)
|
41
|
+
end
|
42
|
+
|
43
|
+
# Determine fully qualified tag for a given tag used inside the
|
44
|
+
# definition of another tag ("context"). This method will start
|
45
|
+
# the search in the specified context until it finds a match for
|
46
|
+
# the tag.
|
47
|
+
#
|
48
|
+
# Does not recurse into qualifying the type parameters, but
|
49
|
+
# returns any which were passed in unchanged.
|
50
|
+
#
|
51
|
+
# @param tag [String, nil] The namespace to
|
52
|
+
# match, complete with generic parameters set to appropriate
|
53
|
+
# values if available
|
54
|
+
# @param context_tag [String] The fully qualified context in which
|
55
|
+
# the tag was referenced; start from here to resolve the name.
|
56
|
+
# Should not be prefixed with '::'.
|
57
|
+
# @return [String, nil] fully qualified tag
|
58
|
+
def qualify tag, context_tag = ''
|
59
|
+
return tag if ['Boolean', 'self', nil].include?(tag)
|
60
|
+
|
61
|
+
type = ComplexType.try_parse(tag)
|
62
|
+
return unless type.defined?
|
63
|
+
return tag if type.literal?
|
64
|
+
|
65
|
+
context_type = ComplexType.try_parse(context_tag)
|
66
|
+
return unless context_type.defined?
|
67
|
+
|
68
|
+
fqns = qualify_namespace(type.rooted_namespace, context_type.rooted_namespace)
|
69
|
+
return unless fqns
|
70
|
+
|
71
|
+
fqns + type.substring
|
72
|
+
end
|
73
|
+
|
74
|
+
# @return [void]
|
75
|
+
def clear
|
76
|
+
[cached_collect, cached_resolve].each(&:clear)
|
77
|
+
end
|
78
|
+
|
79
|
+
private
|
80
|
+
|
81
|
+
# @return [Store]
|
82
|
+
attr_reader :store
|
83
|
+
|
84
|
+
# @param name [String]
|
85
|
+
# @param gates [Array<String>]
|
86
|
+
# @return [String, nil]
|
87
|
+
def resolve_and_cache name, gates
|
88
|
+
cached_resolve[[name, gates]] = resolve_uncached(name, gates)
|
89
|
+
end
|
90
|
+
|
91
|
+
# @param name [String]
|
92
|
+
# @param gates [Array<String>]
|
93
|
+
# @return [String, nil]
|
94
|
+
def resolve_uncached name, gates
|
95
|
+
parts = name.split('::')
|
96
|
+
here = parts.shift
|
97
|
+
resolved = simple_resolve(here, gates)
|
98
|
+
return resolved if parts.empty? || resolved.nil?
|
99
|
+
|
100
|
+
final = "#{resolved}::#{parts.join('::')}".sub(/^::/, '')
|
101
|
+
final if store.namespace_exists?(final)
|
102
|
+
end
|
103
|
+
|
104
|
+
# @param name [String]
|
105
|
+
# @param gates [Array<String>]
|
106
|
+
# @return [String, nil]
|
107
|
+
def simple_resolve name, gates
|
108
|
+
gates.each do |gate|
|
109
|
+
here = "#{gate}::#{name}".sub(/^::/, '').sub(/::$/, '')
|
110
|
+
return here if store.namespace_exists?(here)
|
111
|
+
end
|
112
|
+
nil
|
113
|
+
end
|
114
|
+
|
115
|
+
# @param gates [Array<String>]
|
116
|
+
# @return [Array<Pin::Base>]
|
117
|
+
def collect_and_cache gates
|
118
|
+
skip = Set.new
|
119
|
+
cached_collect[gates] = gates.flat_map do |gate|
|
120
|
+
inner_get_constants(gate, %i[public private], skip)
|
121
|
+
end
|
122
|
+
end
|
123
|
+
|
124
|
+
# @return [Hash{Array(Name, Array<String>) => String, nil}]
|
125
|
+
def cached_resolve
|
126
|
+
@cached_resolve ||= {}
|
127
|
+
end
|
128
|
+
|
129
|
+
# @return [Hash{Array<String> => Array<Pin::Base>}]
|
130
|
+
def cached_collect
|
131
|
+
@cached_collect ||= {}
|
132
|
+
end
|
133
|
+
|
134
|
+
# Determine fully qualified namespace for a given namespace used
|
135
|
+
# inside the definition of another tag ("context"). This method
|
136
|
+
# will start the search in the specified context until it finds a
|
137
|
+
# match for the namespace.
|
138
|
+
#
|
139
|
+
# @param namespace [String, nil] The namespace to
|
140
|
+
# match
|
141
|
+
# @param context_namespace [String] The context namespace in which the
|
142
|
+
# tag was referenced; start from here to resolve the name
|
143
|
+
# @return [String, nil] fully qualified namespace
|
144
|
+
def qualify_namespace namespace, context_namespace = ''
|
145
|
+
if namespace.start_with?('::')
|
146
|
+
inner_qualify(namespace[2..], '', Set.new)
|
147
|
+
else
|
148
|
+
inner_qualify(namespace, context_namespace, Set.new)
|
149
|
+
end
|
150
|
+
end
|
151
|
+
|
152
|
+
# @param name [String] Namespace to fully qualify
|
153
|
+
# @param root [String] The context to search
|
154
|
+
# @param skip [Set<String>] Contexts already searched
|
155
|
+
# @return [String, nil] Fully qualified ("rooted") namespace
|
156
|
+
def inner_qualify name, root, skip
|
157
|
+
return name if name == ComplexType::GENERIC_TAG_NAME
|
158
|
+
return nil if name.nil?
|
159
|
+
return nil if skip.include?(root)
|
160
|
+
skip.add root
|
161
|
+
possibles = []
|
162
|
+
if name == ''
|
163
|
+
return '' if root == ''
|
164
|
+
|
165
|
+
inner_qualify(root, '', skip)
|
166
|
+
else
|
167
|
+
return name if root == '' && store.namespace_exists?(name)
|
168
|
+
roots = root.to_s.split('::')
|
169
|
+
while roots.length.positive?
|
170
|
+
fqns = "#{roots.join('::')}::#{name}"
|
171
|
+
return fqns if store.namespace_exists?(fqns)
|
172
|
+
incs = store.get_includes(roots.join('::'))
|
173
|
+
incs.each do |inc|
|
174
|
+
foundinc = inner_qualify(name, inc.parametrized_tag.to_s, skip)
|
175
|
+
possibles.push foundinc unless foundinc.nil?
|
176
|
+
end
|
177
|
+
roots.pop
|
178
|
+
end
|
179
|
+
if possibles.empty?
|
180
|
+
incs = store.get_includes('')
|
181
|
+
incs.each do |inc|
|
182
|
+
foundinc = inner_qualify(name, inc.parametrized_tag.to_s, skip)
|
183
|
+
possibles.push foundinc unless foundinc.nil?
|
184
|
+
end
|
185
|
+
end
|
186
|
+
return name if store.namespace_exists?(name)
|
187
|
+
possibles.last
|
188
|
+
end
|
189
|
+
end
|
190
|
+
|
191
|
+
# @param fqns [String]
|
192
|
+
# @param visibility [Array<Symbol>]
|
193
|
+
# @param skip [Set<String>]
|
194
|
+
# @return [Array<Pin::Base>]
|
195
|
+
def inner_get_constants fqns, visibility, skip
|
196
|
+
return [] if fqns.nil? || skip.include?(fqns)
|
197
|
+
skip.add fqns
|
198
|
+
result = []
|
199
|
+
|
200
|
+
store.get_prepends(fqns).each do |pre|
|
201
|
+
pre_fqns = resolve(pre.name, pre.closure.gates - skip.to_a)
|
202
|
+
result.concat inner_get_constants(pre_fqns, [:public], skip)
|
203
|
+
end
|
204
|
+
result.concat(store.get_constants(fqns, visibility).sort { |a, b| a.name <=> b.name })
|
205
|
+
store.get_includes(fqns).each do |pin|
|
206
|
+
inc_fqns = resolve(pin.name, pin.closure.gates - skip.to_a)
|
207
|
+
result.concat inner_get_constants(inc_fqns, [:public], skip)
|
208
|
+
end
|
209
|
+
sc_ref = store.get_superclass(fqns)
|
210
|
+
if sc_ref
|
211
|
+
fqsc = dereference(sc_ref)
|
212
|
+
result.concat inner_get_constants(fqsc, [:public], skip) unless %w[Object BasicObject].include?(fqsc)
|
213
|
+
end
|
214
|
+
result
|
215
|
+
end
|
216
|
+
end
|
217
|
+
end
|
218
|
+
end
|
@@ -15,6 +15,9 @@ module Solargraph
|
|
15
15
|
@pins ||= []
|
16
16
|
end
|
17
17
|
|
18
|
+
# @return [Set<String>]
|
19
|
+
attr_reader :namespaces
|
20
|
+
|
18
21
|
# @return [Hash{String => Array<Pin::Namespace>}]
|
19
22
|
def namespace_hash
|
20
23
|
@namespace_hash ||= Hash.new { |h, k| h[k] = [] }
|
@@ -36,30 +39,37 @@ module Solargraph
|
|
36
39
|
def pins_by_class klass
|
37
40
|
# @type [Set<Solargraph::Pin::Base>]
|
38
41
|
s = Set.new
|
42
|
+
# @sg-ignore need to support destructured args in blocks
|
39
43
|
@pin_select_cache[klass] ||= pin_class_hash.each_with_object(s) { |(key, o), n| n.merge(o) if key <= klass }
|
40
44
|
end
|
41
45
|
|
42
|
-
# @return [Hash{String => Array<
|
46
|
+
# @return [Hash{String => Array<String>}]
|
43
47
|
def include_references
|
44
48
|
@include_references ||= Hash.new { |h, k| h[k] = [] }
|
45
49
|
end
|
46
50
|
|
47
|
-
# @return [Hash{String => Array<Pin::Reference::
|
51
|
+
# @return [Hash{String => Array<Pin::Reference::Include>}]
|
52
|
+
def include_reference_pins
|
53
|
+
@include_reference_pins ||= Hash.new { |h, k| h[k] = [] }
|
54
|
+
end
|
55
|
+
|
56
|
+
# @return [Hash{String => Array<String>}]
|
48
57
|
def extend_references
|
49
58
|
@extend_references ||= Hash.new { |h, k| h[k] = [] }
|
50
59
|
end
|
51
60
|
|
52
|
-
# @return [Hash{String => Array<
|
61
|
+
# @return [Hash{String => Array<String>}]
|
53
62
|
def prepend_references
|
54
63
|
@prepend_references ||= Hash.new { |h, k| h[k] = [] }
|
55
64
|
end
|
56
65
|
|
57
|
-
# @return [Hash{String => Array<
|
66
|
+
# @return [Hash{String => Array<String>}]
|
58
67
|
def superclass_references
|
59
68
|
@superclass_references ||= Hash.new { |h, k| h[k] = [] }
|
60
69
|
end
|
61
70
|
|
62
|
-
# @param pins [
|
71
|
+
# @param pins [Enumerable<Pin::Base>]
|
72
|
+
# @return [self]
|
63
73
|
def merge pins
|
64
74
|
deep_clone.catalog pins
|
65
75
|
end
|
@@ -69,6 +79,7 @@ module Solargraph
|
|
69
79
|
attr_writer :pins, :pin_select_cache, :namespace_hash, :pin_class_hash, :path_pin_hash, :include_references,
|
70
80
|
:extend_references, :prepend_references, :superclass_references
|
71
81
|
|
82
|
+
# @return [self]
|
72
83
|
def deep_clone
|
73
84
|
Index.allocate.tap do |copy|
|
74
85
|
copy.pin_select_cache = {}
|
@@ -83,8 +94,10 @@ module Solargraph
|
|
83
94
|
end
|
84
95
|
end
|
85
96
|
|
86
|
-
# @param new_pins [
|
97
|
+
# @param new_pins [Enumerable<Pin::Base>]
|
98
|
+
# @return [self]
|
87
99
|
def catalog new_pins
|
100
|
+
# @type [Hash{Class<generic<T>> => Set<generic<T>>}]
|
88
101
|
@pin_select_cache = {}
|
89
102
|
pins.concat new_pins
|
90
103
|
set = new_pins.to_set
|
@@ -108,29 +121,10 @@ module Solargraph
|
|
108
121
|
# @return [void]
|
109
122
|
def map_references klass, hash
|
110
123
|
pins_by_class(klass).each do |pin|
|
111
|
-
|
124
|
+
hash[pin.namespace].push pin
|
112
125
|
end
|
113
126
|
end
|
114
127
|
|
115
|
-
# Add references to a map
|
116
|
-
#
|
117
|
-
# @param hash [Hash{String => Array<Pin::Reference>}]
|
118
|
-
# @param reference_pin [Pin::Reference]
|
119
|
-
#
|
120
|
-
# @return [void]
|
121
|
-
def store_parametric_reference(hash, reference_pin)
|
122
|
-
referenced_ns = reference_pin.name
|
123
|
-
referenced_tag_params = reference_pin.generic_values
|
124
|
-
referenced_tag = referenced_ns +
|
125
|
-
if referenced_tag_params && referenced_tag_params.length > 0
|
126
|
-
"<" + referenced_tag_params.join(', ') + ">"
|
127
|
-
else
|
128
|
-
''
|
129
|
-
end
|
130
|
-
referencing_ns = reference_pin.namespace
|
131
|
-
hash[referencing_ns].push referenced_tag
|
132
|
-
end
|
133
|
-
|
134
128
|
# @return [void]
|
135
129
|
def map_overrides
|
136
130
|
pins_by_class(Pin::Reference::Override).each do |ovr|
|
@@ -45,12 +45,18 @@ module Solargraph
|
|
45
45
|
code_object_map[pin.path].docstring = pin.docstring
|
46
46
|
store.get_includes(pin.path).each do |ref|
|
47
47
|
include_object = code_object_at(pin.path, YARD::CodeObjects::ClassObject)
|
48
|
-
|
48
|
+
unless include_object.nil? || include_object.nil?
|
49
|
+
include_object.instance_mixins.push code_object_map[ref.parametrized_tag.to_s]
|
50
|
+
end
|
49
51
|
end
|
50
52
|
store.get_extends(pin.path).each do |ref|
|
51
53
|
extend_object = code_object_at(pin.path, YARD::CodeObjects::ClassObject)
|
52
|
-
|
53
|
-
|
54
|
+
next unless extend_object
|
55
|
+
code_object = code_object_map[ref.parametrized_tag.to_s]
|
56
|
+
next unless code_object
|
57
|
+
extend_object.class_mixins.push code_object
|
58
|
+
# @todo add spec showing why this next line is necessary
|
59
|
+
extend_object.instance_mixins.push code_object
|
54
60
|
end
|
55
61
|
end
|
56
62
|
store.method_pins.each do |pin|
|
@@ -67,7 +73,7 @@ module Solargraph
|
|
67
73
|
method_object.docstring = pin.docstring
|
68
74
|
method_object.visibility = pin.visibility || :public
|
69
75
|
method_object.parameters = pin.parameters.map do |p|
|
70
|
-
[p.
|
76
|
+
[p.full_name, p.asgn_code]
|
71
77
|
end
|
72
78
|
end
|
73
79
|
end
|