solargraph 0.7.0 → 0.7.5
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.rb +18 -10
- data/lib/solargraph/code_map.rb +49 -8
- data/lib/solargraph/node_methods.rb +1 -3
- data/lib/solargraph/server.rb +1 -1
- data/lib/solargraph/version.rb +1 -1
- data/lib/solargraph/yard_map.rb +21 -15
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: bc699f1c3abc5198bf2fde325bb4dfde8c6cb384
|
|
4
|
+
data.tar.gz: 6f676543082c9943d647772d3c4c7f04ab4caefe
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: d519c282a68e56c063068d03a1d7067e98d544714e5b234b5f5da08c6b2e354fcc0067240bf6630eeeeb94b02cf57c1461715054b241febfe73217b53e6e3129
|
|
7
|
+
data.tar.gz: 57e7b7388f4aca96e654a1997cd8d236227f9ebb76f7b4d118ca2fe5e3e015955c583889693e683e81f37e978b5d8c5781d218b2e18af17e6d88262f7bde5f12
|
data/lib/solargraph/api_map.rb
CHANGED
|
@@ -10,7 +10,7 @@ module Solargraph
|
|
|
10
10
|
'begin', 'break', 'case', 'class', 'def', 'defined?', 'do', 'else',
|
|
11
11
|
'elsif', 'end', 'ensure', 'false', 'for', 'if', 'in', 'module', 'next',
|
|
12
12
|
'nil', 'not', 'or', 'redo', 'rescue', 'retry', 'return', 'self', 'super',
|
|
13
|
-
'then', 'true', 'undef', 'unless', 'until', 'when', 'while', 'yield'
|
|
13
|
+
'then', 'true', 'undef', 'unless', 'until', 'when', 'while', 'yield',
|
|
14
14
|
]
|
|
15
15
|
|
|
16
16
|
MAPPABLE_METHODS = [
|
|
@@ -97,10 +97,9 @@ module Solargraph
|
|
|
97
97
|
@file_comments[filename][node.loc]
|
|
98
98
|
end
|
|
99
99
|
|
|
100
|
-
def self.get_keywords
|
|
100
|
+
def self.get_keywords
|
|
101
101
|
result = []
|
|
102
|
-
keywords = KEYWORDS
|
|
103
|
-
keywords -= Snippets.keywords if without_snippets
|
|
102
|
+
keywords = KEYWORDS + MAPPABLE_METHODS
|
|
104
103
|
keywords.each { |k|
|
|
105
104
|
result.push Suggestion.new(k, kind: Suggestion::KEYWORD, detail: 'Keyword')
|
|
106
105
|
}
|
|
@@ -347,7 +346,7 @@ module Solargraph
|
|
|
347
346
|
unless p == 'new' and scope != :instance
|
|
348
347
|
if scope == :instance
|
|
349
348
|
meths = get_instance_methods(type)
|
|
350
|
-
meths += get_methods('') if top
|
|
349
|
+
meths += get_methods('') if top or type.to_s == ''
|
|
351
350
|
else
|
|
352
351
|
meths = get_methods(type)
|
|
353
352
|
#meths += get_methods('') if top
|
|
@@ -469,10 +468,17 @@ module Solargraph
|
|
|
469
468
|
Dir.chdir(workspace) do
|
|
470
469
|
#YARD::Registry.load(yard_options[:include] - yard_options[:exclude], true)
|
|
471
470
|
#YARD::Registry.save
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
471
|
+
Thread.new {
|
|
472
|
+
STDERR.puts "Updating the yardoc..."
|
|
473
|
+
globs = yard_options[:include] - yard_options[:exclude]
|
|
474
|
+
#cmd = "yardoc #{globs.join(' ')} -e #{Solargraph::YARD_EXTENSION_FILE} #{yard_options[:flags].join(' ')}"
|
|
475
|
+
cmd = "yardoc -e #{Solargraph::YARD_EXTENSION_FILE}"
|
|
476
|
+
STDERR.puts "Update yardoc with #{cmd}"
|
|
477
|
+
STDERR.puts `#{cmd}`
|
|
478
|
+
unless $?.success?
|
|
479
|
+
STDERR.puts "There was an error processing the workspace yardoc."
|
|
480
|
+
end
|
|
481
|
+
}
|
|
476
482
|
end
|
|
477
483
|
end
|
|
478
484
|
end
|
|
@@ -538,7 +544,9 @@ module Solargraph
|
|
|
538
544
|
if n.kind_of?(AST::Node)
|
|
539
545
|
if n.type == :class and !n.children[1].nil?
|
|
540
546
|
s = unpack_name(n.children[1])
|
|
541
|
-
|
|
547
|
+
# @todo This skip might not work properly. We might need to get a
|
|
548
|
+
# fully qualified namespace from it first
|
|
549
|
+
meths += get_instance_methods(s, namespace) unless skip.include?(s)
|
|
542
550
|
end
|
|
543
551
|
current_scope = :public
|
|
544
552
|
n.children.each { |c|
|
data/lib/solargraph/code_map.rb
CHANGED
|
@@ -4,6 +4,8 @@ module Solargraph
|
|
|
4
4
|
class CodeMap
|
|
5
5
|
attr_accessor :node
|
|
6
6
|
attr_accessor :api_map
|
|
7
|
+
attr_reader :code
|
|
8
|
+
attr_reader :parsed
|
|
7
9
|
|
|
8
10
|
include NodeMethods
|
|
9
11
|
|
|
@@ -20,23 +22,53 @@ module Solargraph
|
|
|
20
22
|
if @api_map.nil?
|
|
21
23
|
@api_map = ApiMap.new(workspace)
|
|
22
24
|
end
|
|
23
|
-
|
|
24
25
|
@code = code.gsub(/\r/, '')
|
|
25
26
|
tries = 0
|
|
26
27
|
# Hide incomplete code to avoid syntax errors
|
|
27
|
-
|
|
28
|
+
# @todo This might not be necessary given the corrected character
|
|
29
|
+
# replacement in retries.
|
|
30
|
+
#tmp = "#{@code}\nX".gsub(/[\.@]([\s])/, '#\1').gsub(/([\A\s]?)def([\s]*?[\n\Z])/, '\1#ef\2')
|
|
31
|
+
tmp = @code
|
|
28
32
|
begin
|
|
29
33
|
node, comments = Parser::CurrentRuby.parse_with_comments(tmp)
|
|
30
34
|
@node = @api_map.append_node(node, comments, filename)
|
|
35
|
+
@parsed = tmp
|
|
36
|
+
@code.freeze
|
|
37
|
+
@parsed.freeze
|
|
31
38
|
rescue Parser::SyntaxError => e
|
|
32
39
|
if tries < 10
|
|
40
|
+
STDERR.puts "Error parsing #{filename}: #{e.message}"
|
|
41
|
+
STDERR.puts "Retrying..."
|
|
33
42
|
tries += 1
|
|
34
43
|
spot = e.diagnostic.location.begin_pos
|
|
35
|
-
|
|
36
|
-
|
|
44
|
+
#STDERR.puts "CODE>>>>"
|
|
45
|
+
#STDERR.puts tmp
|
|
46
|
+
#STDERR.puts "<<<<CODE"
|
|
47
|
+
#STDERR.puts "Spot #{spot}: #{tmp[spot]}"
|
|
48
|
+
repl = '_'
|
|
49
|
+
if tmp[spot] == '@' or tmp[spot] == ':'
|
|
50
|
+
# Stub unfinished instance variables and symbols
|
|
51
|
+
spot -= 1
|
|
52
|
+
elsif tmp[spot - 1] == '.'
|
|
53
|
+
# Stub unfinished method calls
|
|
54
|
+
repl = '#' if spot == tmp.length or tmp[spot] == '\n'
|
|
55
|
+
spot -= 2
|
|
37
56
|
else
|
|
38
|
-
|
|
57
|
+
# Stub the whole line
|
|
58
|
+
spot = beginning_of_line_from(tmp, spot)
|
|
59
|
+
repl = '#'
|
|
60
|
+
if tmp[spot+1..-1].rstrip == 'end'
|
|
61
|
+
repl= 'end;end'
|
|
62
|
+
end
|
|
39
63
|
end
|
|
64
|
+
#if spot == 0
|
|
65
|
+
# tmp = '#' + tmp[1..-1]
|
|
66
|
+
#else
|
|
67
|
+
tmp = tmp[0..spot] + repl + tmp[spot+repl.length+1..-1].to_s
|
|
68
|
+
#end
|
|
69
|
+
#STDERR.puts "CHNG>>>>"
|
|
70
|
+
#STDERR.puts tmp
|
|
71
|
+
#STDERR.puts "<<<<CHNG"
|
|
40
72
|
retry
|
|
41
73
|
end
|
|
42
74
|
raise e
|
|
@@ -193,7 +225,7 @@ module Solargraph
|
|
|
193
225
|
parts = current_namespace.to_s.split('::')
|
|
194
226
|
result += get_snippets_at(index) if with_snippets
|
|
195
227
|
result += get_local_variables_and_methods_at(index)
|
|
196
|
-
result += ApiMap.get_keywords
|
|
228
|
+
result += ApiMap.get_keywords
|
|
197
229
|
while parts.length > 0
|
|
198
230
|
ns = parts.join('::')
|
|
199
231
|
result += @api_map.namespaces_in(ns)
|
|
@@ -208,7 +240,7 @@ module Solargraph
|
|
|
208
240
|
end
|
|
209
241
|
end
|
|
210
242
|
end
|
|
211
|
-
result = reduce_starting_with(result, word_at(index)) if filtered
|
|
243
|
+
#result = reduce_starting_with(result, word_at(index)) if filtered
|
|
212
244
|
result.uniq{|s| s.path}
|
|
213
245
|
end
|
|
214
246
|
|
|
@@ -335,7 +367,7 @@ module Solargraph
|
|
|
335
367
|
prefix = prefix[0..-2]
|
|
336
368
|
end
|
|
337
369
|
if matched
|
|
338
|
-
result.push Suggestion.new(detail['prefix'], kind: Suggestion::
|
|
370
|
+
result.push Suggestion.new(detail['prefix'], kind: Suggestion::SNIPPET, detail: name, insert: detail['body'].join("\r\n"))
|
|
339
371
|
end
|
|
340
372
|
}
|
|
341
373
|
result
|
|
@@ -413,5 +445,14 @@ module Solargraph
|
|
|
413
445
|
nil
|
|
414
446
|
end
|
|
415
447
|
|
|
448
|
+
def beginning_of_line_from str, i
|
|
449
|
+
while i > 0 and str[i] != "\n"
|
|
450
|
+
i -= 1
|
|
451
|
+
end
|
|
452
|
+
if i > 0 and str[i..-1].strip == ''
|
|
453
|
+
i = beginning_of_line_from str, i -1
|
|
454
|
+
end
|
|
455
|
+
i
|
|
456
|
+
end
|
|
416
457
|
end
|
|
417
458
|
end
|
|
@@ -68,8 +68,7 @@ module Solargraph
|
|
|
68
68
|
@yard_options = {
|
|
69
69
|
include: [],
|
|
70
70
|
exclude: [],
|
|
71
|
-
flags: []
|
|
72
|
-
all: []
|
|
71
|
+
flags: []
|
|
73
72
|
}
|
|
74
73
|
unless workspace.nil?
|
|
75
74
|
yardopts_file = File.join(workspace, '.yardopts')
|
|
@@ -77,7 +76,6 @@ module Solargraph
|
|
|
77
76
|
yardopts = File.read(yardopts_file)
|
|
78
77
|
yardopts.lines.each { |line|
|
|
79
78
|
arg = line.strip
|
|
80
|
-
@yard_options[:all].push arg
|
|
81
79
|
if arg.start_with?('-')
|
|
82
80
|
@yard_options[:flags].push arg
|
|
83
81
|
else
|
data/lib/solargraph/server.rb
CHANGED
|
@@ -24,7 +24,7 @@ module Solargraph
|
|
|
24
24
|
@@semaphore.synchronize {
|
|
25
25
|
code_map = CodeMap.new(code: params['text'], filename: params['filename'], api_map: @@api_hash[workspace])
|
|
26
26
|
offset = code_map.get_offset(params['line'].to_i, params['column'].to_i)
|
|
27
|
-
sugg = code_map.suggest_at(offset, with_snippets: true, filtered: true)
|
|
27
|
+
sugg = code_map.suggest_at(offset, with_snippets: params['with_snippets'] == '1' ? true : false, filtered: true)
|
|
28
28
|
}
|
|
29
29
|
{ "status" => "ok", "suggestions" => sugg }.to_json
|
|
30
30
|
rescue Exception => e
|
data/lib/solargraph/version.rb
CHANGED
data/lib/solargraph/yard_map.rb
CHANGED
|
@@ -21,7 +21,11 @@ module Solargraph
|
|
|
21
21
|
unless used.include?(g)
|
|
22
22
|
used.push g
|
|
23
23
|
gy = YARD::Registry.yardoc_file_for_gem(g)
|
|
24
|
-
|
|
24
|
+
if gy.nil?
|
|
25
|
+
STDERR.puts "Required path not found: #{r}"
|
|
26
|
+
else
|
|
27
|
+
yardocs.push gy
|
|
28
|
+
end
|
|
25
29
|
end
|
|
26
30
|
end
|
|
27
31
|
}
|
|
@@ -85,17 +89,6 @@ module Solargraph
|
|
|
85
89
|
yardocs.each { |y|
|
|
86
90
|
yard = load_yardoc(y)
|
|
87
91
|
unless yard.nil?
|
|
88
|
-
if namespace == '' and scope == ''
|
|
89
|
-
# Check for a bind tag in the yardoc root. If it exists, treat
|
|
90
|
-
# workspace code as a DSL that uses public instance methods in the
|
|
91
|
-
# specified namespaces.
|
|
92
|
-
b = yard.root.tag(:bind)
|
|
93
|
-
unless b.nil?
|
|
94
|
-
b.types.each { |t|
|
|
95
|
-
consts += get_instance_methods(t, '', visibility: :public)
|
|
96
|
-
}
|
|
97
|
-
end
|
|
98
|
-
end
|
|
99
92
|
ns = nil
|
|
100
93
|
if scope == ''
|
|
101
94
|
ns = yard.at(namespace)
|
|
@@ -148,11 +141,19 @@ module Solargraph
|
|
|
148
141
|
cached = cache.get_methods(namespace, scope, visibility)
|
|
149
142
|
return cached unless cached.nil?
|
|
150
143
|
meths = []
|
|
144
|
+
binds = []
|
|
151
145
|
yardocs.each { |y|
|
|
152
146
|
yard = load_yardoc(y)
|
|
153
147
|
unless yard.nil?
|
|
154
148
|
ns = nil
|
|
155
149
|
ns = find_first_resolved_namespace(yard, namespace, scope)
|
|
150
|
+
if namespace == '' and scope == ''
|
|
151
|
+
# Check for a bind tag in the yardoc root. If it exists, treat
|
|
152
|
+
# workspace code as a DSL that uses public instance methods in the
|
|
153
|
+
# specified namespaces.
|
|
154
|
+
b = yard.root.tag(:bind)
|
|
155
|
+
binds.concat b.types unless b.nil?
|
|
156
|
+
end
|
|
156
157
|
unless ns.nil?
|
|
157
158
|
ns.meths(scope: :class, visibility: visibility).each { |m|
|
|
158
159
|
n = m.to_s.split(/[\.#]/).last.gsub(/=/, ' = ')
|
|
@@ -171,6 +172,9 @@ module Solargraph
|
|
|
171
172
|
end
|
|
172
173
|
end
|
|
173
174
|
}
|
|
175
|
+
binds.each { |b|
|
|
176
|
+
meths += get_instance_methods(b, scope, visibility: [:public])
|
|
177
|
+
}
|
|
174
178
|
cache.set_methods(namespace, scope, visibility, meths)
|
|
175
179
|
meths
|
|
176
180
|
end
|
|
@@ -196,7 +200,9 @@ module Solargraph
|
|
|
196
200
|
end
|
|
197
201
|
}
|
|
198
202
|
if ns.kind_of?(YARD::CodeObjects::ClassObject) and namespace != 'Object'
|
|
199
|
-
|
|
203
|
+
if ns.superclass.kind_of?(YARD::CodeObjects::Proxy)
|
|
204
|
+
meths += get_instance_methods(ns.superclass.to_s)
|
|
205
|
+
end
|
|
200
206
|
end
|
|
201
207
|
end
|
|
202
208
|
end
|
|
@@ -252,8 +258,8 @@ module Solargraph
|
|
|
252
258
|
def cache_core
|
|
253
259
|
c = get_constants '', ''
|
|
254
260
|
c.each { |n|
|
|
255
|
-
get_methods
|
|
256
|
-
get_instance_methods
|
|
261
|
+
#get_methods n.label, visibility: :public
|
|
262
|
+
#get_instance_methods n.label, visibility: :public
|
|
257
263
|
}
|
|
258
264
|
end
|
|
259
265
|
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.7.
|
|
4
|
+
version: 0.7.5
|
|
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-05-
|
|
11
|
+
date: 2017-05-16 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: parser
|