solargraph 0.14.2 → 0.14.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/solargraph.rb +0 -1
- data/lib/solargraph/api_map.rb +168 -123
- data/lib/solargraph/api_map/config.rb +41 -26
- data/lib/solargraph/api_map/source.rb +48 -31
- data/lib/solargraph/code_map.rb +22 -19
- data/lib/solargraph/live_map.rb +2 -1
- data/lib/solargraph/pin.rb +11 -10
- data/lib/solargraph/pin/base_variable.rb +4 -0
- data/lib/solargraph/pin/namespace.rb +23 -0
- data/lib/solargraph/plugin/process.rb +7 -5
- data/lib/solargraph/server.rb +57 -33
- data/lib/solargraph/shell.rb +4 -2
- data/lib/solargraph/suggestion.rb +1 -1
- data/lib/solargraph/version.rb +1 -1
- data/lib/solargraph/yard_map.rb +8 -5
- metadata +3 -17
- data/lib/solargraph/yard_methods.rb +0 -56
data/lib/solargraph/server.rb
CHANGED
@@ -1,13 +1,12 @@
|
|
1
1
|
require 'sinatra/base'
|
2
2
|
require 'thread'
|
3
3
|
require 'yard'
|
4
|
-
require 'puma'
|
5
4
|
|
6
5
|
module Solargraph
|
7
6
|
class Server < Sinatra::Base
|
8
7
|
|
9
8
|
set :port, 7657
|
10
|
-
set :server, :
|
9
|
+
set :server, :webrick
|
11
10
|
|
12
11
|
@@api_hash = {}
|
13
12
|
@@semaphore = Mutex.new
|
@@ -24,18 +23,30 @@ module Solargraph
|
|
24
23
|
post '/prepare' do
|
25
24
|
content_type :json
|
26
25
|
STDERR.puts "Preparing #{params['workspace']}"
|
27
|
-
|
28
|
-
|
26
|
+
begin
|
27
|
+
Server.prepare_workspace params['workspace']
|
28
|
+
{ "status" => "ok"}.to_json
|
29
|
+
rescue Exception => e
|
30
|
+
STDERR.puts e
|
31
|
+
STDERR.puts e.backtrace.join("\n")
|
32
|
+
{ "status" => "err", "message" => e.message + "\n" + e.backtrace.join("\n") }.to_json
|
33
|
+
end
|
29
34
|
end
|
30
35
|
|
31
36
|
post '/update' do
|
32
37
|
content_type :json
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
api_map.
|
38
|
+
begin
|
39
|
+
# @type [Solargraph::ApiMap]
|
40
|
+
api_map = get_api_map(params['workspace'])
|
41
|
+
unless api_map.nil?
|
42
|
+
api_map.update params['filename']
|
43
|
+
end
|
44
|
+
{ "status" => "ok"}.to_json
|
45
|
+
rescue Exception => e
|
46
|
+
STDERR.puts e
|
47
|
+
STDERR.puts e.backtrace.join("\n")
|
48
|
+
{ "status" => "err", "message" => e.message + "\n" + e.backtrace.join("\n") }.to_json
|
37
49
|
end
|
38
|
-
{ "status" => "ok"}.to_json
|
39
50
|
end
|
40
51
|
|
41
52
|
post '/suggest' do
|
@@ -43,10 +54,7 @@ module Solargraph
|
|
43
54
|
begin
|
44
55
|
sugg = []
|
45
56
|
workspace = params['workspace']
|
46
|
-
api_map =
|
47
|
-
@@semaphore.synchronize {
|
48
|
-
api_map = @@api_hash[workspace]
|
49
|
-
}
|
57
|
+
api_map = get_api_map(workspace)
|
50
58
|
with_all = params['all'] == '1' ? true : false
|
51
59
|
code_map = CodeMap.new(code: params['text'], filename: params['filename'], api_map: api_map, cursor: [params['line'].to_i, params['column'].to_i])
|
52
60
|
offset = code_map.get_offset(params['line'].to_i, params['column'].to_i)
|
@@ -64,11 +72,10 @@ module Solargraph
|
|
64
72
|
begin
|
65
73
|
sugg = []
|
66
74
|
workspace = params['workspace'] || nil
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
}
|
75
|
+
api_map = get_api_map(workspace)
|
76
|
+
code_map = CodeMap.new(code: params['text'], filename: params['filename'], api_map: api_map, cursor: [params['line'].to_i, params['column'].to_i])
|
77
|
+
offset = code_map.get_offset(params['line'].to_i, params['column'].to_i)
|
78
|
+
sugg = code_map.signatures_at(offset)
|
72
79
|
{ "status" => "ok", "suggestions" => sugg }.to_json
|
73
80
|
rescue Exception => e
|
74
81
|
STDERR.puts e
|
@@ -79,16 +86,20 @@ module Solargraph
|
|
79
86
|
|
80
87
|
post '/resolve' do
|
81
88
|
content_type :json
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
api_map =
|
89
|
+
begin
|
90
|
+
workspace = params['workspace'] || nil
|
91
|
+
result = []
|
92
|
+
api_map = get_api_map(workspace)
|
86
93
|
unless api_map.nil?
|
87
94
|
# @todo Get suggestions that match the path
|
88
95
|
result.concat api_map.get_path_suggestions(params['path'])
|
89
96
|
end
|
90
|
-
|
91
|
-
|
97
|
+
{ "status" => "ok", "suggestions" => result.map{|s| s.as_json(all: true)} }.to_json
|
98
|
+
rescue Exception => e
|
99
|
+
STDERR.puts e
|
100
|
+
STDERR.puts e.backtrace.join("\n")
|
101
|
+
{ "status" => "err", "message" => e.message + "\n" + e.backtrace.join("\n") }.to_json
|
102
|
+
end
|
92
103
|
end
|
93
104
|
|
94
105
|
post '/hover' do
|
@@ -96,11 +107,10 @@ module Solargraph
|
|
96
107
|
begin
|
97
108
|
sugg = []
|
98
109
|
workspace = params['workspace'] || nil
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
}
|
110
|
+
api_map = get_api_map(workspace)
|
111
|
+
code_map = CodeMap.new(code: params['text'], filename: params['filename'], api_map: @@api_hash[workspace], cursor: [params['line'].to_i, params['column'].to_i])
|
112
|
+
offset = code_map.get_offset(params['line'].to_i, params['column'].to_i)
|
113
|
+
sugg = code_map.resolve_object_at(offset)
|
104
114
|
{ "status" => "ok", "suggestions" => sugg }.to_json
|
105
115
|
rescue Exception => e
|
106
116
|
STDERR.puts e
|
@@ -111,7 +121,7 @@ module Solargraph
|
|
111
121
|
|
112
122
|
get '/search' do
|
113
123
|
workspace = params['workspace']
|
114
|
-
api_map =
|
124
|
+
api_map = get_api_map(workspace)
|
115
125
|
required = []
|
116
126
|
unless api_map.nil?
|
117
127
|
required.concat api_map.required
|
@@ -123,7 +133,7 @@ module Solargraph
|
|
123
133
|
|
124
134
|
get '/document' do
|
125
135
|
workspace = params['workspace']
|
126
|
-
api_map =
|
136
|
+
api_map = get_api_map(workspace)
|
127
137
|
required = []
|
128
138
|
unless api_map.nil?
|
129
139
|
required.concat api_map.required
|
@@ -137,6 +147,20 @@ module Solargraph
|
|
137
147
|
exit
|
138
148
|
end
|
139
149
|
|
150
|
+
# @return [Solargraph::ApiMap]
|
151
|
+
def self.get_api_map workspace
|
152
|
+
api_map = nil
|
153
|
+
@@semaphore.synchronize {
|
154
|
+
api_map = @@api_hash[workspace]
|
155
|
+
}
|
156
|
+
api_map
|
157
|
+
end
|
158
|
+
|
159
|
+
# @return [Solargraph::ApiMap]
|
160
|
+
def get_api_map workspace
|
161
|
+
Server.get_api_map workspace
|
162
|
+
end
|
163
|
+
|
140
164
|
def htmlify text
|
141
165
|
rdoc_to_html text
|
142
166
|
end
|
@@ -154,9 +178,9 @@ module Solargraph
|
|
154
178
|
class << self
|
155
179
|
def prepare_workspace directory
|
156
180
|
Thread.new do
|
181
|
+
api_map = Solargraph::ApiMap.new(directory)
|
182
|
+
api_map.yard_map
|
157
183
|
@@semaphore.synchronize do
|
158
|
-
api_map = Solargraph::ApiMap.new(directory)
|
159
|
-
api_map.yard_map
|
160
184
|
@@api_hash[directory] = api_map
|
161
185
|
end
|
162
186
|
end
|
data/lib/solargraph/shell.rb
CHANGED
@@ -56,13 +56,15 @@ module Solargraph
|
|
56
56
|
option :files, type: :string, aliases: :f, desc: 'The public files directory', default: nil
|
57
57
|
def server
|
58
58
|
port = options[:port]
|
59
|
-
|
59
|
+
# This line should not be necessary with WEBrick
|
60
|
+
#port = available_port if port.zero?
|
60
61
|
Solargraph::Server.set :port, port
|
61
62
|
Solargraph::Server.set :views, options[:views] unless options[:views].nil?
|
62
63
|
Solargraph::Server.set :public_folder, options[:files] unless options[:files].nil?
|
63
64
|
my_pid = nil
|
64
65
|
Solargraph::Server.run! do
|
65
|
-
|
66
|
+
# This line should not be necessary with WEBrick
|
67
|
+
#STDERR.puts "Solargraph server pid=#{Process.pid} port=#{port}"
|
66
68
|
my_pid = Process.pid
|
67
69
|
Signal.trap("INT") do
|
68
70
|
Solargraph::Server.stop!
|
@@ -121,7 +121,7 @@ module Solargraph
|
|
121
121
|
|
122
122
|
# @param pin [Solargraph::Pin::Base]
|
123
123
|
def self.pull pin, return_type = nil
|
124
|
-
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, location: pin.location)
|
124
|
+
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 || pin.return_type, location: pin.location)
|
125
125
|
end
|
126
126
|
end
|
127
127
|
|
data/lib/solargraph/version.rb
CHANGED
data/lib/solargraph/yard_map.rb
CHANGED
@@ -20,9 +20,9 @@ module Solargraph
|
|
20
20
|
used = []
|
21
21
|
@required = required
|
22
22
|
@namespace_yardocs = {}
|
23
|
-
if @required.include?('bundler/setup')
|
24
|
-
|
25
|
-
else
|
23
|
+
#if @required.include?('bundler/setup') or @required.include?('bundler/require')
|
24
|
+
# yardocs.concat bundled_gem_yardocs
|
25
|
+
#else
|
26
26
|
@required.each do |r|
|
27
27
|
if workspace.nil? or !File.exist?(File.join workspace, 'lib', "#{r}.rb")
|
28
28
|
g = r.split('/').first
|
@@ -39,7 +39,7 @@ module Solargraph
|
|
39
39
|
end
|
40
40
|
end
|
41
41
|
end
|
42
|
-
end
|
42
|
+
#end
|
43
43
|
yardocs.push File.join(Dir.home, '.solargraph', 'cache', '2.0.0', 'yardoc')
|
44
44
|
#yardocs.push File.join(Dir.home, '.solargraph', 'cache', '2.0.0', 'yardoc-stdlib')
|
45
45
|
yardocs.uniq!
|
@@ -122,19 +122,22 @@ module Solargraph
|
|
122
122
|
consts.each { |c|
|
123
123
|
detail = nil
|
124
124
|
kind = nil
|
125
|
+
return_type = nil
|
125
126
|
if c.kind_of?(YARD::CodeObjects::ClassObject)
|
126
127
|
detail = 'Class'
|
127
128
|
kind = Suggestion::CLASS
|
129
|
+
return_type = "Class<#{c.to_s}>"
|
128
130
|
elsif c.kind_of?(YARD::CodeObjects::ModuleObject)
|
129
131
|
detail = 'Module'
|
130
132
|
kind = Suggestion::MODULE
|
133
|
+
return_type = "Module<#{c.to_s}>"
|
131
134
|
elsif c.kind_of?(YARD::CodeObjects::ConstantObject)
|
132
135
|
detail = 'Constant'
|
133
136
|
kind = Suggestion::CONSTANT
|
134
137
|
else
|
135
138
|
next
|
136
139
|
end
|
137
|
-
result.push Suggestion.new(c.to_s.split('::').last, detail:
|
140
|
+
result.push Suggestion.new(c.to_s.split('::').last, detail: c.to_s, kind: kind, docstring: c.docstring, return_type: return_type)
|
138
141
|
}
|
139
142
|
cache.set_constants(namespace, scope, result)
|
140
143
|
result
|
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.14.
|
4
|
+
version: 0.14.3
|
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-
|
11
|
+
date: 2017-11-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: parser
|
@@ -86,20 +86,6 @@ dependencies:
|
|
86
86
|
- - "~>"
|
87
87
|
- !ruby/object:Gem::Version
|
88
88
|
version: '1.14'
|
89
|
-
- !ruby/object:Gem::Dependency
|
90
|
-
name: puma
|
91
|
-
requirement: !ruby/object:Gem::Requirement
|
92
|
-
requirements:
|
93
|
-
- - "~>"
|
94
|
-
- !ruby/object:Gem::Version
|
95
|
-
version: '3.8'
|
96
|
-
type: :runtime
|
97
|
-
prerelease: false
|
98
|
-
version_requirements: !ruby/object:Gem::Requirement
|
99
|
-
requirements:
|
100
|
-
- - "~>"
|
101
|
-
- !ruby/object:Gem::Version
|
102
|
-
version: '3.8'
|
103
89
|
- !ruby/object:Gem::Dependency
|
104
90
|
name: rspec
|
105
91
|
requirement: !ruby/object:Gem::Requirement
|
@@ -208,6 +194,7 @@ files:
|
|
208
194
|
- lib/solargraph/pin/instance_variable.rb
|
209
195
|
- lib/solargraph/pin/local_variable.rb
|
210
196
|
- lib/solargraph/pin/method.rb
|
197
|
+
- lib/solargraph/pin/namespace.rb
|
211
198
|
- lib/solargraph/pin/plugin/method.rb
|
212
199
|
- lib/solargraph/pin/symbol.rb
|
213
200
|
- lib/solargraph/plugin.rb
|
@@ -228,7 +215,6 @@ files:
|
|
228
215
|
- lib/solargraph/views/search.erb
|
229
216
|
- lib/solargraph/yard_map.rb
|
230
217
|
- lib/solargraph/yard_map/cache.rb
|
231
|
-
- lib/solargraph/yard_methods.rb
|
232
218
|
- lib/yard-solargraph.rb
|
233
219
|
- yardoc/2.0.0.tar.gz
|
234
220
|
homepage: http://solargraph.org
|
@@ -1,56 +0,0 @@
|
|
1
|
-
module Solargraph
|
2
|
-
module YardMethods
|
3
|
-
def yard_options
|
4
|
-
if @yard_options.nil?
|
5
|
-
@yard_options = {
|
6
|
-
include: [],
|
7
|
-
exclude: [],
|
8
|
-
flags: []
|
9
|
-
}
|
10
|
-
unless workspace.nil?
|
11
|
-
yardopts_file = File.join(workspace, '.yardopts')
|
12
|
-
if File.exist?(yardopts_file)
|
13
|
-
yardopts = File.read(yardopts_file)
|
14
|
-
yardopts.lines.each { |line|
|
15
|
-
arg = line.strip
|
16
|
-
if arg.start_with?('--exclude')
|
17
|
-
@yard_options[:exclude].concat arg.split(/[\s]+/)[1..-1]
|
18
|
-
elsif arg.start_with?('-')
|
19
|
-
@yard_options[:flags].push arg
|
20
|
-
else
|
21
|
-
@yard_options[:include].push arg
|
22
|
-
end
|
23
|
-
}
|
24
|
-
end
|
25
|
-
end
|
26
|
-
@yard_options[:include].concat ['app/**/*.rb', 'lib/**/*.rb'] if @yard_options[:include].empty?
|
27
|
-
end
|
28
|
-
@yard_options
|
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
|
55
|
-
end
|
56
|
-
end
|