solargraph 0.58.1 → 0.59.0.dev.1

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 (162) hide show
  1. checksums.yaml +4 -4
  2. data/.envrc +3 -0
  3. data/.github/workflows/linting.yml +4 -5
  4. data/.github/workflows/plugins.yml +40 -36
  5. data/.github/workflows/rspec.yml +45 -13
  6. data/.github/workflows/typecheck.yml +2 -2
  7. data/.rubocop_todo.yml +27 -49
  8. data/README.md +3 -3
  9. data/Rakefile +1 -0
  10. data/lib/solargraph/api_map/cache.rb +110 -110
  11. data/lib/solargraph/api_map/constants.rb +289 -279
  12. data/lib/solargraph/api_map/index.rb +204 -193
  13. data/lib/solargraph/api_map/source_to_yard.rb +109 -97
  14. data/lib/solargraph/api_map/store.rb +387 -384
  15. data/lib/solargraph/api_map.rb +1000 -945
  16. data/lib/solargraph/complex_type/conformance.rb +176 -0
  17. data/lib/solargraph/complex_type/type_methods.rb +242 -228
  18. data/lib/solargraph/complex_type/unique_type.rb +632 -482
  19. data/lib/solargraph/complex_type.rb +549 -444
  20. data/lib/solargraph/convention/data_definition/data_definition_node.rb +93 -91
  21. data/lib/solargraph/convention/data_definition.rb +108 -105
  22. data/lib/solargraph/convention/struct_definition/struct_assignment_node.rb +62 -61
  23. data/lib/solargraph/convention/struct_definition/struct_definition_node.rb +103 -102
  24. data/lib/solargraph/convention/struct_definition.rb +168 -164
  25. data/lib/solargraph/diagnostics/require_not_found.rb +54 -53
  26. data/lib/solargraph/diagnostics/rubocop.rb +119 -118
  27. data/lib/solargraph/diagnostics/rubocop_helpers.rb +70 -68
  28. data/lib/solargraph/diagnostics/type_check.rb +56 -55
  29. data/lib/solargraph/doc_map.rb +200 -439
  30. data/lib/solargraph/equality.rb +34 -34
  31. data/lib/solargraph/gem_pins.rb +97 -98
  32. data/lib/solargraph/language_server/host/dispatch.rb +131 -130
  33. data/lib/solargraph/language_server/host/message_worker.rb +113 -112
  34. data/lib/solargraph/language_server/host/sources.rb +100 -99
  35. data/lib/solargraph/language_server/host.rb +883 -878
  36. data/lib/solargraph/language_server/message/extended/check_gem_version.rb +109 -114
  37. data/lib/solargraph/language_server/message/extended/document.rb +24 -23
  38. data/lib/solargraph/language_server/message/text_document/completion.rb +58 -56
  39. data/lib/solargraph/language_server/message/text_document/definition.rb +42 -40
  40. data/lib/solargraph/language_server/message/text_document/document_symbol.rb +28 -26
  41. data/lib/solargraph/language_server/message/text_document/formatting.rb +150 -148
  42. data/lib/solargraph/language_server/message/text_document/hover.rb +60 -58
  43. data/lib/solargraph/language_server/message/text_document/signature_help.rb +25 -24
  44. data/lib/solargraph/language_server/message/text_document/type_definition.rb +27 -25
  45. data/lib/solargraph/language_server/message/workspace/workspace_symbol.rb +25 -23
  46. data/lib/solargraph/library.rb +729 -683
  47. data/lib/solargraph/location.rb +87 -82
  48. data/lib/solargraph/logging.rb +57 -37
  49. data/lib/solargraph/parser/comment_ripper.rb +76 -69
  50. data/lib/solargraph/parser/flow_sensitive_typing.rb +483 -255
  51. data/lib/solargraph/parser/node_processor/base.rb +122 -92
  52. data/lib/solargraph/parser/node_processor.rb +63 -62
  53. data/lib/solargraph/parser/parser_gem/class_methods.rb +167 -149
  54. data/lib/solargraph/parser/parser_gem/node_chainer.rb +191 -166
  55. data/lib/solargraph/parser/parser_gem/node_methods.rb +506 -486
  56. data/lib/solargraph/parser/parser_gem/node_processors/and_node.rb +22 -22
  57. data/lib/solargraph/parser/parser_gem/node_processors/args_node.rb +61 -59
  58. data/lib/solargraph/parser/parser_gem/node_processors/begin_node.rb +24 -15
  59. data/lib/solargraph/parser/parser_gem/node_processors/block_node.rb +46 -46
  60. data/lib/solargraph/parser/parser_gem/node_processors/def_node.rb +60 -53
  61. data/lib/solargraph/parser/parser_gem/node_processors/if_node.rb +53 -23
  62. data/lib/solargraph/parser/parser_gem/node_processors/ivasgn_node.rb +41 -40
  63. data/lib/solargraph/parser/parser_gem/node_processors/lvasgn_node.rb +30 -29
  64. data/lib/solargraph/parser/parser_gem/node_processors/masgn_node.rb +61 -59
  65. data/lib/solargraph/parser/parser_gem/node_processors/opasgn_node.rb +98 -98
  66. data/lib/solargraph/parser/parser_gem/node_processors/or_node.rb +22 -0
  67. data/lib/solargraph/parser/parser_gem/node_processors/orasgn_node.rb +17 -17
  68. data/lib/solargraph/parser/parser_gem/node_processors/resbody_node.rb +39 -38
  69. data/lib/solargraph/parser/parser_gem/node_processors/sclass_node.rb +53 -52
  70. data/lib/solargraph/parser/parser_gem/node_processors/send_node.rb +296 -291
  71. data/lib/solargraph/parser/parser_gem/node_processors/when_node.rb +23 -0
  72. data/lib/solargraph/parser/parser_gem/node_processors/while_node.rb +33 -29
  73. data/lib/solargraph/parser/parser_gem/node_processors.rb +74 -70
  74. data/lib/solargraph/parser/region.rb +75 -69
  75. data/lib/solargraph/parser/snippet.rb +17 -17
  76. data/lib/solargraph/pin/base.rb +761 -729
  77. data/lib/solargraph/pin/base_variable.rb +418 -126
  78. data/lib/solargraph/pin/block.rb +126 -104
  79. data/lib/solargraph/pin/breakable.rb +13 -9
  80. data/lib/solargraph/pin/callable.rb +278 -231
  81. data/lib/solargraph/pin/closure.rb +68 -72
  82. data/lib/solargraph/pin/common.rb +94 -79
  83. data/lib/solargraph/pin/compound_statement.rb +55 -0
  84. data/lib/solargraph/pin/conversions.rb +124 -123
  85. data/lib/solargraph/pin/delegated_method.rb +131 -120
  86. data/lib/solargraph/pin/documenting.rb +115 -114
  87. data/lib/solargraph/pin/instance_variable.rb +38 -34
  88. data/lib/solargraph/pin/keyword.rb +16 -20
  89. data/lib/solargraph/pin/local_variable.rb +31 -75
  90. data/lib/solargraph/pin/method.rb +720 -672
  91. data/lib/solargraph/pin/method_alias.rb +42 -34
  92. data/lib/solargraph/pin/namespace.rb +121 -115
  93. data/lib/solargraph/pin/parameter.rb +338 -275
  94. data/lib/solargraph/pin/proxy_type.rb +40 -39
  95. data/lib/solargraph/pin/reference/override.rb +47 -47
  96. data/lib/solargraph/pin/reference/superclass.rb +17 -15
  97. data/lib/solargraph/pin/reference.rb +41 -39
  98. data/lib/solargraph/pin/search.rb +62 -61
  99. data/lib/solargraph/pin/signature.rb +69 -61
  100. data/lib/solargraph/pin/symbol.rb +53 -53
  101. data/lib/solargraph/pin/until.rb +18 -18
  102. data/lib/solargraph/pin/while.rb +18 -18
  103. data/lib/solargraph/pin.rb +46 -44
  104. data/lib/solargraph/pin_cache.rb +665 -245
  105. data/lib/solargraph/position.rb +118 -119
  106. data/lib/solargraph/range.rb +112 -112
  107. data/lib/solargraph/rbs_map/conversions.rb +846 -823
  108. data/lib/solargraph/rbs_map/core_map.rb +65 -58
  109. data/lib/solargraph/rbs_map/stdlib_map.rb +72 -43
  110. data/lib/solargraph/rbs_map.rb +217 -163
  111. data/lib/solargraph/shell.rb +397 -352
  112. data/lib/solargraph/source/chain/call.rb +372 -337
  113. data/lib/solargraph/source/chain/constant.rb +28 -26
  114. data/lib/solargraph/source/chain/hash.rb +35 -34
  115. data/lib/solargraph/source/chain/if.rb +29 -28
  116. data/lib/solargraph/source/chain/instance_variable.rb +34 -13
  117. data/lib/solargraph/source/chain/literal.rb +53 -48
  118. data/lib/solargraph/source/chain/or.rb +31 -23
  119. data/lib/solargraph/source/chain.rb +294 -291
  120. data/lib/solargraph/source/change.rb +89 -82
  121. data/lib/solargraph/source/cursor.rb +172 -166
  122. data/lib/solargraph/source/source_chainer.rb +204 -194
  123. data/lib/solargraph/source/updater.rb +59 -55
  124. data/lib/solargraph/source.rb +524 -498
  125. data/lib/solargraph/source_map/clip.rb +237 -226
  126. data/lib/solargraph/source_map/data.rb +37 -34
  127. data/lib/solargraph/source_map/mapper.rb +282 -259
  128. data/lib/solargraph/source_map.rb +220 -212
  129. data/lib/solargraph/type_checker/problem.rb +34 -32
  130. data/lib/solargraph/type_checker/rules.rb +157 -84
  131. data/lib/solargraph/type_checker.rb +895 -814
  132. data/lib/solargraph/version.rb +1 -1
  133. data/lib/solargraph/workspace/config.rb +257 -255
  134. data/lib/solargraph/workspace/gemspecs.rb +367 -0
  135. data/lib/solargraph/workspace/require_paths.rb +98 -97
  136. data/lib/solargraph/workspace.rb +362 -220
  137. data/lib/solargraph/yard_map/helpers.rb +45 -44
  138. data/lib/solargraph/yard_map/mapper/to_method.rb +134 -130
  139. data/lib/solargraph/yard_map/mapper/to_namespace.rb +32 -31
  140. data/lib/solargraph/yard_map/mapper.rb +84 -79
  141. data/lib/solargraph/yardoc.rb +97 -87
  142. data/lib/solargraph.rb +126 -105
  143. data/rbs/fills/rubygems/0/dependency.rbs +193 -0
  144. data/rbs/fills/tuple/tuple.rbs +28 -0
  145. data/rbs/shims/ast/0/node.rbs +5 -0
  146. data/rbs/shims/diff-lcs/1.5/diff-lcs.rbs +11 -0
  147. data/rbs_collection.yaml +1 -1
  148. data/solargraph.gemspec +2 -1
  149. metadata +22 -17
  150. data/lib/solargraph/type_checker/checks.rb +0 -124
  151. data/lib/solargraph/type_checker/param_def.rb +0 -37
  152. data/lib/solargraph/yard_map/to_method.rb +0 -89
  153. data/sig/shims/ast/0/node.rbs +0 -5
  154. /data/{sig → rbs}/shims/ast/2.4/.rbs_meta.yaml +0 -0
  155. /data/{sig → rbs}/shims/ast/2.4/ast.rbs +0 -0
  156. /data/{sig → rbs}/shims/parser/3.2.0.1/builders/default.rbs +0 -0
  157. /data/{sig → rbs}/shims/parser/3.2.0.1/manifest.yaml +0 -0
  158. /data/{sig → rbs}/shims/parser/3.2.0.1/parser.rbs +0 -0
  159. /data/{sig → rbs}/shims/parser/3.2.0.1/polyfill.rbs +0 -0
  160. /data/{sig → rbs}/shims/thor/1.2.0.1/.rbs_meta.yaml +0 -0
  161. /data/{sig → rbs}/shims/thor/1.2.0.1/manifest.yaml +0 -0
  162. /data/{sig → rbs}/shims/thor/1.2.0.1/thor.rbs +0 -0
@@ -1,87 +1,97 @@
1
- # frozen_string_literal: true
2
-
3
- require 'open3'
4
-
5
- module Solargraph
6
- # Methods for caching and loading YARD documentation for gems.
7
- #
8
- module Yardoc
9
- module_function
10
-
11
- # Build and cache a gem's yardoc and return the path. If the cache already
12
- # exists, do nothing and return the path.
13
- #
14
- # @param yard_plugins [Array<String>] The names of YARD plugins to use.
15
- # @param gemspec [Gem::Specification]
16
- # @return [String] The path to the cached yardoc.
17
- def cache(yard_plugins, gemspec)
18
- path = PinCache.yardoc_path gemspec
19
- return path if cached?(gemspec)
20
-
21
- unless Dir.exist? gemspec.gem_dir
22
- # Can happen in at least some (old?) RubyGems versions when we
23
- # have a gemspec describing a standard library like bundler.
24
- #
25
- # https://github.com/apiology/solargraph/actions/runs/17650140201/job/50158676842?pr=10
26
- Solargraph.logger.info { "Bad info from gemspec - #{gemspec.gem_dir} does not exist" }
27
- return path
28
- end
29
-
30
- Solargraph.logger.info "Caching yardoc for #{gemspec.name} #{gemspec.version}"
31
- cmd = "yardoc --db #{path} --no-output --plugin solargraph"
32
- yard_plugins.each { |plugin| cmd << " --plugin #{plugin}" }
33
- Solargraph.logger.debug { "Running: #{cmd}" }
34
- # @todo set these up to run in parallel
35
- stdout_and_stderr_str, status = Open3.capture2e(current_bundle_env_tweaks, cmd, chdir: gemspec.gem_dir)
36
- unless status.success?
37
- Solargraph.logger.warn { "YARD failed running #{cmd.inspect} in #{gemspec.gem_dir}" }
38
- Solargraph.logger.info stdout_and_stderr_str
39
- end
40
- path
41
- end
42
-
43
- # True if the gem yardoc is cached.
44
- #
45
- # @param gemspec [Gem::Specification]
46
- def cached?(gemspec)
47
- yardoc = File.join(PinCache.yardoc_path(gemspec), 'complete')
48
- File.exist?(yardoc)
49
- end
50
-
51
- # True if another process is currently building the yardoc cache.
52
- #
53
- # @param gemspec [Gem::Specification]
54
- def processing?(gemspec)
55
- yardoc = File.join(PinCache.yardoc_path(gemspec), 'processing')
56
- File.exist?(yardoc)
57
- end
58
-
59
- # Load a gem's yardoc and return its code objects.
60
- #
61
- # @note This method modifies the global YARD registry.
62
- #
63
- # @param gemspec [Gem::Specification]
64
- # @return [Array<YARD::CodeObjects::Base>]
65
- def load!(gemspec)
66
- YARD::Registry.load! PinCache.yardoc_path gemspec
67
- YARD::Registry.all
68
- end
69
-
70
- # If the BUNDLE_GEMFILE environment variable is set, we need to
71
- # make sure it's an absolute path, as we'll be changing
72
- # directories.
73
- #
74
- # 'bundle exec' sets an absolute path here, but at least the
75
- # overcommit gem does not, breaking on-the-fly documention with a
76
- # spawned yardoc command from our current bundle
77
- #
78
- # @return [Hash{String => String}] a hash of environment variables to override
79
- def current_bundle_env_tweaks
80
- tweaks = {}
81
- if ENV['BUNDLE_GEMFILE'] && !ENV['BUNDLE_GEMFILE'].empty?
82
- tweaks['BUNDLE_GEMFILE'] = File.expand_path(ENV['BUNDLE_GEMFILE'])
83
- end
84
- tweaks
85
- end
86
- end
87
- end
1
+ # frozen_string_literal: true
2
+
3
+ require 'open3'
4
+
5
+ module Solargraph
6
+ # Methods for caching and loading YARD documentation for gems.
7
+ #
8
+ module Yardoc
9
+ module_function
10
+
11
+ # Build and save a gem's yardoc into a given path.
12
+ #
13
+ # @param gem_yardoc_path [String] the path to the yardoc cache of a particular gem
14
+ # @param yard_plugins [Array<String>]
15
+ # @param gemspec [Gem::Specification]
16
+ #
17
+ # @return [void]
18
+ def build_docs gem_yardoc_path, yard_plugins, gemspec
19
+ return if docs_built?(gem_yardoc_path)
20
+
21
+ unless Dir.exist? gemspec.gem_dir
22
+ # Can happen in at least some (old?) RubyGems versions when we
23
+ # have a gemspec describing a standard library like bundler.
24
+ #
25
+ # https://github.com/apiology/solargraph/actions/runs/17650140201/job/50158676842?pr=10
26
+ Solargraph.logger.info { "Bad info from gemspec - #{gemspec.gem_dir} does not exist" }
27
+ return
28
+ end
29
+
30
+ Solargraph.logger.info "Caching yardoc for #{gemspec.name} #{gemspec.version}"
31
+ cmd = "yardoc --db #{gem_yardoc_path} --no-output --plugin solargraph"
32
+ yard_plugins.each { |plugin| cmd << " --plugin #{plugin}" }
33
+ Solargraph.logger.debug { "Running: #{cmd}" }
34
+ # @todo set these up to run in parallel
35
+ # @sg-ignore Our fill won't work properly due to an issue in
36
+ # Callable#arity_matches? - see comment there
37
+ stdout_and_stderr_str, status = Open3.capture2e(current_bundle_env_tweaks, cmd, chdir: gemspec.gem_dir)
38
+ return if status.success?
39
+ Solargraph.logger.warn { "YARD failed running #{cmd.inspect} in #{gemspec.gem_dir}" }
40
+ Solargraph.logger.info stdout_and_stderr_str
41
+ end
42
+
43
+ # @param gem_yardoc_path [String] the path to the yardoc cache of a particular gem
44
+ # @param gemspec [Gem::Specification, Bundler::LazySpecification]
45
+ # @param out [StringIO, IO, nil] where to log messages
46
+ # @return [Array<Pin::Base>]
47
+ def build_pins gem_yardoc_path, gemspec, out: $stderr
48
+ yardoc = load!(gem_yardoc_path)
49
+ YardMap::Mapper.new(yardoc, gemspec).map
50
+ end
51
+
52
+ # True if the gem yardoc is cached.
53
+ #
54
+ # @param gem_yardoc_path [String]
55
+ def docs_built? gem_yardoc_path
56
+ yardoc = File.join(gem_yardoc_path, 'complete')
57
+ File.exist?(yardoc)
58
+ end
59
+
60
+ # True if another process is currently building the yardoc cache.
61
+ #
62
+ # @param gem_yardoc_path [String] the path to the yardoc cache of a particular gem
63
+ def processing? gem_yardoc_path
64
+ yardoc = File.join(gem_yardoc_path, 'processing')
65
+ File.exist?(yardoc)
66
+ end
67
+
68
+ # Load a gem's yardoc and return its code objects.
69
+ #
70
+ # @note This method modifies the global YARD registry.
71
+ #
72
+ # @param gem_yardoc_path [String] the path to the yardoc cache of a particular gem
73
+ # @return [Array<YARD::CodeObjects::Base>]
74
+ def load! gem_yardoc_path
75
+ YARD::Registry.load! gem_yardoc_path
76
+ YARD::Registry.all
77
+ end
78
+
79
+ # If the BUNDLE_GEMFILE environment variable is set, we need to
80
+ # make sure it's an absolute path, as we'll be changing
81
+ # directories.
82
+ #
83
+ # 'bundle exec' sets an absolute path here, but at least the
84
+ # overcommit gem does not, breaking on-the-fly documention with a
85
+ # spawned yardoc command from our current bundle
86
+ #
87
+ # @return [Hash{String => String}] a hash of environment variables to override
88
+ def current_bundle_env_tweaks
89
+ tweaks = {}
90
+ # @sg-ignore Translate to something flow sensitive typing understands
91
+ if ENV['BUNDLE_GEMFILE'] && !ENV['BUNDLE_GEMFILE'].empty?
92
+ tweaks['BUNDLE_GEMFILE'] = File.expand_path(ENV['BUNDLE_GEMFILE'])
93
+ end
94
+ tweaks
95
+ end
96
+ end
97
+ end
data/lib/solargraph.rb CHANGED
@@ -1,105 +1,126 @@
1
- # frozen_string_literal: true
2
-
3
- Encoding.default_external = 'UTF-8'
4
-
5
- require 'bundler'
6
- require 'set'
7
- require 'yard-solargraph'
8
- require 'solargraph/yard_tags'
9
- require 'solargraph/version'
10
-
11
- # The top-level namespace for the Solargraph code mapping, documentation,
12
- # static analysis, and language server libraries.
13
- #
14
- module Solargraph
15
- class InvalidOffsetError < RangeError; end
16
- class DiagnosticsError < RuntimeError; end
17
- class FileNotFoundError < RuntimeError; end
18
- class SourceNotAvailableError < StandardError; end
19
- class ComplexTypeError < StandardError; end
20
- class WorkspaceTooLargeError < RuntimeError; end
21
- class BundleNotFoundError < StandardError; end
22
- class InvalidRubocopVersionError < RuntimeError; end
23
-
24
- autoload :Position, 'solargraph/position'
25
- autoload :Range, 'solargraph/range'
26
- autoload :Location, 'solargraph/location'
27
- autoload :Shell, 'solargraph/shell'
28
- autoload :Source, 'solargraph/source'
29
- autoload :SourceMap, 'solargraph/source_map'
30
- autoload :ApiMap, 'solargraph/api_map'
31
- autoload :Yardoc, 'solargraph/yardoc'
32
- autoload :YardMap, 'solargraph/yard_map'
33
- autoload :Pin, 'solargraph/pin'
34
- autoload :DocMap, 'solargraph/doc_map'
35
- autoload :ServerMethods, 'solargraph/server_methods'
36
- autoload :LanguageServer, 'solargraph/language_server'
37
- autoload :Workspace, 'solargraph/workspace'
38
- autoload :Page, 'solargraph/page'
39
- autoload :Library, 'solargraph/library'
40
- autoload :Diagnostics, 'solargraph/diagnostics'
41
- autoload :ComplexType, 'solargraph/complex_type'
42
- autoload :Bench, 'solargraph/bench'
43
- autoload :Logging, 'solargraph/logging'
44
- autoload :TypeChecker, 'solargraph/type_checker'
45
- autoload :Environ, 'solargraph/environ'
46
- autoload :Equality, 'solargraph/equality'
47
- autoload :Convention, 'solargraph/convention'
48
- autoload :Parser, 'solargraph/parser'
49
- autoload :RbsMap, 'solargraph/rbs_map'
50
- autoload :GemPins, 'solargraph/gem_pins'
51
- autoload :PinCache, 'solargraph/pin_cache'
52
-
53
- dir = File.dirname(__FILE__)
54
- VIEWS_PATH = File.join(dir, 'solargraph', 'views')
55
-
56
- CHDIR_MUTEX = Mutex.new
57
-
58
- # @param type [Symbol] Type of assert.
59
- def self.asserts_on?(type)
60
- if ENV['SOLARGRAPH_ASSERTS'].nil? || ENV['SOLARGRAPH_ASSERTS'].empty?
61
- false
62
- elsif ENV['SOLARGRAPH_ASSERTS'] == 'on'
63
- true
64
- else
65
- logger.warn "Unrecognized SOLARGRAPH_ASSERTS value: #{ENV['SOLARGRAPH_ASSERTS']}"
66
- false
67
- end
68
- end
69
-
70
- # @param type [Symbol] The type of assertion to perform.
71
- # @param msg [String, nil] An optional message to log
72
- # @param block [Proc] A block that returns a message to log
73
- # @return [void]
74
- def self.assert_or_log(type, msg = nil, &block)
75
- raise (msg || block.call) if asserts_on?(type) && ![:combine_with_visibility].include?(type)
76
- logger.info msg, &block
77
- end
78
-
79
- # A convenience method for Solargraph::Logging.logger.
80
- #
81
- # @return [Logger]
82
- def self.logger
83
- Solargraph::Logging.logger
84
- end
85
-
86
- # A helper method that runs Bundler.with_unbundled_env or falls back to
87
- # Bundler.with_clean_env for earlier versions of Bundler.
88
- #
89
- # @generic T
90
- # @yieldreturn [generic<T>]
91
- # @sg-ignore dynamic call, but both functions behave the same
92
- # @return [generic<T>]
93
- def self.with_clean_env &block
94
- meth = if Bundler.respond_to?(:with_original_env)
95
- :with_original_env
96
- else
97
- :with_clean_env
98
- end
99
- Bundler.send meth, &block
100
- end
101
- end
102
-
103
- # Ensure that ParserGem node processors are properly loaded to avoid conflicts
104
- # with Convention node processors
105
- require 'solargraph/parser/parser_gem/node_processors'
1
+ # frozen_string_literal: true
2
+
3
+ Encoding.default_external = 'UTF-8'
4
+
5
+ require 'bundler'
6
+ require 'set'
7
+ require 'yard-solargraph'
8
+ require 'solargraph/yard_tags'
9
+ require 'solargraph/version'
10
+
11
+ # The top-level namespace for the Solargraph code mapping, documentation,
12
+ # static analysis, and language server libraries.
13
+ #
14
+ module Solargraph
15
+ class InvalidOffsetError < RangeError; end
16
+ class DiagnosticsError < RuntimeError; end
17
+ class FileNotFoundError < RuntimeError; end
18
+ class SourceNotAvailableError < StandardError; end
19
+ class ComplexTypeError < StandardError; end
20
+ class WorkspaceTooLargeError < RuntimeError; end
21
+ class BundleNotFoundError < StandardError; end
22
+ class InvalidRubocopVersionError < RuntimeError; end
23
+
24
+ autoload :Position, 'solargraph/position'
25
+ autoload :Range, 'solargraph/range'
26
+ autoload :Location, 'solargraph/location'
27
+ autoload :Shell, 'solargraph/shell'
28
+ autoload :Source, 'solargraph/source'
29
+ autoload :SourceMap, 'solargraph/source_map'
30
+ autoload :ApiMap, 'solargraph/api_map'
31
+ autoload :Yardoc, 'solargraph/yardoc'
32
+ autoload :YardMap, 'solargraph/yard_map'
33
+ autoload :Pin, 'solargraph/pin'
34
+ autoload :DocMap, 'solargraph/doc_map'
35
+ autoload :ServerMethods, 'solargraph/server_methods'
36
+ autoload :LanguageServer, 'solargraph/language_server'
37
+ autoload :Workspace, 'solargraph/workspace'
38
+ autoload :Page, 'solargraph/page'
39
+ autoload :Library, 'solargraph/library'
40
+ autoload :Diagnostics, 'solargraph/diagnostics'
41
+ autoload :ComplexType, 'solargraph/complex_type'
42
+ autoload :Bench, 'solargraph/bench'
43
+ autoload :Logging, 'solargraph/logging'
44
+ autoload :TypeChecker, 'solargraph/type_checker'
45
+ autoload :Environ, 'solargraph/environ'
46
+ autoload :Equality, 'solargraph/equality'
47
+ autoload :Convention, 'solargraph/convention'
48
+ autoload :Parser, 'solargraph/parser'
49
+ autoload :RbsMap, 'solargraph/rbs_map'
50
+ autoload :GemPins, 'solargraph/gem_pins'
51
+ autoload :PinCache, 'solargraph/pin_cache'
52
+
53
+ dir = File.dirname(__FILE__)
54
+ VIEWS_PATH = File.join(dir, 'solargraph', 'views')
55
+
56
+ CHDIR_MUTEX = Mutex.new
57
+
58
+ def self.asserts_on?
59
+ # @sg-ignore Translate to something flow sensitive typing understands
60
+ if ENV['SOLARGRAPH_ASSERTS'].nil? || ENV['SOLARGRAPH_ASSERTS'].empty?
61
+ false
62
+ elsif ENV['SOLARGRAPH_ASSERTS'] == 'on'
63
+ true
64
+ else
65
+ logger.warn "Unrecognized SOLARGRAPH_ASSERTS value: #{ENV['SOLARGRAPH_ASSERTS']}"
66
+ false
67
+ end
68
+ end
69
+
70
+ # @param type [Symbol] The type of assertion to perform.
71
+ # @param msg [String, nil] An optional message to log
72
+ # @param block [Proc] A block that returns a message to log
73
+ # @return [void]
74
+ def self.assert_or_log(type, msg = nil, &block)
75
+ if asserts_on?
76
+ # @type [String, nil]
77
+ msg ||= block.call
78
+
79
+ raise "No message given for #{type.inspect}" if msg.nil?
80
+
81
+ # conditional aliases to handle compatibility corner cases
82
+ # @sg-ignore flow sensitive typing needs to handle 'raise if'
83
+ return if type == :alias_target_missing && msg.include?('highline/compatibility.rb')
84
+ # @sg-ignore flow sensitive typing needs to handle 'raise if'
85
+ return if type == :alias_target_missing && msg.include?('lib/json/add/date.rb')
86
+ # @todo :combine_with_visibility is not ready for prime time -
87
+ # lots of disagreements found in practice that heuristics need
88
+ # to be created for and/or debugging needs to resolve in pin
89
+ # generation.
90
+ # @todo :api_map_namespace_pin_stack triggers in a badly handled
91
+ # self type case - 'keeps track of self type in method
92
+ # parameters in subclass' in call_spec.rb
93
+ return if %i[api_map_namespace_pin_stack combine_with_visibility].include?(type)
94
+
95
+ raise msg
96
+ end
97
+ logger.info msg, &block
98
+ end
99
+
100
+ # A convenience method for Solargraph::Logging.logger.
101
+ #
102
+ # @return [Logger]
103
+ def self.logger
104
+ Solargraph::Logging.logger
105
+ end
106
+
107
+ # A helper method that runs Bundler.with_unbundled_env or falls back to
108
+ # Bundler.with_clean_env for earlier versions of Bundler.
109
+ #
110
+ # @generic T
111
+ # @yieldreturn [generic<T>]
112
+ # @sg-ignore dynamic call, but both functions behave the same
113
+ # @return [generic<T>]
114
+ def self.with_clean_env &block
115
+ meth = if Bundler.respond_to?(:with_original_env)
116
+ :with_original_env
117
+ else
118
+ :with_clean_env
119
+ end
120
+ Bundler.send meth, &block
121
+ end
122
+ end
123
+
124
+ # Ensure that ParserGem node processors are properly loaded to avoid conflicts
125
+ # with Convention node processors
126
+ require 'solargraph/parser/parser_gem/node_processors'
@@ -0,0 +1,193 @@
1
+ # <!-- rdoc-file=lib/rubygems/dependency.rb -->
2
+ # The Dependency class holds a Gem name and a Gem::Requirement.
3
+ #
4
+ class Gem::Dependency
5
+ @name: untyped
6
+
7
+ @requirement: untyped
8
+
9
+ @type: untyped
10
+
11
+ @prerelease: untyped
12
+
13
+ @version_requirements: untyped
14
+
15
+ @version_requirement: untyped
16
+
17
+ # <!-- rdoc-file=lib/rubygems/dependency.rb -->
18
+ # Valid dependency types.
19
+ #
20
+ TYPES: ::Array[:development | :runtime]
21
+
22
+ # <!-- rdoc-file=lib/rubygems/dependency.rb -->
23
+ # Dependency name or regular expression.
24
+ #
25
+ attr_accessor name: untyped
26
+
27
+ # <!-- rdoc-file=lib/rubygems/dependency.rb -->
28
+ # Allows you to force this dependency to be a prerelease.
29
+ #
30
+ attr_writer prerelease: untyped
31
+
32
+ # <!--
33
+ # rdoc-file=lib/rubygems/dependency.rb
34
+ # - new(name, *requirements)
35
+ # -->
36
+ # Constructs a dependency with `name` and `requirements`. The last argument can
37
+ # optionally be the dependency type, which defaults to `:runtime`.
38
+ #
39
+ def initialize: (untyped name, *untyped requirements) -> void
40
+
41
+ def hash: () -> untyped
42
+
43
+ def inspect: () -> untyped
44
+
45
+ # <!--
46
+ # rdoc-file=lib/rubygems/dependency.rb
47
+ # - prerelease?()
48
+ # -->
49
+ # Does this dependency require a prerelease?
50
+ #
51
+ def prerelease?: () -> untyped
52
+
53
+ # <!--
54
+ # rdoc-file=lib/rubygems/dependency.rb
55
+ # - latest_version?()
56
+ # -->
57
+ # Is this dependency simply asking for the latest version of a gem?
58
+ #
59
+ def latest_version?: () -> untyped
60
+
61
+ def pretty_print: (untyped q) -> untyped
62
+
63
+ # <!--
64
+ # rdoc-file=lib/rubygems/dependency.rb
65
+ # - requirement()
66
+ # -->
67
+ # What does this dependency require?
68
+ #
69
+ def requirement: () -> untyped
70
+
71
+ # <!--
72
+ # rdoc-file=lib/rubygems/dependency.rb
73
+ # - requirements_list()
74
+ # -->
75
+ #
76
+ def requirements_list: () -> untyped
77
+
78
+ def to_s: () -> ::String
79
+
80
+ # <!--
81
+ # rdoc-file=lib/rubygems/dependency.rb
82
+ # - type()
83
+ # -->
84
+ # Dependency type.
85
+ #
86
+ def type: () -> untyped
87
+
88
+ # <!--
89
+ # rdoc-file=lib/rubygems/dependency.rb
90
+ # - runtime?()
91
+ # -->
92
+ #
93
+ def runtime?: () -> untyped
94
+
95
+ def ==: (untyped other) -> untyped
96
+
97
+ # <!--
98
+ # rdoc-file=lib/rubygems/dependency.rb
99
+ # - <=>(other)
100
+ # -->
101
+ # Dependencies are ordered by name.
102
+ #
103
+ def <=>: (untyped other) -> untyped
104
+
105
+ # <!--
106
+ # rdoc-file=lib/rubygems/dependency.rb
107
+ # - =~(other)
108
+ # -->
109
+ # Uses this dependency as a pattern to compare to `other`. This dependency will
110
+ # match if the name matches the other's name, and other has only an equal
111
+ # version requirement that satisfies this dependency.
112
+ #
113
+ def =~: (untyped other) -> (nil | false | untyped)
114
+
115
+ # <!--
116
+ # rdoc-file=lib/rubygems/dependency.rb
117
+ # - ===(other)
118
+ # -->
119
+ #
120
+ alias === =~
121
+
122
+ # <!--
123
+ # rdoc-file=lib/rubygems/dependency.rb
124
+ # - dep.match? name => true or false
125
+ # - dep.match? name, version => true or false
126
+ # - dep.match? spec => true or false
127
+ # -->
128
+ # Does this dependency match the specification described by `name` and `version`
129
+ # or match `spec`?
130
+ #
131
+ # NOTE: Unlike #matches_spec? this method does not return true when the version
132
+ # is a prerelease version unless this is a prerelease dependency.
133
+ #
134
+ def match?: (untyped obj, ?untyped? version, ?bool allow_prerelease) -> (false | true | untyped)
135
+
136
+ # <!--
137
+ # rdoc-file=lib/rubygems/dependency.rb
138
+ # - matches_spec?(spec)
139
+ # -->
140
+ # Does this dependency match `spec`?
141
+ #
142
+ # NOTE: This is not a convenience method. Unlike #match? this method returns
143
+ # true when `spec` is a prerelease version even if this dependency is not a
144
+ # prerelease dependency.
145
+ #
146
+ def matches_spec?: (untyped spec) -> (false | true | untyped)
147
+
148
+ # <!--
149
+ # rdoc-file=lib/rubygems/dependency.rb
150
+ # - merge(other)
151
+ # -->
152
+ # Merges the requirements of `other` into this dependency
153
+ #
154
+ def merge: (untyped other) -> untyped
155
+
156
+ # <!--
157
+ # rdoc-file=lib/rubygems/dependency.rb
158
+ # - matching_specs(platform_only = false)
159
+ # -->
160
+ #
161
+ def matching_specs: (?bool platform_only) -> untyped
162
+
163
+ # <!--
164
+ # rdoc-file=lib/rubygems/dependency.rb
165
+ # - specific?()
166
+ # -->
167
+ # True if the dependency will not always match the latest version.
168
+ #
169
+ def specific?: () -> untyped
170
+
171
+ # <!--
172
+ # rdoc-file=lib/rubygems/dependency.rb
173
+ # - to_specs()
174
+ # -->
175
+ #
176
+ def to_specs: () -> untyped
177
+
178
+ # <!--
179
+ # rdoc-file=lib/rubygems/dependency.rb
180
+ # - to_spec()
181
+ # -->
182
+ #
183
+ def to_spec: () -> untyped
184
+
185
+ # <!--
186
+ # rdoc-file=lib/rubygems/dependency.rb
187
+ # - identity()
188
+ # -->
189
+ #
190
+ def identity: () -> (:complete | :abs_latest | :latest | :released)
191
+
192
+ def encode_with: (untyped coder) -> untyped
193
+ end
@@ -144,6 +144,34 @@ module Solargraph
144
144
  | [T] (8 index) { (int index) -> T } -> (I | T)
145
145
  | [T] (9 index) { (int index) -> T } -> (J | T)
146
146
  | [T] (int index) { (int index) -> T } -> (A | B | C | D | E | F | G | H | I | J | T)
147
+
148
+ # <!--
149
+ # rdoc-file=array.rb
150
+ # - first -> object or nil
151
+ # - first(count) -> new_array
152
+ # -->
153
+ # Returns elements from `self`, or `nil`; does not modify `self`.
154
+ #
155
+ # With no argument given, returns the first element (if available):
156
+ #
157
+ # a = [:foo, 'bar', 2]
158
+ # a.first # => :foo
159
+ # a # => [:foo, "bar", 2]
160
+ #
161
+ # If `self` is empty, returns `nil`.
162
+ #
163
+ # [].first # => nil
164
+ #
165
+ # With a non-negative integer argument `count` given, returns the first `count`
166
+ # elements (as available) in a new array:
167
+ #
168
+ # a.first(0) # => []
169
+ # a.first(2) # => [:foo, "bar"]
170
+ # a.first(50) # => [:foo, "bar", 2]
171
+ #
172
+ # Related: see [Methods for Querying](rdoc-ref:Array@Methods+for+Querying).
173
+ #
174
+ def first: %a{implicitly-returns-nil} () -> A
147
175
  end
148
176
  end
149
177
  end
@@ -0,0 +1,5 @@
1
+ module ::AST
2
+ class Node
3
+ def children: () -> Array[self | Integer | String | Symbol | nil]
4
+ end
5
+ end
@@ -0,0 +1,11 @@
1
+ module Diff
2
+ end
3
+
4
+ module Diff::LCS
5
+ def self.LCS: (Array[String], Array[String]) -> Array[String]
6
+ | (String, String) -> Array[String]
7
+ def self.diff: (Array[String], Array[String]) -> Array[Array[String]]
8
+ | (String, String) -> Array[Array[Diff::LCS::Change]]
9
+
10
+ def self.patch!: (Array[String], Array[String]) -> String
11
+ end