solargraph 0.44.3 → 0.49.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/FUNDING.yml +1 -0
- data/.github/workflows/rspec.yml +41 -0
- data/CHANGELOG.md +57 -0
- data/LICENSE +1 -1
- data/README.md +18 -2
- data/SPONSORS.md +2 -2
- data/lib/solargraph/api_map/store.rb +13 -1
- data/lib/solargraph/api_map.rb +57 -34
- data/lib/solargraph/cache.rb +51 -0
- data/lib/solargraph/complex_type/type_methods.rb +10 -6
- data/lib/solargraph/complex_type/unique_type.rb +57 -0
- data/lib/solargraph/complex_type.rb +35 -2
- data/lib/solargraph/convention/rakefile.rb +17 -0
- data/lib/solargraph/convention/rspec.rb +13 -4
- data/lib/solargraph/convention.rb +2 -0
- data/lib/solargraph/diagnostics/require_not_found.rb +16 -0
- data/lib/solargraph/diagnostics/rubocop.rb +17 -3
- data/lib/solargraph/diagnostics/rubocop_helpers.rb +3 -1
- data/lib/solargraph/language_server/host.rb +22 -18
- data/lib/solargraph/language_server/message/extended/download_core.rb +1 -5
- data/lib/solargraph/language_server/message/initialize.rb +2 -0
- data/lib/solargraph/language_server/message/text_document/formatting.rb +1 -1
- data/lib/solargraph/language_server/message/text_document/hover.rb +16 -4
- data/lib/solargraph/language_server/message/text_document/signature_help.rb +1 -6
- data/lib/solargraph/language_server/message/workspace/did_change_watched_files.rb +10 -3
- data/lib/solargraph/language_server/message/workspace/workspace_symbol.rb +1 -1
- data/lib/solargraph/language_server/uri_helpers.rb +1 -1
- data/lib/solargraph/library.rb +21 -20
- data/lib/solargraph/parser/legacy/class_methods.rb +0 -5
- data/lib/solargraph/parser/legacy/node_processors/casgn_node.rb +12 -2
- data/lib/solargraph/parser/legacy/node_processors/sclass_node.rb +24 -3
- data/lib/solargraph/parser/rubyvm/class_methods.rb +8 -4
- data/lib/solargraph/parser/rubyvm/node_processors/casgn_node.rb +13 -2
- data/lib/solargraph/parser/rubyvm/node_processors/def_node.rb +20 -9
- data/lib/solargraph/parser/rubyvm/node_processors/defs_node.rb +14 -3
- data/lib/solargraph/parser/rubyvm/node_processors/kw_arg_node.rb +2 -2
- data/lib/solargraph/parser/rubyvm/node_processors/sclass_node.rb +14 -3
- data/lib/solargraph/parser/rubyvm/node_processors/send_node.rb +4 -2
- data/lib/solargraph/parser/rubyvm/node_processors.rb +1 -0
- data/lib/solargraph/parser/rubyvm/node_wrapper.rb +47 -0
- data/lib/solargraph/pin/base.rb +5 -2
- data/lib/solargraph/pin/block.rb +2 -1
- data/lib/solargraph/pin/conversions.rb +2 -6
- data/lib/solargraph/pin/method.rb +100 -10
- data/lib/solargraph/pin/namespace.rb +4 -1
- data/lib/solargraph/pin/parameter.rb +10 -7
- data/lib/solargraph/pin/search.rb +56 -0
- data/lib/solargraph/pin/signature.rb +23 -0
- data/lib/solargraph/pin.rb +2 -0
- data/lib/solargraph/range.rb +1 -1
- data/lib/solargraph/rbs_map/conversions.rb +394 -0
- data/lib/solargraph/rbs_map/core_fills.rb +61 -0
- data/lib/solargraph/rbs_map/core_map.rb +38 -0
- data/lib/solargraph/rbs_map/core_signs.rb +33 -0
- data/lib/solargraph/rbs_map/stdlib_map.rb +36 -0
- data/lib/solargraph/rbs_map.rb +73 -0
- data/lib/solargraph/shell.rb +38 -30
- data/lib/solargraph/source/chain/call.rb +34 -23
- data/lib/solargraph/source/chain.rb +21 -6
- data/lib/solargraph/source.rb +1 -1
- data/lib/solargraph/source_map/clip.rb +5 -0
- data/lib/solargraph/source_map/mapper.rb +31 -2
- data/lib/solargraph/source_map.rb +1 -10
- data/lib/solargraph/type_checker/checks.rb +13 -0
- data/lib/solargraph/type_checker.rb +90 -61
- data/lib/solargraph/version.rb +1 -1
- data/lib/solargraph/views/environment.erb +2 -2
- data/lib/solargraph/workspace.rb +12 -14
- data/lib/solargraph/yard_map/mapper/to_method.rb +7 -4
- data/lib/solargraph/yard_map.rb +54 -196
- data/lib/solargraph.rb +4 -4
- data/solargraph.gemspec +8 -6
- metadata +46 -37
- data/lib/solargraph/compat.rb +0 -37
- data/lib/solargraph/yard_map/core_docs.rb +0 -170
- data/lib/solargraph/yard_map/core_fills.rb +0 -203
- data/lib/solargraph/yard_map/core_gen.rb +0 -76
- data/lib/solargraph/yard_map/rdoc_to_yard.rb +0 -140
- data/lib/solargraph/yard_map/stdlib_fills.rb +0 -43
- data/yardoc/2.2.2.tar.gz +0 -0
|
@@ -8,14 +8,23 @@ module Solargraph
|
|
|
8
8
|
@environ ||= Environ.new(
|
|
9
9
|
requires: ['rspec'],
|
|
10
10
|
domains: ['RSpec::Matchers', 'RSpec::ExpectationGroups'],
|
|
11
|
-
# This override is necessary due to an erroneous @return tag in
|
|
12
|
-
# rspec's YARD documentation.
|
|
13
|
-
# @todo The return types have been fixed (https://github.com/rspec/rspec-expectations/pull/1121)
|
|
14
11
|
pins: [
|
|
12
|
+
# This override is necessary due to an erroneous @return tag in
|
|
13
|
+
# rspec's YARD documentation.
|
|
14
|
+
# @todo The return types have been fixed (https://github.com/rspec/rspec-expectations/pull/1121)
|
|
15
15
|
Solargraph::Pin::Reference::Override.method_return('RSpec::Matchers#expect', 'RSpec::Expectations::ExpectationTarget')
|
|
16
|
-
]
|
|
16
|
+
].concat(extras)
|
|
17
17
|
)
|
|
18
18
|
end
|
|
19
|
+
|
|
20
|
+
private
|
|
21
|
+
|
|
22
|
+
def extras
|
|
23
|
+
@@extras ||= SourceMap.load_string(%(
|
|
24
|
+
def describe(*args); end
|
|
25
|
+
def it(*args); end
|
|
26
|
+
)).pins
|
|
27
|
+
end
|
|
19
28
|
end
|
|
20
29
|
end
|
|
21
30
|
end
|
|
@@ -11,6 +11,7 @@ module Solargraph
|
|
|
11
11
|
autoload :Gemfile, 'solargraph/convention/gemfile'
|
|
12
12
|
autoload :Rspec, 'solargraph/convention/rspec'
|
|
13
13
|
autoload :Gemspec, 'solargraph/convention/gemspec'
|
|
14
|
+
autoload :Rakefile, 'solargraph/convention/rakefile'
|
|
14
15
|
|
|
15
16
|
@@conventions = Set.new
|
|
16
17
|
|
|
@@ -43,5 +44,6 @@ module Solargraph
|
|
|
43
44
|
register Gemfile
|
|
44
45
|
register Gemspec
|
|
45
46
|
register Rspec
|
|
47
|
+
register Rakefile
|
|
46
48
|
end
|
|
47
49
|
end
|
|
@@ -12,6 +12,10 @@ module Solargraph
|
|
|
12
12
|
refs = {}
|
|
13
13
|
map = api_map.source_map(source.filename)
|
|
14
14
|
map.requires.each { |ref| refs[ref.name] = ref }
|
|
15
|
+
api_map.missing_docs.each do |r|
|
|
16
|
+
next unless refs.key?(r)
|
|
17
|
+
result.push docs_error(r, refs[r].location)
|
|
18
|
+
end
|
|
15
19
|
api_map.unresolved_requires.each do |r|
|
|
16
20
|
next unless refs.key?(r)
|
|
17
21
|
result.push require_error(r, refs[r].location)
|
|
@@ -21,6 +25,18 @@ module Solargraph
|
|
|
21
25
|
|
|
22
26
|
private
|
|
23
27
|
|
|
28
|
+
# @param path [String]
|
|
29
|
+
# @param location [Location]
|
|
30
|
+
# @return [Hash]
|
|
31
|
+
def docs_error path, location
|
|
32
|
+
{
|
|
33
|
+
range: location.range.to_hash,
|
|
34
|
+
severity: Diagnostics::Severities::WARNING,
|
|
35
|
+
source: 'RequireNotFound',
|
|
36
|
+
message: "YARD docs not found for #{path}"
|
|
37
|
+
}
|
|
38
|
+
end
|
|
39
|
+
|
|
24
40
|
# @param path [String]
|
|
25
41
|
# @param location [Location]
|
|
26
42
|
# @return [Hash]
|
|
@@ -11,6 +11,7 @@ module Solargraph
|
|
|
11
11
|
|
|
12
12
|
# Conversion of RuboCop severity names to LSP constants
|
|
13
13
|
SEVERITIES = {
|
|
14
|
+
'info' => Severities::HINT,
|
|
14
15
|
'refactor' => Severities::HINT,
|
|
15
16
|
'convention' => Severities::INFORMATION,
|
|
16
17
|
'warning' => Severities::WARNING,
|
|
@@ -22,16 +23,20 @@ module Solargraph
|
|
|
22
23
|
# @param _api_map [Solargraph::ApiMap]
|
|
23
24
|
# @return [Array<Hash>]
|
|
24
25
|
def diagnose source, _api_map
|
|
26
|
+
@source = source
|
|
25
27
|
require_rubocop(rubocop_version)
|
|
26
28
|
options, paths = generate_options(source.filename, source.code)
|
|
27
29
|
store = RuboCop::ConfigStore.new
|
|
28
30
|
runner = RuboCop::Runner.new(options, store)
|
|
29
31
|
result = redirect_stdout{ runner.run(paths) }
|
|
32
|
+
|
|
33
|
+
return [] if result.empty?
|
|
34
|
+
|
|
30
35
|
make_array JSON.parse(result)
|
|
31
36
|
rescue RuboCop::ValidationError, RuboCop::ConfigNotFoundError => e
|
|
32
37
|
raise DiagnosticsError, "Error in RuboCop configuration: #{e.message}"
|
|
33
|
-
rescue JSON::ParserError
|
|
34
|
-
raise DiagnosticsError,
|
|
38
|
+
rescue JSON::ParserError => e
|
|
39
|
+
raise DiagnosticsError, "RuboCop returned invalid data: #{e.message}"
|
|
35
40
|
end
|
|
36
41
|
|
|
37
42
|
private
|
|
@@ -88,8 +93,17 @@ module Solargraph
|
|
|
88
93
|
if off['location']['start_line'] != off['location']['last_line']
|
|
89
94
|
Position.new(off['location']['start_line'], 0)
|
|
90
95
|
else
|
|
96
|
+
start_line = off['location']['start_line'] - 1
|
|
97
|
+
last_column = off['location']['last_column']
|
|
98
|
+
line = @source.code.lines[start_line]
|
|
99
|
+
col_off = if line.nil? || line.empty?
|
|
100
|
+
1
|
|
101
|
+
else
|
|
102
|
+
0
|
|
103
|
+
end
|
|
104
|
+
|
|
91
105
|
Position.new(
|
|
92
|
-
|
|
106
|
+
start_line, last_column - col_off
|
|
93
107
|
)
|
|
94
108
|
end
|
|
95
109
|
end
|
|
@@ -10,13 +10,15 @@ module Solargraph
|
|
|
10
10
|
# Requires a specific version of rubocop, or the latest installed version
|
|
11
11
|
# if _version_ is `nil`.
|
|
12
12
|
#
|
|
13
|
-
# @param version [String]
|
|
13
|
+
# @param version [String, nil]
|
|
14
14
|
# @raise [InvalidRubocopVersionError] if _version_ is not installed
|
|
15
15
|
def require_rubocop(version = nil)
|
|
16
16
|
begin
|
|
17
17
|
gem_path = Gem::Specification.find_by_name('rubocop', version).full_gem_path
|
|
18
18
|
gem_lib_path = File.join(gem_path, 'lib')
|
|
19
19
|
$LOAD_PATH.unshift(gem_lib_path) unless $LOAD_PATH.include?(gem_lib_path)
|
|
20
|
+
# @todo Gem::MissingSpecVersionError is undocumented for some reason
|
|
21
|
+
# @sg-ignore
|
|
20
22
|
rescue Gem::MissingSpecVersionError => e
|
|
21
23
|
raise InvalidRubocopVersionError,
|
|
22
24
|
"could not find '#{e.name}' (#{e.requirement}) - "\
|
|
@@ -130,35 +130,39 @@ module Solargraph
|
|
|
130
130
|
end
|
|
131
131
|
end
|
|
132
132
|
|
|
133
|
-
# Respond to a notification that
|
|
134
|
-
# The libraries will determine whether the
|
|
133
|
+
# Respond to a notification that files were created in the workspace.
|
|
134
|
+
# The libraries will determine whether the files should be merged; see
|
|
135
135
|
# Solargraph::Library#create_from_disk.
|
|
136
136
|
#
|
|
137
|
-
# @param
|
|
138
|
-
# @return [Boolean] True if
|
|
139
|
-
def create
|
|
140
|
-
|
|
137
|
+
# @param uris [Array<String>] The URIs of the files.
|
|
138
|
+
# @return [Boolean] True if at least one library accepted at least one file.
|
|
139
|
+
def create *uris
|
|
140
|
+
filenames = uris.map { |uri| uri_to_file(uri) }
|
|
141
141
|
result = false
|
|
142
142
|
libraries.each do |lib|
|
|
143
|
-
result = true if lib.create_from_disk(
|
|
143
|
+
result = true if lib.create_from_disk(*filenames)
|
|
144
|
+
end
|
|
145
|
+
uris.each do |uri|
|
|
146
|
+
diagnoser.schedule uri if open?(uri)
|
|
144
147
|
end
|
|
145
|
-
diagnoser.schedule uri if open?(uri)
|
|
146
148
|
result
|
|
147
149
|
end
|
|
148
150
|
|
|
149
|
-
# Delete the specified
|
|
151
|
+
# Delete the specified files from the library.
|
|
150
152
|
#
|
|
151
|
-
# @param
|
|
153
|
+
# @param uris [Array<String>] The file uris.
|
|
152
154
|
# @return [void]
|
|
153
|
-
def delete
|
|
154
|
-
|
|
155
|
+
def delete *uris
|
|
156
|
+
filenames = uris.map { |uri| uri_to_file(uri) }
|
|
155
157
|
libraries.each do |lib|
|
|
156
|
-
lib.delete(
|
|
158
|
+
lib.delete(*filenames)
|
|
159
|
+
end
|
|
160
|
+
uris.each do |uri|
|
|
161
|
+
send_notification "textDocument/publishDiagnostics", {
|
|
162
|
+
uri: uri,
|
|
163
|
+
diagnostics: []
|
|
164
|
+
}
|
|
157
165
|
end
|
|
158
|
-
send_notification "textDocument/publishDiagnostics", {
|
|
159
|
-
uri: uri,
|
|
160
|
-
diagnostics: []
|
|
161
|
-
}
|
|
162
166
|
end
|
|
163
167
|
|
|
164
168
|
# Open the specified file in the library.
|
|
@@ -692,7 +696,7 @@ module Solargraph
|
|
|
692
696
|
params['contentChanges'].each do |recvd|
|
|
693
697
|
chng = check_diff(params['textDocument']['uri'], recvd)
|
|
694
698
|
changes.push Solargraph::Source::Change.new(
|
|
695
|
-
(chng['range'].nil? ?
|
|
699
|
+
(chng['range'].nil? ?
|
|
696
700
|
nil :
|
|
697
701
|
Solargraph::Range.from_to(chng['range']['start']['line'], chng['range']['start']['character'], chng['range']['end']['line'], chng['range']['end']['character'])
|
|
698
702
|
),
|
|
@@ -10,11 +10,7 @@ module Solargraph
|
|
|
10
10
|
#
|
|
11
11
|
class DownloadCore < Base
|
|
12
12
|
def process
|
|
13
|
-
|
|
14
|
-
Solargraph::YardMap::CoreDocs.download ver
|
|
15
|
-
host.show_message "Downloaded documentation for Ruby #{ver}.", LanguageServer::MessageTypes::INFO
|
|
16
|
-
rescue StandardError => e
|
|
17
|
-
host.show_message "An error occurred while downloading documentation: [#{e.class}] #{e.message}", LanguageServer::MessageTypes::ERROR
|
|
13
|
+
host.show_message "Downloading cores is deprecated. Solargraph currently uses RBS for core and stdlib documentation", LanguageServer::MessageTypes::INFO
|
|
18
14
|
end
|
|
19
15
|
end
|
|
20
16
|
end
|
|
@@ -25,6 +25,8 @@ module Solargraph
|
|
|
25
25
|
}
|
|
26
26
|
}
|
|
27
27
|
}
|
|
28
|
+
# FIXME: lsp default is utf-16, may have different position
|
|
29
|
+
result[:capabilities][:positionEncoding] = "utf-32" if params.dig("capabilities", "general", "positionEncodings")&.include?("utf-32")
|
|
28
30
|
result[:capabilities].merge! static_completion unless dynamic_registration_for?('textDocument', 'completion')
|
|
29
31
|
result[:capabilities].merge! static_signature_help unless dynamic_registration_for?('textDocument', 'signatureHelp')
|
|
30
32
|
# result[:capabilities].merge! static_on_type_formatting unless dynamic_registration_for?('textDocument', 'onTypeFormatting')
|
|
@@ -54,7 +54,7 @@ module Solargraph
|
|
|
54
54
|
def cli_args file_uri, config
|
|
55
55
|
file = UriHelpers.uri_to_file(file_uri)
|
|
56
56
|
args = [
|
|
57
|
-
config['cops'] == 'all' ? '--
|
|
57
|
+
config['cops'] == 'all' ? '--autocorrect-all' : '--autocorrect',
|
|
58
58
|
'--cache', 'false',
|
|
59
59
|
'--format', formatter_class(config).name,
|
|
60
60
|
]
|
|
@@ -27,16 +27,28 @@ module Solargraph
|
|
|
27
27
|
last_link = this_link unless this_link.nil?
|
|
28
28
|
end
|
|
29
29
|
set_result(
|
|
30
|
-
contents
|
|
31
|
-
kind: 'markdown',
|
|
32
|
-
value: contents.join("\n\n")
|
|
33
|
-
}
|
|
30
|
+
contents_or_nil(contents)
|
|
34
31
|
)
|
|
35
32
|
rescue FileNotFoundError => e
|
|
36
33
|
Logging.logger.warn "[#{e.class}] #{e.message}"
|
|
37
34
|
Logging.logger.warn e.backtrace.join("\n")
|
|
38
35
|
set_result nil
|
|
39
36
|
end
|
|
37
|
+
|
|
38
|
+
private
|
|
39
|
+
|
|
40
|
+
def contents_or_nil contents
|
|
41
|
+
stripped = contents
|
|
42
|
+
.map(&:strip)
|
|
43
|
+
.reject { |c| c.empty? }
|
|
44
|
+
return nil if stripped.empty?
|
|
45
|
+
{
|
|
46
|
+
contents: {
|
|
47
|
+
kind: 'markdown',
|
|
48
|
+
value: stripped.join("\n\n")
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
end
|
|
40
52
|
end
|
|
41
53
|
end
|
|
42
54
|
end
|
|
@@ -9,13 +9,8 @@ module Solargraph
|
|
|
9
9
|
line = params['position']['line']
|
|
10
10
|
col = params['position']['character']
|
|
11
11
|
suggestions = host.signatures_at(params['textDocument']['uri'], line, col)
|
|
12
|
-
info = []
|
|
13
|
-
suggestions.each do |pin|
|
|
14
|
-
info.concat pin.overloads.map(&:signature_help)
|
|
15
|
-
info.push pin.signature_help
|
|
16
|
-
end
|
|
17
12
|
set_result({
|
|
18
|
-
signatures:
|
|
13
|
+
signatures: suggestions.flat_map { |pin| pin.signature_help }
|
|
19
14
|
})
|
|
20
15
|
rescue FileNotFoundError => e
|
|
21
16
|
Logging.logger.warn "[#{e.class}] #{e.message}"
|
|
@@ -10,22 +10,29 @@ module Solargraph::LanguageServer::Message::Workspace
|
|
|
10
10
|
|
|
11
11
|
def process
|
|
12
12
|
need_catalog = false
|
|
13
|
+
to_create = []
|
|
14
|
+
to_delete = []
|
|
15
|
+
|
|
13
16
|
# @param change [Hash]
|
|
14
17
|
params['changes'].each do |change|
|
|
15
18
|
if change['type'] == CREATED
|
|
16
|
-
|
|
19
|
+
to_create << change['uri']
|
|
17
20
|
need_catalog = true
|
|
18
21
|
elsif change['type'] == CHANGED
|
|
19
22
|
next if host.open?(change['uri'])
|
|
20
|
-
|
|
23
|
+
to_create << change['uri']
|
|
21
24
|
need_catalog = true
|
|
22
25
|
elsif change['type'] == DELETED
|
|
23
|
-
|
|
26
|
+
to_delete << change['uri']
|
|
24
27
|
need_catalog = true
|
|
25
28
|
else
|
|
26
29
|
set_error Solargraph::LanguageServer::ErrorCodes::INVALID_PARAMS, "Unknown change type ##{change['type']} for #{uri_to_file(change['uri'])}"
|
|
27
30
|
end
|
|
28
31
|
end
|
|
32
|
+
|
|
33
|
+
host.create *to_create
|
|
34
|
+
host.delete *to_delete
|
|
35
|
+
|
|
29
36
|
# Force host to catalog libraries after file changes (see castwide/solargraph#139)
|
|
30
37
|
host.catalog if need_catalog
|
|
31
38
|
end
|
|
@@ -8,7 +8,7 @@ class Solargraph::LanguageServer::Message::Workspace::WorkspaceSymbol < Solargra
|
|
|
8
8
|
info = pins.map do |pin|
|
|
9
9
|
uri = file_to_uri(pin.location.filename)
|
|
10
10
|
{
|
|
11
|
-
name: pin.
|
|
11
|
+
name: pin.path,
|
|
12
12
|
containerName: pin.namespace,
|
|
13
13
|
kind: pin.symbol_kind,
|
|
14
14
|
location: {
|
|
@@ -14,7 +14,7 @@ module Solargraph
|
|
|
14
14
|
# @param uri [String]
|
|
15
15
|
# @return [String]
|
|
16
16
|
def uri_to_file uri
|
|
17
|
-
decode(uri).sub(/^file
|
|
17
|
+
decode(uri).sub(/^file\:(?:\/\/)?/, '').sub(/^\/([a-z]\:)/i, '\1')
|
|
18
18
|
end
|
|
19
19
|
|
|
20
20
|
# Convert a file path to a URI.
|
data/lib/solargraph/library.rb
CHANGED
|
@@ -106,36 +106,37 @@ module Solargraph
|
|
|
106
106
|
result
|
|
107
107
|
end
|
|
108
108
|
|
|
109
|
-
# Create
|
|
109
|
+
# Create file sources from files on disk. A file is ignored if it is
|
|
110
110
|
# neither open in the library nor included in the workspace.
|
|
111
111
|
#
|
|
112
|
-
# @param
|
|
113
|
-
# @return [Boolean] True if
|
|
114
|
-
def create_from_disk
|
|
112
|
+
# @param filenames [Array<String>]
|
|
113
|
+
# @return [Boolean] True if at least one file was added to the workspace.
|
|
114
|
+
def create_from_disk *filenames
|
|
115
115
|
result = false
|
|
116
116
|
mutex.synchronize do
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
workspace.merge(
|
|
121
|
-
maybe_map source
|
|
122
|
-
result = true
|
|
117
|
+
sources = filenames
|
|
118
|
+
.reject { |filename| File.directory?(filename) || !File.exist?(filename) }
|
|
119
|
+
.map { |filename| Solargraph::Source.load_string(File.read(filename), filename) }
|
|
120
|
+
result = workspace.merge(*sources)
|
|
121
|
+
sources.each { |source| maybe_map source }
|
|
123
122
|
end
|
|
124
123
|
result
|
|
125
124
|
end
|
|
126
125
|
|
|
127
|
-
# Delete
|
|
126
|
+
# Delete files from the library. Deleting a file will make it unavailable
|
|
128
127
|
# for checkout and optionally remove it from the workspace unless the
|
|
129
128
|
# workspace configuration determines that it should still exist.
|
|
130
129
|
#
|
|
131
|
-
# @param
|
|
132
|
-
# @return [Boolean] True if
|
|
133
|
-
def delete
|
|
134
|
-
detach filename
|
|
130
|
+
# @param filenames [Array<String>]
|
|
131
|
+
# @return [Boolean] True if any file was deleted
|
|
132
|
+
def delete *filenames
|
|
135
133
|
result = false
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
134
|
+
filenames.each do |filename|
|
|
135
|
+
detach filename
|
|
136
|
+
mutex.synchronize do
|
|
137
|
+
result ||= workspace.remove(filename)
|
|
138
|
+
@synchronized = !result if synchronized?
|
|
139
|
+
end
|
|
139
140
|
end
|
|
140
141
|
result
|
|
141
142
|
end
|
|
@@ -267,7 +268,7 @@ module Solargraph
|
|
|
267
268
|
next unless source_map_hash.key?(full)
|
|
268
269
|
return Location.new(full, Solargraph::Range.from_to(0, 0, 0, 0))
|
|
269
270
|
end
|
|
270
|
-
api_map.yard_map.require_reference(pin.name)
|
|
271
|
+
# api_map.yard_map.require_reference(pin.name)
|
|
271
272
|
rescue FileNotFoundError
|
|
272
273
|
nil
|
|
273
274
|
end
|
|
@@ -522,7 +523,7 @@ module Solargraph
|
|
|
522
523
|
return unless source
|
|
523
524
|
return unless @current == source || workspace.has_file?(source.filename)
|
|
524
525
|
if source_map_hash.key?(source.filename)
|
|
525
|
-
return if source_map_hash[source.filename].code == source.code &&
|
|
526
|
+
return if source_map_hash[source.filename].code == source.code &&
|
|
526
527
|
source_map_hash[source.filename].source.synchronized? &&
|
|
527
528
|
source.synchronized?
|
|
528
529
|
if source.synchronized?
|
|
@@ -115,16 +115,11 @@ module Solargraph
|
|
|
115
115
|
result = []
|
|
116
116
|
if node.type == :str
|
|
117
117
|
result.push Range.from_node(node)
|
|
118
|
-
elsif node.type == :dstr
|
|
119
|
-
here = Range.from_node(node)
|
|
120
|
-
there = Range.from_node(node.children[1])
|
|
121
|
-
result.push Range.new(here.start, there.start)
|
|
122
118
|
end
|
|
123
119
|
node.children.each do |child|
|
|
124
120
|
result.concat string_ranges(child)
|
|
125
121
|
end
|
|
126
122
|
if node.type == :dstr && node.children.last.nil?
|
|
127
|
-
# result.push Range.new(result.last.ending, result.last.ending)
|
|
128
123
|
last = node.children[-2]
|
|
129
124
|
unless last.nil?
|
|
130
125
|
rng = Range.from_node(last)
|
|
@@ -8,16 +8,26 @@ module Solargraph
|
|
|
8
8
|
include Legacy::NodeMethods
|
|
9
9
|
|
|
10
10
|
def process
|
|
11
|
-
here = get_node_start_position(node)
|
|
12
11
|
pins.push Solargraph::Pin::Constant.new(
|
|
13
12
|
location: get_node_location(node),
|
|
14
13
|
closure: region.closure,
|
|
15
|
-
name:
|
|
14
|
+
name: const_name,
|
|
16
15
|
comments: comments_for(node),
|
|
17
16
|
assignment: node.children[2]
|
|
18
17
|
)
|
|
19
18
|
process_children
|
|
20
19
|
end
|
|
20
|
+
|
|
21
|
+
private
|
|
22
|
+
|
|
23
|
+
# @return [String]
|
|
24
|
+
def const_name
|
|
25
|
+
if node.children[0]
|
|
26
|
+
Parser::NodeMethods.unpack_name(node.children[0]) + "::#{node.children[1]}"
|
|
27
|
+
else
|
|
28
|
+
node.children[1].to_s
|
|
29
|
+
end
|
|
30
|
+
end
|
|
21
31
|
end
|
|
22
32
|
end
|
|
23
33
|
end
|
|
@@ -6,11 +6,32 @@ module Solargraph
|
|
|
6
6
|
module NodeProcessors
|
|
7
7
|
class SclassNode < Parser::NodeProcessor::Base
|
|
8
8
|
def process
|
|
9
|
-
|
|
10
|
-
|
|
9
|
+
sclass = node.children[0]
|
|
10
|
+
if sclass.is_a?(AST::Node) && sclass.type == :self
|
|
11
|
+
closure = region.closure
|
|
12
|
+
elsif sclass.is_a?(AST::Node) && sclass.type == :casgn
|
|
13
|
+
names = [region.closure.namespace, region.closure.name]
|
|
14
|
+
if sclass.children[0].nil? && names.last != sclass.children[1].to_s
|
|
15
|
+
names << sclass.children[1].to_s
|
|
16
|
+
else
|
|
17
|
+
names.concat [NodeMethods.unpack_name(sclass.children[0]), sclass.children[1].to_s]
|
|
18
|
+
end
|
|
19
|
+
name = names.reject(&:empty?).join('::')
|
|
20
|
+
closure = Solargraph::Pin::Namespace.new(name: name, location: region.closure.location)
|
|
21
|
+
elsif sclass.is_a?(AST::Node) && sclass.type == :const
|
|
22
|
+
names = [region.closure.namespace, region.closure.name]
|
|
23
|
+
also = NodeMethods.unpack_name(sclass)
|
|
24
|
+
if also != region.closure.name
|
|
25
|
+
names << also
|
|
26
|
+
end
|
|
27
|
+
name = names.reject(&:empty?).join('::')
|
|
28
|
+
closure = Solargraph::Pin::Namespace.new(name: name, location: region.closure.location)
|
|
29
|
+
else
|
|
30
|
+
return
|
|
31
|
+
end
|
|
11
32
|
pins.push Solargraph::Pin::Singleton.new(
|
|
12
33
|
location: get_node_location(node),
|
|
13
|
-
closure:
|
|
34
|
+
closure: closure
|
|
14
35
|
)
|
|
15
36
|
process_children region.update(visibility: :public, scope: :class, closure: pins.last)
|
|
16
37
|
end
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
require 'solargraph/parser/rubyvm/node_processors'
|
|
2
|
+
require 'solargraph/parser/rubyvm/node_wrapper'
|
|
2
3
|
|
|
3
4
|
module Solargraph
|
|
4
5
|
module Parser
|
|
@@ -7,8 +8,10 @@ module Solargraph
|
|
|
7
8
|
# @param code [String]
|
|
8
9
|
# @param filename [String]
|
|
9
10
|
# @return [Array(Parser::AST::Node, Array<Parser::Source::Comment>)]
|
|
11
|
+
# @sg-ignore
|
|
10
12
|
def parse_with_comments code, filename = nil
|
|
11
13
|
node = RubyVM::AbstractSyntaxTree.parse(code).children[2]
|
|
14
|
+
node &&= RubyVM::AbstractSyntaxTree::NodeWrapper.from(node, code.lines)
|
|
12
15
|
comments = CommentRipper.new(code).parse
|
|
13
16
|
[node, comments]
|
|
14
17
|
rescue ::SyntaxError => e
|
|
@@ -19,8 +22,10 @@ module Solargraph
|
|
|
19
22
|
# @param filename [String, nil]
|
|
20
23
|
# @param line [Integer]
|
|
21
24
|
# @return [Parser::AST::Node]
|
|
25
|
+
# @sg-ignore
|
|
22
26
|
def parse code, filename = nil, line = 0
|
|
23
|
-
RubyVM::AbstractSyntaxTree.parse(code).children[2]
|
|
27
|
+
node = RubyVM::AbstractSyntaxTree.parse(code).children[2]
|
|
28
|
+
node and RubyVM::AbstractSyntaxTree::NodeWrapper.from(node, code.lines)
|
|
24
29
|
rescue ::SyntaxError => e
|
|
25
30
|
raise Parser::SyntaxError, e.message
|
|
26
31
|
end
|
|
@@ -87,7 +92,7 @@ module Solargraph
|
|
|
87
92
|
end
|
|
88
93
|
|
|
89
94
|
def infer_literal_node_type node
|
|
90
|
-
|
|
95
|
+
NodeMethods.infer_literal_node_type node
|
|
91
96
|
end
|
|
92
97
|
|
|
93
98
|
def version
|
|
@@ -123,13 +128,12 @@ module Solargraph
|
|
|
123
128
|
elsif node.type == :DSTR
|
|
124
129
|
here = Range.from_node(node)
|
|
125
130
|
there = Range.from_node(node.children[1])
|
|
126
|
-
result.push Range.new(here.start, there.
|
|
131
|
+
result.push Range.new(here.start, there&.start || here.ending)
|
|
127
132
|
end
|
|
128
133
|
node.children.each do |child|
|
|
129
134
|
result.concat string_ranges(child)
|
|
130
135
|
end
|
|
131
136
|
if node.type == :DSTR && node.children.last.nil?
|
|
132
|
-
# result.push Range.new(result.last.ending, result.last.ending)
|
|
133
137
|
last = node.children[-2]
|
|
134
138
|
unless last.nil?
|
|
135
139
|
rng = Range.from_node(last)
|
|
@@ -9,12 +9,23 @@ module Solargraph
|
|
|
9
9
|
pins.push Solargraph::Pin::Constant.new(
|
|
10
10
|
location: get_node_location(node),
|
|
11
11
|
closure: region.closure,
|
|
12
|
-
name:
|
|
12
|
+
name: const_name,
|
|
13
13
|
comments: comments_for(node),
|
|
14
|
-
assignment: node.children[1]
|
|
14
|
+
assignment: node.children[2] || node.children[1]
|
|
15
15
|
)
|
|
16
16
|
process_children
|
|
17
17
|
end
|
|
18
|
+
|
|
19
|
+
private
|
|
20
|
+
|
|
21
|
+
# @return [String]
|
|
22
|
+
def const_name
|
|
23
|
+
if Parser.is_ast_node?(node.children[0])
|
|
24
|
+
Parser::NodeMethods.unpack_name(node.children[0])
|
|
25
|
+
else
|
|
26
|
+
node.children[0].to_s
|
|
27
|
+
end
|
|
28
|
+
end
|
|
18
29
|
end
|
|
19
30
|
end
|
|
20
31
|
end
|
|
@@ -6,7 +6,8 @@ module Solargraph
|
|
|
6
6
|
module NodeProcessors
|
|
7
7
|
class DefNode < Parser::NodeProcessor::Base
|
|
8
8
|
def process
|
|
9
|
-
|
|
9
|
+
anon_splat = node_has_anon_splat?
|
|
10
|
+
|
|
10
11
|
methpin = Solargraph::Pin::Method.new(
|
|
11
12
|
location: get_node_location(node),
|
|
12
13
|
closure: region.closure,
|
|
@@ -14,17 +15,19 @@ module Solargraph
|
|
|
14
15
|
comments: comments_for(node),
|
|
15
16
|
scope: region.scope || (region.closure.is_a?(Pin::Singleton) ? :class : :instance),
|
|
16
17
|
visibility: region.visibility,
|
|
17
|
-
node: node
|
|
18
|
+
node: node,
|
|
19
|
+
anon_splat: anon_splat
|
|
18
20
|
)
|
|
19
|
-
if methpin.name == 'initialize'
|
|
21
|
+
if methpin.name == 'initialize' && methpin.scope == :instance
|
|
20
22
|
pins.push Solargraph::Pin::Method.new(
|
|
21
23
|
location: methpin.location,
|
|
22
24
|
closure: methpin.closure,
|
|
23
25
|
name: 'new',
|
|
24
26
|
comments: methpin.comments,
|
|
25
27
|
scope: :class,
|
|
26
|
-
parameters: methpin.parameters
|
|
27
|
-
|
|
28
|
+
parameters: methpin.parameters,
|
|
29
|
+
anon_splat: anon_splat
|
|
30
|
+
)
|
|
28
31
|
# @todo Smelly instance variable access.
|
|
29
32
|
pins.last.instance_variable_set(:@return_type, ComplexType::SELF)
|
|
30
33
|
pins.push methpin
|
|
@@ -40,8 +43,9 @@ module Solargraph
|
|
|
40
43
|
scope: :class,
|
|
41
44
|
visibility: :public,
|
|
42
45
|
parameters: methpin.parameters,
|
|
43
|
-
node: methpin.node
|
|
44
|
-
|
|
46
|
+
node: methpin.node,
|
|
47
|
+
anon_splat: anon_splat
|
|
48
|
+
)
|
|
45
49
|
pins.push Solargraph::Pin::Method.new(
|
|
46
50
|
location: methpin.location,
|
|
47
51
|
closure: methpin.closure,
|
|
@@ -50,13 +54,20 @@ module Solargraph
|
|
|
50
54
|
scope: :instance,
|
|
51
55
|
visibility: :private,
|
|
52
56
|
parameters: methpin.parameters,
|
|
53
|
-
node: methpin.node
|
|
54
|
-
|
|
57
|
+
node: methpin.node,
|
|
58
|
+
anon_splat: anon_splat
|
|
59
|
+
)
|
|
55
60
|
else
|
|
56
61
|
pins.push methpin
|
|
57
62
|
end
|
|
58
63
|
process_children region.update(closure: methpin, scope: methpin.scope)
|
|
59
64
|
end
|
|
65
|
+
|
|
66
|
+
private
|
|
67
|
+
|
|
68
|
+
def node_has_anon_splat?
|
|
69
|
+
node.children[1]&.children&.first == [nil]
|
|
70
|
+
end
|
|
60
71
|
end
|
|
61
72
|
end
|
|
62
73
|
end
|