solargraph 0.12.2 → 0.13.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/lib/solargraph.rb +1 -0
- data/lib/solargraph/api_map.rb +179 -431
- data/lib/solargraph/api_map/cache.rb +4 -0
- data/lib/solargraph/api_map/config.rb +1 -1
- data/lib/solargraph/api_map/source.rb +297 -0
- data/lib/solargraph/code_map.rb +81 -134
- data/lib/solargraph/pin.rb +12 -0
- data/lib/solargraph/pin/attribute.rb +16 -0
- data/lib/solargraph/pin/base.rb +47 -0
- data/lib/solargraph/pin/base_variable.rb +33 -0
- data/lib/solargraph/pin/class_variable.rb +6 -0
- data/lib/solargraph/pin/constant.rb +18 -0
- data/lib/solargraph/pin/instance_variable.rb +12 -0
- data/lib/solargraph/pin/method.rb +65 -0
- data/lib/solargraph/pin/symbol.rb +9 -0
- data/lib/solargraph/server.rb +15 -7
- data/lib/solargraph/shell.rb +7 -0
- data/lib/solargraph/suggestion.rb +7 -2
- data/lib/solargraph/version.rb +1 -1
- data/lib/solargraph/yard_map.rb +1 -1
- data/lib/solargraph/yard_methods.rb +28 -1
- metadata +12 -6
- data/lib/solargraph/api_map/attr_pin.rb +0 -37
- data/lib/solargraph/api_map/cvar_pin.rb +0 -27
- data/lib/solargraph/api_map/ivar_pin.rb +0 -29
- data/lib/solargraph/api_map/method_pin.rb +0 -56
@@ -0,0 +1,12 @@
|
|
1
|
+
module Solargraph
|
2
|
+
module Pin
|
3
|
+
autoload :Base, 'solargraph/pin/base'
|
4
|
+
autoload :Method, 'solargraph/pin/method'
|
5
|
+
autoload :Attribute, 'solargraph/pin/attribute'
|
6
|
+
autoload :BaseVariable, 'solargraph/pin/base_variable'
|
7
|
+
autoload :InstanceVariable, 'solargraph/pin/instance_variable'
|
8
|
+
autoload :ClassVariable, 'solargraph/pin/class_variable'
|
9
|
+
autoload :Constant, 'solargraph/pin/constant'
|
10
|
+
autoload :Symbol, 'solargraph/pin/symbol'
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module Solargraph
|
2
|
+
module Pin
|
3
|
+
class Attribute < Base
|
4
|
+
attr_reader :access
|
5
|
+
|
6
|
+
def initialize source, node, namespace, access
|
7
|
+
super(source, node, namespace)
|
8
|
+
@access = access
|
9
|
+
end
|
10
|
+
|
11
|
+
def name
|
12
|
+
@name ||= "#{node.children[0]}#{access == :writer ? '=' : ''}"
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
module Solargraph
|
2
|
+
module Pin
|
3
|
+
class Base
|
4
|
+
attr_reader :source
|
5
|
+
attr_reader :node
|
6
|
+
attr_reader :namespace
|
7
|
+
|
8
|
+
def initialize source, node, namespace
|
9
|
+
@source = source
|
10
|
+
@node = node
|
11
|
+
@namespace = namespace
|
12
|
+
end
|
13
|
+
|
14
|
+
def docstring
|
15
|
+
@docstring ||= source.docstring_for(node)
|
16
|
+
end
|
17
|
+
|
18
|
+
def name
|
19
|
+
nil
|
20
|
+
end
|
21
|
+
|
22
|
+
def path
|
23
|
+
nil
|
24
|
+
end
|
25
|
+
|
26
|
+
def kind
|
27
|
+
nil
|
28
|
+
end
|
29
|
+
|
30
|
+
def return_type
|
31
|
+
nil
|
32
|
+
end
|
33
|
+
|
34
|
+
def signature
|
35
|
+
nil
|
36
|
+
end
|
37
|
+
|
38
|
+
def value
|
39
|
+
nil
|
40
|
+
end
|
41
|
+
|
42
|
+
def parameters
|
43
|
+
[]
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
module Solargraph
|
2
|
+
module Pin
|
3
|
+
class BaseVariable < Base
|
4
|
+
include NodeMethods
|
5
|
+
|
6
|
+
def name
|
7
|
+
node.children[0].to_s
|
8
|
+
end
|
9
|
+
|
10
|
+
def kind
|
11
|
+
Solargraph::Suggestion::VARIABLE
|
12
|
+
end
|
13
|
+
|
14
|
+
def return_type
|
15
|
+
if @return_type.nil? and !docstring.nil?
|
16
|
+
tag = docstring.tag(:type)
|
17
|
+
@return_type = tag.types[0] unless tag.nil?
|
18
|
+
end
|
19
|
+
@return_type ||= literal_from_assignment
|
20
|
+
end
|
21
|
+
|
22
|
+
def signature
|
23
|
+
@signature ||= resolve_node_signature(node.children[(node.type == :casgn ? 2 : 1)])
|
24
|
+
end
|
25
|
+
|
26
|
+
private
|
27
|
+
|
28
|
+
def literal_from_assignment
|
29
|
+
infer_literal_node_type(node.children[(node.type == :casgn ? 2 : 1)])
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module Solargraph
|
2
|
+
module Pin
|
3
|
+
class Constant < BaseVariable
|
4
|
+
|
5
|
+
def name
|
6
|
+
@name ||= node.children[1].to_s
|
7
|
+
end
|
8
|
+
|
9
|
+
def kind
|
10
|
+
Solargraph::Suggestion::CONSTANT
|
11
|
+
end
|
12
|
+
|
13
|
+
def value
|
14
|
+
source.code_for(node.children[2])
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,65 @@
|
|
1
|
+
module Solargraph
|
2
|
+
module Pin
|
3
|
+
class Method < Base
|
4
|
+
attr_reader :scope
|
5
|
+
attr_reader :visibility
|
6
|
+
|
7
|
+
def initialize source, node, namespace, scope, visibility
|
8
|
+
super(source, node, namespace)
|
9
|
+
@scope = scope
|
10
|
+
@visibility = visibility
|
11
|
+
end
|
12
|
+
|
13
|
+
def name
|
14
|
+
@name ||= "#{node.children[(node.type == :def ? 0 : 1)]}"
|
15
|
+
end
|
16
|
+
|
17
|
+
def path
|
18
|
+
@path ||= namespace + (scope == :instance ? '#' : '.') + name
|
19
|
+
end
|
20
|
+
|
21
|
+
def kind
|
22
|
+
Solargraph::Suggestion::METHOD
|
23
|
+
end
|
24
|
+
|
25
|
+
def return_type
|
26
|
+
if @return_type.nil? and !docstring.nil?
|
27
|
+
tag = docstring.tag(:return)
|
28
|
+
@return_type = tag.types[0] unless tag.nil?
|
29
|
+
end
|
30
|
+
@return_type
|
31
|
+
end
|
32
|
+
|
33
|
+
def parameters
|
34
|
+
@parameters ||= get_method_args
|
35
|
+
end
|
36
|
+
|
37
|
+
private
|
38
|
+
|
39
|
+
# @return [Array<String>]
|
40
|
+
def get_method_args
|
41
|
+
list = nil
|
42
|
+
args = []
|
43
|
+
node.children.each { |c|
|
44
|
+
if c.kind_of?(AST::Node) and c.type == :args
|
45
|
+
list = c
|
46
|
+
break
|
47
|
+
end
|
48
|
+
}
|
49
|
+
return args if list.nil?
|
50
|
+
list.children.each { |c|
|
51
|
+
if c.type == :arg
|
52
|
+
args.push c.children[0].to_s
|
53
|
+
elsif c.type == :optarg
|
54
|
+
args.push "#{c.children[0]} = #{source.code_for(c.children[1])}"
|
55
|
+
elsif c.type == :kwarg
|
56
|
+
args.push "#{c.children[0]}:"
|
57
|
+
elsif c.type == :kwoptarg
|
58
|
+
args.push "#{c.children[0]}: #{source.code_for(c.children[1])}"
|
59
|
+
end
|
60
|
+
}
|
61
|
+
args
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
data/lib/solargraph/server.rb
CHANGED
@@ -21,8 +21,20 @@ module Solargraph
|
|
21
21
|
end
|
22
22
|
|
23
23
|
post '/prepare' do
|
24
|
+
content_type :json
|
24
25
|
STDERR.puts "Preparing #{params['workspace']}"
|
25
26
|
Server.prepare_workspace params['workspace']
|
27
|
+
{ "status" => "ok"}.to_json
|
28
|
+
end
|
29
|
+
|
30
|
+
post '/update' do
|
31
|
+
content_type :json
|
32
|
+
# @type [Solargraph::ApiMap]
|
33
|
+
api_map = @@api_hash[params['workspace']]
|
34
|
+
unless api_map.nil?
|
35
|
+
api_map.update params['filename']
|
36
|
+
end
|
37
|
+
{ "status" => "ok"}.to_json
|
26
38
|
end
|
27
39
|
|
28
40
|
post '/suggest' do
|
@@ -30,7 +42,6 @@ module Solargraph
|
|
30
42
|
begin
|
31
43
|
sugg = []
|
32
44
|
workspace = params['workspace']
|
33
|
-
#Server.prepare_workspace workspace unless @@api_hash.has_key?(workspace)
|
34
45
|
@@semaphore.synchronize {
|
35
46
|
code_map = CodeMap.new(code: params['text'], filename: params['filename'], api_map: @@api_hash[workspace], cursor: [params['line'].to_i, params['column'].to_i])
|
36
47
|
offset = code_map.get_offset(params['line'].to_i, params['column'].to_i)
|
@@ -49,7 +60,6 @@ module Solargraph
|
|
49
60
|
begin
|
50
61
|
sugg = []
|
51
62
|
workspace = params['workspace'] || nil
|
52
|
-
#Server.prepare_workspace workspace unless @@api_hash.has_key?(workspace)
|
53
63
|
@@semaphore.synchronize {
|
54
64
|
code_map = CodeMap.new(code: params['text'], filename: params['filename'], api_map: @@api_hash[workspace], cursor: [params['line'].to_i, params['column'].to_i])
|
55
65
|
offset = code_map.get_offset(params['line'].to_i, params['column'].to_i)
|
@@ -68,7 +78,6 @@ module Solargraph
|
|
68
78
|
begin
|
69
79
|
sugg = []
|
70
80
|
workspace = params['workspace'] || nil
|
71
|
-
#Server.prepare_workspace workspace unless @@api_hash.has_key?(workspace)
|
72
81
|
@@semaphore.synchronize {
|
73
82
|
code_map = CodeMap.new(code: params['text'], filename: params['filename'], api_map: @@api_hash[workspace], cursor: [params['line'].to_i, params['column'].to_i])
|
74
83
|
offset = code_map.get_offset(params['line'].to_i, params['column'].to_i)
|
@@ -127,13 +136,12 @@ module Solargraph
|
|
127
136
|
|
128
137
|
def prepare_workspace directory
|
129
138
|
Thread.new do
|
130
|
-
@@semaphore.synchronize
|
139
|
+
@@semaphore.synchronize do
|
131
140
|
api_map = Solargraph::ApiMap.new(directory)
|
132
|
-
api_map.update_yardoc
|
133
141
|
@@api_hash[directory] = api_map
|
134
|
-
|
142
|
+
end
|
135
143
|
end
|
136
|
-
|
144
|
+
end
|
137
145
|
end
|
138
146
|
|
139
147
|
class Helpers
|
data/lib/solargraph/shell.rb
CHANGED
@@ -7,6 +7,13 @@ require 'net/http'
|
|
7
7
|
|
8
8
|
module Solargraph
|
9
9
|
class Shell < Thor
|
10
|
+
map %w[--version -v] => :version
|
11
|
+
|
12
|
+
desc "--version, -v", "Print the version"
|
13
|
+
def version
|
14
|
+
puts Solargraph::VERSION
|
15
|
+
end
|
16
|
+
|
10
17
|
desc 'prepare', 'Cache YARD files for the current environment'
|
11
18
|
option :force, type: :boolean, aliases: :f, desc: 'Force download of YARDOC files if they already exist'
|
12
19
|
option :host, type: :string, aliases: :h, desc: 'The host that provides YARDOC files for download', default: 'yardoc.solargraph.org'
|
@@ -15,7 +15,7 @@ module Solargraph
|
|
15
15
|
|
16
16
|
attr_reader :label, :kind, :insert, :detail, :documentation, :code_object, :location, :arguments
|
17
17
|
|
18
|
-
def initialize label, kind: KEYWORD, insert: nil, detail: nil, documentation: nil, code_object: nil, location: nil, arguments: [], return_type: nil
|
18
|
+
def initialize label, kind: KEYWORD, insert: nil, detail: nil, documentation: nil, code_object: nil, location: nil, arguments: [], return_type: nil, path: nil
|
19
19
|
@helper = Server::Helpers.new
|
20
20
|
@label = label.to_s
|
21
21
|
@kind = kind
|
@@ -26,10 +26,11 @@ module Solargraph
|
|
26
26
|
@location = location
|
27
27
|
@arguments = arguments
|
28
28
|
@return_type = return_type
|
29
|
+
@path = path
|
29
30
|
end
|
30
31
|
|
31
32
|
def path
|
32
|
-
code_object.nil? ? label : code_object.path
|
33
|
+
@path ||= (code_object.nil? ? label : code_object.path)
|
33
34
|
end
|
34
35
|
|
35
36
|
def to_s
|
@@ -97,6 +98,10 @@ module Solargraph
|
|
97
98
|
}
|
98
99
|
obj.to_json(args)
|
99
100
|
end
|
101
|
+
|
102
|
+
def self.pull pin, return_type = nil
|
103
|
+
Suggestion.new(pin.name, insert: pin.name.gsub(/=/, ' = '), kind: pin.kind, documentation: pin.docstring, detail: pin.namespace, arguments: pin.parameters, path: pin.path, return_type: return_type)
|
104
|
+
end
|
100
105
|
end
|
101
106
|
|
102
107
|
end
|
data/lib/solargraph/version.rb
CHANGED
data/lib/solargraph/yard_map.rb
CHANGED
@@ -13,7 +13,9 @@ module Solargraph
|
|
13
13
|
yardopts = File.read(yardopts_file)
|
14
14
|
yardopts.lines.each { |line|
|
15
15
|
arg = line.strip
|
16
|
-
if arg.start_with?('
|
16
|
+
if arg.start_with?('--exclude')
|
17
|
+
@yard_options[:exclude].concat arg.split(/[\s]+/)[1..-1]
|
18
|
+
elsif arg.start_with?('-')
|
17
19
|
@yard_options[:flags].push arg
|
18
20
|
else
|
19
21
|
@yard_options[:include].push arg
|
@@ -25,5 +27,30 @@ module Solargraph
|
|
25
27
|
end
|
26
28
|
@yard_options
|
27
29
|
end
|
30
|
+
|
31
|
+
def yard_files
|
32
|
+
if @yard_files.nil?
|
33
|
+
@yard_files = []
|
34
|
+
yard_options[:include].each do |glob|
|
35
|
+
if File.file?(glob)
|
36
|
+
@yard_files.push File.realpath(glob)
|
37
|
+
elsif File.directory?(glob)
|
38
|
+
@yard_files.concat Dir["#{glob}/**/*"].map{ |f| File.realpath(f) }
|
39
|
+
else
|
40
|
+
@yard_files.concat Dir[glob].map{ |f| File.realpath(f) }
|
41
|
+
end
|
42
|
+
end
|
43
|
+
yard_options[:exclude].each do |glob|
|
44
|
+
if File.file?(glob)
|
45
|
+
@yard_files.delete File.realpath(glob)
|
46
|
+
elsif File.directory?(glob)
|
47
|
+
@yard_files -= Dir["#{glob}/**/*"].map{ |f| File.realpath(f) }
|
48
|
+
else
|
49
|
+
@yard_files -= Dir[glob].map{ |f| File.realpath(f) }
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
@yard_files
|
54
|
+
end
|
28
55
|
end
|
29
56
|
end
|
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.
|
4
|
+
version: 0.13.0
|
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-
|
11
|
+
date: 2017-10-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: parser
|
@@ -158,14 +158,20 @@ files:
|
|
158
158
|
- bin/solargraph
|
159
159
|
- lib/solargraph.rb
|
160
160
|
- lib/solargraph/api_map.rb
|
161
|
-
- lib/solargraph/api_map/attr_pin.rb
|
162
161
|
- lib/solargraph/api_map/cache.rb
|
163
162
|
- lib/solargraph/api_map/config.rb
|
164
|
-
- lib/solargraph/api_map/
|
165
|
-
- lib/solargraph/api_map/ivar_pin.rb
|
166
|
-
- lib/solargraph/api_map/method_pin.rb
|
163
|
+
- lib/solargraph/api_map/source.rb
|
167
164
|
- lib/solargraph/code_map.rb
|
168
165
|
- lib/solargraph/node_methods.rb
|
166
|
+
- lib/solargraph/pin.rb
|
167
|
+
- lib/solargraph/pin/attribute.rb
|
168
|
+
- lib/solargraph/pin/base.rb
|
169
|
+
- lib/solargraph/pin/base_variable.rb
|
170
|
+
- lib/solargraph/pin/class_variable.rb
|
171
|
+
- lib/solargraph/pin/constant.rb
|
172
|
+
- lib/solargraph/pin/instance_variable.rb
|
173
|
+
- lib/solargraph/pin/method.rb
|
174
|
+
- lib/solargraph/pin/symbol.rb
|
169
175
|
- lib/solargraph/server.rb
|
170
176
|
- lib/solargraph/shell.rb
|
171
177
|
- lib/solargraph/snippets.rb
|
@@ -1,37 +0,0 @@
|
|
1
|
-
module Solargraph
|
2
|
-
class ApiMap
|
3
|
-
class AttrPin
|
4
|
-
attr_reader :node
|
5
|
-
|
6
|
-
def initialize node
|
7
|
-
@node = node
|
8
|
-
end
|
9
|
-
|
10
|
-
def suggestions
|
11
|
-
@suggestions ||= generate_suggestions
|
12
|
-
end
|
13
|
-
|
14
|
-
private
|
15
|
-
|
16
|
-
def generate_suggestions
|
17
|
-
suggestions = []
|
18
|
-
c = node
|
19
|
-
if c.kind_of?(AST::Node) and c.type == :send and c.children[1] == :attr_reader
|
20
|
-
c.children[2..-1].each { |x|
|
21
|
-
suggestions.push Suggestion.new(x.children[0], kind: Suggestion::FIELD) if x.type == :sym
|
22
|
-
}
|
23
|
-
elsif c.kind_of?(AST::Node) and c.type == :send and c.children[1] == :attr_writer
|
24
|
-
c.children[2..-1].each { |x|
|
25
|
-
suggestions.push Suggestion.new("#{x.children[0]}=", kind: Suggestion::FIELD) if x.type == :sym
|
26
|
-
}
|
27
|
-
elsif c.kind_of?(AST::Node) and c.type == :send and c.children[1] == :attr_accessor
|
28
|
-
c.children[2..-1].each { |x|
|
29
|
-
suggestions.push Suggestion.new(x.children[0], kind: Suggestion::FIELD) if x.type == :sym
|
30
|
-
suggestions.push Suggestion.new("#{x.children[0]}=", insert: "#{x.children[0]} = ", kind: Suggestion::FIELD) if x.type == :sym
|
31
|
-
}
|
32
|
-
end
|
33
|
-
suggestions
|
34
|
-
end
|
35
|
-
end
|
36
|
-
end
|
37
|
-
end
|