solargraph 0.13.0 → 0.13.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.
- checksums.yaml +4 -4
- data/lib/solargraph/api_map/source.rb +55 -13
- data/lib/solargraph/api_map.rb +159 -106
- data/lib/solargraph/code_map.rb +120 -191
- data/lib/solargraph/node_methods.rb +5 -1
- data/lib/solargraph/pin/attribute.rb +14 -1
- data/lib/solargraph/pin/base.rb +18 -0
- data/lib/solargraph/pin/global_variable.rb +6 -0
- data/lib/solargraph/pin/local_variable.rb +25 -0
- data/lib/solargraph/pin/method.rb +2 -0
- data/lib/solargraph/pin.rb +2 -0
- data/lib/solargraph/server.rb +11 -7
- data/lib/solargraph/shell.rb +17 -2
- data/lib/solargraph/suggestion.rb +48 -36
- data/lib/solargraph/version.rb +1 -1
- data/lib/solargraph/yard_map/cache.rb +2 -2
- data/lib/solargraph/yard_map.rb +146 -91
- data/lib/yard-solargraph.rb +0 -23
- metadata +32 -2
data/lib/solargraph/server.rb
CHANGED
@@ -1,12 +1,13 @@
|
|
1
1
|
require 'sinatra/base'
|
2
2
|
require 'thread'
|
3
3
|
require 'yard'
|
4
|
+
require 'puma'
|
4
5
|
|
5
6
|
module Solargraph
|
6
7
|
class Server < Sinatra::Base
|
7
8
|
|
8
9
|
set :port, 7657
|
9
|
-
set :server, :
|
10
|
+
set :server, :puma
|
10
11
|
|
11
12
|
@@api_hash = {}
|
12
13
|
@@semaphore = Mutex.new
|
@@ -42,11 +43,13 @@ module Solargraph
|
|
42
43
|
begin
|
43
44
|
sugg = []
|
44
45
|
workspace = params['workspace']
|
46
|
+
api_map = nil
|
45
47
|
@@semaphore.synchronize {
|
46
|
-
|
47
|
-
offset = code_map.get_offset(params['line'].to_i, params['column'].to_i)
|
48
|
-
sugg = code_map.suggest_at(offset, with_snippets: params['with_snippets'] == '1' ? true : false, filtered: (params['filtered'] || false))
|
48
|
+
api_map = @@api_hash[workspace]
|
49
49
|
}
|
50
|
+
code_map = CodeMap.new(code: params['text'], filename: params['filename'], api_map: api_map, cursor: [params['line'].to_i, params['column'].to_i])
|
51
|
+
offset = code_map.get_offset(params['line'].to_i, params['column'].to_i)
|
52
|
+
sugg = code_map.suggest_at(offset, with_snippets: params['with_snippets'] == '1' ? true : false, filtered: true)
|
50
53
|
{ "status" => "ok", "suggestions" => sugg }.to_json
|
51
54
|
rescue Exception => e
|
52
55
|
STDERR.puts e
|
@@ -130,14 +133,15 @@ module Solargraph
|
|
130
133
|
end
|
131
134
|
|
132
135
|
class << self
|
133
|
-
def run!
|
134
|
-
|
135
|
-
end
|
136
|
+
#def run!
|
137
|
+
# super
|
138
|
+
#end
|
136
139
|
|
137
140
|
def prepare_workspace directory
|
138
141
|
Thread.new do
|
139
142
|
@@semaphore.synchronize do
|
140
143
|
api_map = Solargraph::ApiMap.new(directory)
|
144
|
+
api_map.yard_map
|
141
145
|
@@api_hash[directory] = api_map
|
142
146
|
end
|
143
147
|
end
|
data/lib/solargraph/shell.rb
CHANGED
@@ -4,6 +4,7 @@ require 'fileutils'
|
|
4
4
|
require 'rubygems/package'
|
5
5
|
require 'zlib'
|
6
6
|
require 'net/http'
|
7
|
+
require 'socket'
|
7
8
|
|
8
9
|
module Solargraph
|
9
10
|
class Shell < Thor
|
@@ -54,10 +55,14 @@ module Solargraph
|
|
54
55
|
option :views, type: :string, aliases: :v, desc: 'The view template directory', default: nil
|
55
56
|
option :files, type: :string, aliases: :f, desc: 'The public files directory', default: nil
|
56
57
|
def server
|
57
|
-
|
58
|
+
port = options[:port]
|
59
|
+
port = available_port if port.zero?
|
60
|
+
Solargraph::Server.set :port, port
|
58
61
|
Solargraph::Server.set :views, options[:views] unless options[:views].nil?
|
59
62
|
Solargraph::Server.set :public_folder, options[:files] unless options[:files].nil?
|
60
|
-
Solargraph::Server.run!
|
63
|
+
Solargraph::Server.run! do
|
64
|
+
STDERR.puts "Solargraph server pid=#{Process.pid} port=#{port}"
|
65
|
+
end
|
61
66
|
end
|
62
67
|
|
63
68
|
desc 'suggest', 'Get code suggestions for the provided input'
|
@@ -98,5 +103,15 @@ module Solargraph
|
|
98
103
|
end
|
99
104
|
STDOUT.puts "Configuration file initialized."
|
100
105
|
end
|
106
|
+
|
107
|
+
private
|
108
|
+
|
109
|
+
def available_port
|
110
|
+
socket = Socket.new(:INET, :STREAM, 0)
|
111
|
+
socket.bind(Addrinfo.tcp("127.0.0.1", 0))
|
112
|
+
port = socket.local_address.ip_port
|
113
|
+
socket.close
|
114
|
+
port
|
115
|
+
end
|
101
116
|
end
|
102
117
|
end
|
@@ -3,74 +3,86 @@ require 'json'
|
|
3
3
|
module Solargraph
|
4
4
|
|
5
5
|
class Suggestion
|
6
|
-
CLASS =
|
6
|
+
CLASS = 'Class'
|
7
7
|
CONSTANT = 'Constant'
|
8
|
-
|
9
|
-
|
10
|
-
METHOD =
|
11
|
-
|
8
|
+
FIELD = 'Field'
|
9
|
+
KEYWORD = 'Keyword'
|
10
|
+
METHOD = 'Method'
|
11
|
+
MODULE = 'Module'
|
12
12
|
PROPERTY = 'Property'
|
13
|
-
|
14
|
-
|
13
|
+
SNIPPET = 'Snippet'
|
14
|
+
VARIABLE = 'Variable'
|
15
|
+
|
16
|
+
# @return [String]
|
17
|
+
attr_reader :label
|
18
|
+
|
19
|
+
# @return [String]
|
20
|
+
attr_reader :kind
|
21
|
+
|
22
|
+
# @return [String]
|
23
|
+
attr_reader :insert
|
24
|
+
|
25
|
+
# @return [String]
|
26
|
+
attr_reader :detail
|
27
|
+
|
28
|
+
# @return [YARD::CodeObjects::Base]
|
29
|
+
attr_reader :code_object
|
30
|
+
|
31
|
+
# @return [String]
|
32
|
+
attr_reader :location
|
15
33
|
|
16
|
-
|
34
|
+
# @return [Array<String>]
|
35
|
+
attr_reader :arguments
|
17
36
|
|
18
|
-
def initialize label, kind: KEYWORD, insert: nil, detail: nil,
|
37
|
+
def initialize label, kind: KEYWORD, insert: nil, detail: nil, docstring: nil, code_object: nil, location: nil, arguments: [], return_type: nil, path: nil
|
19
38
|
@helper = Server::Helpers.new
|
20
39
|
@label = label.to_s
|
21
40
|
@kind = kind
|
22
41
|
@insert = insert || @label
|
23
42
|
@detail = detail
|
24
43
|
@code_object = code_object
|
25
|
-
@
|
44
|
+
@docstring = docstring
|
26
45
|
@location = location
|
27
46
|
@arguments = arguments
|
28
47
|
@return_type = return_type
|
29
48
|
@path = path
|
30
49
|
end
|
31
|
-
|
50
|
+
|
51
|
+
# @return [String]
|
32
52
|
def path
|
33
53
|
@path ||= (code_object.nil? ? label : code_object.path)
|
34
54
|
end
|
35
55
|
|
56
|
+
# @return [String]
|
36
57
|
def to_s
|
37
58
|
label
|
38
59
|
end
|
39
60
|
|
61
|
+
# @return [String]
|
40
62
|
def return_type
|
41
|
-
if @return_type.nil?
|
42
|
-
|
43
|
-
|
44
|
-
t = documentation.tag(:return)
|
45
|
-
@return_type = t.types[0] unless t.nil? or t.types.nil?
|
46
|
-
end
|
47
|
-
else
|
48
|
-
o = code_object.tag(:overload)
|
49
|
-
if o.nil?
|
50
|
-
r = code_object.tag(:return)
|
51
|
-
else
|
52
|
-
r = o.tag(:return)
|
53
|
-
end
|
54
|
-
@return_type = r.types[0] unless r.nil? or r.types.nil?
|
55
|
-
end
|
63
|
+
if @return_type.nil? and !docstring.nil?
|
64
|
+
t = docstring.tag(:overload)&.tag(:return) || docstring.tag(:return)
|
65
|
+
@return_type = t.types[0] unless t.nil? or t.types.nil?
|
56
66
|
end
|
57
67
|
@return_type
|
58
68
|
end
|
59
69
|
|
70
|
+
# @return [YARD::Docstring]
|
71
|
+
def docstring
|
72
|
+
@docstring ||= @code_object&.docstring
|
73
|
+
end
|
74
|
+
|
75
|
+
# @return [String]
|
60
76
|
def documentation
|
61
|
-
|
62
|
-
unless @code_object.nil? or @code_object.docstring.nil?
|
63
|
-
@documentation = @code_object.docstring
|
64
|
-
end
|
65
|
-
end
|
66
|
-
@documentation
|
77
|
+
@documentation ||= (docstring.nil? ? '' : @helper.html_markup_rdoc(docstring))
|
67
78
|
end
|
68
79
|
|
80
|
+
# @return [Array<String>]
|
69
81
|
def params
|
70
82
|
if @params.nil?
|
71
83
|
@params = []
|
72
|
-
return @params if
|
73
|
-
param_tags =
|
84
|
+
return @params if docstring.nil?
|
85
|
+
param_tags = docstring.tags(:param)
|
74
86
|
unless param_tags.empty?
|
75
87
|
param_tags.each do |t|
|
76
88
|
txt = t.name.to_s
|
@@ -94,13 +106,13 @@ module Solargraph
|
|
94
106
|
arguments: @arguments,
|
95
107
|
params: params,
|
96
108
|
return_type: return_type,
|
97
|
-
documentation: documentation
|
109
|
+
documentation: documentation
|
98
110
|
}
|
99
111
|
obj.to_json(args)
|
100
112
|
end
|
101
113
|
|
102
114
|
def self.pull pin, return_type = nil
|
103
|
-
Suggestion.new(pin.name, insert: pin.name.gsub(/=/, ' = '), kind: pin.kind,
|
115
|
+
Suggestion.new(pin.name, insert: pin.name.gsub(/=/, ' = '), kind: pin.kind, docstring: pin.docstring, detail: pin.namespace, arguments: pin.parameters, path: pin.path, return_type: return_type)
|
104
116
|
end
|
105
117
|
end
|
106
118
|
|
data/lib/solargraph/version.rb
CHANGED
@@ -15,7 +15,7 @@ module Solargraph
|
|
15
15
|
end
|
16
16
|
|
17
17
|
def set_methods namespace, scope, visibility, suggestions
|
18
|
-
@methods[[namespace, scope, visibility]] = suggestions
|
18
|
+
@methods[[namespace, scope, visibility]] = suggestions.uniq{|s| s.path}
|
19
19
|
end
|
20
20
|
|
21
21
|
def get_methods namespace, scope, visibility
|
@@ -23,7 +23,7 @@ module Solargraph
|
|
23
23
|
end
|
24
24
|
|
25
25
|
def set_instance_methods namespace, scope, visibility, suggestions
|
26
|
-
@instance_methods[[namespace, scope, visibility]] = suggestions
|
26
|
+
@instance_methods[[namespace, scope, visibility]] = suggestions.uniq{|s| s.path}
|
27
27
|
end
|
28
28
|
|
29
29
|
def get_instance_methods namespace, scope, visibility
|
data/lib/solargraph/yard_map.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
require 'parser/current'
|
2
2
|
require 'yard'
|
3
|
+
require 'bundler'
|
3
4
|
|
4
5
|
module Solargraph
|
5
6
|
|
@@ -7,32 +8,43 @@ module Solargraph
|
|
7
8
|
autoload :Cache, 'solargraph/yard_map/cache'
|
8
9
|
|
9
10
|
attr_reader :workspace
|
11
|
+
attr_reader :required
|
10
12
|
|
11
13
|
def initialize required: [], workspace: nil
|
12
14
|
@workspace = workspace
|
13
|
-
unless workspace.nil?
|
14
|
-
wsy = File.join(workspace, '.yardoc')
|
15
|
-
#yardocs.push wsy if File.exist?(wsy)
|
16
|
-
end
|
17
15
|
used = []
|
18
|
-
required
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
16
|
+
@required = required
|
17
|
+
@namespace_yardocs = {}
|
18
|
+
if @required.include?('bundler/setup')
|
19
|
+
yardocs.concat bundled_gem_yardocs
|
20
|
+
else
|
21
|
+
@required.each do |r|
|
22
|
+
if workspace.nil? or !File.exist?(File.join workspace, 'lib', "#{r}.rb")
|
23
|
+
g = r.split('/').first
|
24
|
+
unless used.include?(g)
|
25
|
+
used.push g
|
26
|
+
gy = YARD::Registry.yardoc_file_for_gem(g)
|
27
|
+
if gy.nil?
|
28
|
+
STDERR.puts "Required path not found: #{r}"
|
29
|
+
else
|
30
|
+
STDERR.puts "Adding #{gy}"
|
31
|
+
yardocs.unshift gy
|
32
|
+
add_gem_dependencies g
|
33
|
+
end
|
29
34
|
end
|
30
35
|
end
|
31
36
|
end
|
32
|
-
|
37
|
+
end
|
33
38
|
yardocs.push File.join(Dir.home, '.solargraph', 'cache', '2.0.0', 'yardoc')
|
34
39
|
yardocs.uniq!
|
35
|
-
|
40
|
+
yardocs.each do |y|
|
41
|
+
load_yardoc y
|
42
|
+
YARD::Registry.all(:class, :module).each do |ns|
|
43
|
+
@namespace_yardocs[ns.path] ||= []
|
44
|
+
@namespace_yardocs[ns.path].push y
|
45
|
+
end
|
46
|
+
end
|
47
|
+
#cache_core
|
36
48
|
end
|
37
49
|
|
38
50
|
# @return [Array<String>]
|
@@ -82,23 +94,20 @@ module Solargraph
|
|
82
94
|
end
|
83
95
|
|
84
96
|
# @return [Array<Suggestion>]
|
85
|
-
def get_constants namespace, scope = ''
|
97
|
+
def get_constants namespace , scope = ''
|
86
98
|
cached = cache.get_constants(namespace, scope)
|
87
99
|
return cached unless cached.nil?
|
88
100
|
consts = []
|
89
101
|
result = []
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
else
|
97
|
-
ns = yard.resolve(P(scope), namespace)
|
102
|
+
combined_namespaces(namespace, scope).each do |ns|
|
103
|
+
yardocs_documenting(ns).each do |y|
|
104
|
+
yard = load_yardoc(y)
|
105
|
+
unless yard.nil?
|
106
|
+
found = yard.at(ns)
|
107
|
+
consts.concat found.children unless found.nil?
|
98
108
|
end
|
99
|
-
consts += ns.children unless ns.nil?
|
100
109
|
end
|
101
|
-
|
110
|
+
end
|
102
111
|
consts.each { |c|
|
103
112
|
detail = nil
|
104
113
|
kind = nil
|
@@ -114,7 +123,7 @@ module Solargraph
|
|
114
123
|
else
|
115
124
|
next
|
116
125
|
end
|
117
|
-
result.push Suggestion.new(c.to_s.split('::').last, detail: detail, kind: kind,
|
126
|
+
result.push Suggestion.new(c.to_s.split('::').last, detail: detail, kind: kind, docstring: c.docstring)
|
118
127
|
}
|
119
128
|
cache.set_constants(namespace, scope, result)
|
120
129
|
result
|
@@ -125,48 +134,39 @@ module Solargraph
|
|
125
134
|
cached = cache.get_methods(namespace, scope, visibility)
|
126
135
|
return cached unless cached.nil?
|
127
136
|
meths = []
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
i = yard.at("#{ns}#initialize")
|
157
|
-
unless i.nil?
|
158
|
-
meths.delete_if{|m| m.label == 'new'}
|
159
|
-
label = "#{i}"
|
160
|
-
args = get_method_args(i)
|
161
|
-
meths.push Suggestion.new('new', kind: Suggestion::METHOD, documentation: i.docstring, code_object: i, detail: "#{ns}", location: "#{i.file}:#{i.line}", arguments: args)
|
137
|
+
combined_namespaces(namespace, scope).each do |ns|
|
138
|
+
yardocs_documenting(ns).each do |y|
|
139
|
+
yard = load_yardoc(y)
|
140
|
+
unless yard.nil?
|
141
|
+
ns = nil
|
142
|
+
ns = find_first_resolved_namespace(yard, namespace, scope)
|
143
|
+
unless ns.nil?
|
144
|
+
ns.meths(scope: :class, visibility: visibility).each { |m|
|
145
|
+
n = m.to_s.split(/[\.#]/).last.gsub(/=/, ' = ')
|
146
|
+
label = "#{n}"
|
147
|
+
args = get_method_args(m)
|
148
|
+
kind = (m.is_attribute? ? Suggestion::FIELD : Suggestion::METHOD)
|
149
|
+
meths.push Suggestion.new(label, insert: "#{n.gsub(/=/, ' = ')}", kind: kind, docstring: m.docstring, code_object: m, detail: "#{ns}", location: "#{m.file}:#{m.line}", arguments: args)
|
150
|
+
}
|
151
|
+
# Collect superclass methods
|
152
|
+
if ns.kind_of?(YARD::CodeObjects::ClassObject) and !ns.superclass.nil?
|
153
|
+
meths += get_methods ns.superclass.to_s, '', visibility: [:public, :protected] unless ['Object', 'BasicObject', ''].include?(ns.superclass.to_s)
|
154
|
+
end
|
155
|
+
if ns.kind_of?(YARD::CodeObjects::ClassObject) and namespace != 'Class'
|
156
|
+
meths += get_instance_methods('Class')
|
157
|
+
yard = load_yardoc(y)
|
158
|
+
i = yard.at("#{ns}#initialize")
|
159
|
+
unless i.nil?
|
160
|
+
meths.delete_if{|m| m.label == 'new'}
|
161
|
+
label = "#{i}"
|
162
|
+
args = get_method_args(i)
|
163
|
+
meths.push Suggestion.new('new', kind: Suggestion::METHOD, docstring: i.docstring, code_object: i, detail: "#{ns}", location: "#{i.file}:#{i.line}", arguments: args)
|
164
|
+
end
|
162
165
|
end
|
163
166
|
end
|
164
167
|
end
|
165
168
|
end
|
166
|
-
|
167
|
-
binds.each { |b|
|
168
|
-
meths += get_instance_methods(b, scope, visibility: [:public])
|
169
|
-
}
|
169
|
+
end
|
170
170
|
cache.set_methods(namespace, scope, visibility, meths)
|
171
171
|
meths
|
172
172
|
end
|
@@ -176,32 +176,34 @@ module Solargraph
|
|
176
176
|
cached = cache.get_instance_methods(namespace, scope, visibility)
|
177
177
|
return cached unless cached.nil?
|
178
178
|
meths = []
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
ns.
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
179
|
+
combined_namespaces(namespace, scope).each do |ns|
|
180
|
+
yardocs_documenting(ns).each do |y|
|
181
|
+
yard = load_yardoc(y)
|
182
|
+
unless yard.nil?
|
183
|
+
ns = nil
|
184
|
+
ns = find_first_resolved_namespace(yard, namespace, scope)
|
185
|
+
unless ns.nil?
|
186
|
+
ns.meths(scope: :instance, visibility: visibility).each { |m|
|
187
|
+
n = m.to_s.split(/[\.#]/).last
|
188
|
+
if n.to_s.match(/^[a-z]/i) and (namespace == 'Kernel' or !m.to_s.start_with?('Kernel#')) and !m.docstring.to_s.include?(':nodoc:')
|
189
|
+
label = "#{n}"
|
190
|
+
args = get_method_args(m)
|
191
|
+
kind = (m.is_attribute? ? Suggestion::FIELD : Suggestion::METHOD)
|
192
|
+
meths.push Suggestion.new(label, insert: "#{n.gsub(/=/, ' = ')}", kind: kind, docstring: m.docstring, code_object: m, detail: m.namespace, location: "#{m.file}:#{m.line}", arguments: args)
|
193
|
+
end
|
194
|
+
}
|
195
|
+
if ns.kind_of?(YARD::CodeObjects::ClassObject) and namespace != 'Object'
|
196
|
+
unless ns.nil?
|
197
|
+
meths += get_instance_methods(ns.superclass.to_s)
|
198
|
+
end
|
192
199
|
end
|
193
|
-
|
194
|
-
|
195
|
-
unless ns.nil?
|
196
|
-
meths += get_instance_methods(ns.superclass.to_s)
|
200
|
+
ns.instance_mixins.each do |m|
|
201
|
+
meths += get_instance_methods(m.to_s) unless m.to_s == 'Kernel'
|
197
202
|
end
|
198
203
|
end
|
199
|
-
ns.instance_mixins.each do |m|
|
200
|
-
meths += get_instance_methods(m.to_s) unless m.to_s == 'Kernel'
|
201
|
-
end
|
202
204
|
end
|
203
205
|
end
|
204
|
-
|
206
|
+
end
|
205
207
|
cache.set_instance_methods(namespace, scope, visibility, meths)
|
206
208
|
meths
|
207
209
|
end
|
@@ -232,10 +234,10 @@ module Solargraph
|
|
232
234
|
obj = yard.at(parts[0])
|
233
235
|
unless obj.nil?
|
234
236
|
meths = obj.meths(scope: [:instance]).keep_if{|m| m.name.to_s == parts[1]}
|
235
|
-
meths.each
|
237
|
+
meths.each do |m|
|
236
238
|
args = get_method_args(m)
|
237
239
|
result.push Solargraph::Suggestion.new(m.name, kind: 'Method', detail: m.path, code_object: m, arguments: args)
|
238
|
-
|
240
|
+
end
|
239
241
|
end
|
240
242
|
else
|
241
243
|
unless obj.nil?
|
@@ -250,6 +252,25 @@ module Solargraph
|
|
250
252
|
result
|
251
253
|
end
|
252
254
|
|
255
|
+
def bundled_gem_yardocs
|
256
|
+
result = []
|
257
|
+
unless workspace.nil?
|
258
|
+
gl = File.join(workspace, 'Gemfile.lock')
|
259
|
+
if File.file?(gl)
|
260
|
+
lockfile = Bundler::LockfileParser.new(Bundler.read_file(gl))
|
261
|
+
lockfile.specs.each do |s|
|
262
|
+
y = YARD::Registry.yardoc_file_for_gem(s.name, s.version.to_s)
|
263
|
+
if y.nil?
|
264
|
+
STDERR.puts "Bundled gem not found: #{s.name} #{s.version}"
|
265
|
+
else
|
266
|
+
result.push y
|
267
|
+
end
|
268
|
+
end
|
269
|
+
end
|
270
|
+
end
|
271
|
+
result.uniq
|
272
|
+
end
|
273
|
+
|
253
274
|
private
|
254
275
|
|
255
276
|
def cache
|
@@ -296,6 +317,40 @@ module Solargraph
|
|
296
317
|
nil
|
297
318
|
end
|
298
319
|
end
|
299
|
-
end
|
300
320
|
|
321
|
+
def add_gem_dependencies gem_name
|
322
|
+
spec = Gem::Specification.find_by_name(gem_name)
|
323
|
+
spec.nondevelopment_dependencies.each do |dep|
|
324
|
+
gy = YARD::Registry.yardoc_file_for_gem(dep.name)
|
325
|
+
if gy.nil?
|
326
|
+
STDERR.puts "Required path not found: #{r}"
|
327
|
+
else
|
328
|
+
STDERR.puts "Adding #{gy}"
|
329
|
+
yardocs.unshift gy
|
330
|
+
end
|
331
|
+
end
|
332
|
+
end
|
333
|
+
|
334
|
+
def combined_namespaces namespace, scope = ''
|
335
|
+
combined = [namespace]
|
336
|
+
unless scope.empty?
|
337
|
+
parts = scope.split('::')
|
338
|
+
until parts.empty?
|
339
|
+
combined.unshift parts.join('::') + '::' + namespace
|
340
|
+
parts.pop
|
341
|
+
end
|
342
|
+
end
|
343
|
+
combined
|
344
|
+
end
|
345
|
+
|
346
|
+
def yardocs_documenting namespace
|
347
|
+
result = []
|
348
|
+
if namespace == ''
|
349
|
+
result.concat yardocs
|
350
|
+
else
|
351
|
+
result.concat @namespace_yardocs[namespace] unless @namespace_yardocs[namespace].nil?
|
352
|
+
end
|
353
|
+
result
|
354
|
+
end
|
355
|
+
end
|
301
356
|
end
|
data/lib/yard-solargraph.rb
CHANGED
@@ -1,27 +1,4 @@
|
|
1
1
|
require 'yard'
|
2
|
-
require 'yard/handlers/ruby/base'
|
3
|
-
|
4
|
-
class YardHandlerExtension < YARD::Handlers::Ruby::HandlesExtension
|
5
|
-
def matches? node
|
6
|
-
if node.docstring and node.docstring.include?(name)
|
7
|
-
true
|
8
|
-
else
|
9
|
-
false
|
10
|
-
end
|
11
|
-
end
|
12
|
-
end
|
13
|
-
|
14
|
-
class MyHandler < YARD::Handlers::Ruby::CommentHandler
|
15
|
-
handles YardHandlerExtension.new("@bind")
|
16
|
-
|
17
|
-
process do
|
18
|
-
if owner.type == :root
|
19
|
-
d = YARD::Docstring.new(statement.docstring)
|
20
|
-
owner.add_tag d.tag(:bind)
|
21
|
-
end
|
22
|
-
end
|
23
|
-
end
|
24
2
|
|
25
3
|
# Define a @type tag to be used for documenting variables
|
26
4
|
YARD::Tags::Library.define_tag("Type", :type, :with_types_and_name)
|
27
|
-
YARD::Tags::Library.define_tag("Bind", :bind, :with_types)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: solargraph
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.13.
|
4
|
+
version: 0.13.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Fred Snyder
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-10-
|
11
|
+
date: 2017-10-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: parser
|
@@ -72,6 +72,34 @@ dependencies:
|
|
72
72
|
- - "~>"
|
73
73
|
- !ruby/object:Gem::Version
|
74
74
|
version: '0.9'
|
75
|
+
- !ruby/object:Gem::Dependency
|
76
|
+
name: bundler
|
77
|
+
requirement: !ruby/object:Gem::Requirement
|
78
|
+
requirements:
|
79
|
+
- - ">="
|
80
|
+
- !ruby/object:Gem::Version
|
81
|
+
version: '0'
|
82
|
+
type: :runtime
|
83
|
+
prerelease: false
|
84
|
+
version_requirements: !ruby/object:Gem::Requirement
|
85
|
+
requirements:
|
86
|
+
- - ">="
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
version: '0'
|
89
|
+
- !ruby/object:Gem::Dependency
|
90
|
+
name: puma
|
91
|
+
requirement: !ruby/object:Gem::Requirement
|
92
|
+
requirements:
|
93
|
+
- - ">="
|
94
|
+
- !ruby/object:Gem::Version
|
95
|
+
version: '0'
|
96
|
+
type: :runtime
|
97
|
+
prerelease: false
|
98
|
+
version_requirements: !ruby/object:Gem::Requirement
|
99
|
+
requirements:
|
100
|
+
- - ">="
|
101
|
+
- !ruby/object:Gem::Version
|
102
|
+
version: '0'
|
75
103
|
- !ruby/object:Gem::Dependency
|
76
104
|
name: rspec
|
77
105
|
requirement: !ruby/object:Gem::Requirement
|
@@ -169,7 +197,9 @@ files:
|
|
169
197
|
- lib/solargraph/pin/base_variable.rb
|
170
198
|
- lib/solargraph/pin/class_variable.rb
|
171
199
|
- lib/solargraph/pin/constant.rb
|
200
|
+
- lib/solargraph/pin/global_variable.rb
|
172
201
|
- lib/solargraph/pin/instance_variable.rb
|
202
|
+
- lib/solargraph/pin/local_variable.rb
|
173
203
|
- lib/solargraph/pin/method.rb
|
174
204
|
- lib/solargraph/pin/symbol.rb
|
175
205
|
- lib/solargraph/server.rb
|