solargraph 0.2.2 → 0.3.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: fb228dbd2c050d2937573b2e4a4249fb951da217
4
- data.tar.gz: 1af21e85d38cc159b53fc69ba05aeb4011d41a4a
3
+ metadata.gz: a4d07f475a599b0f7f65563328f9154bbc4aad57
4
+ data.tar.gz: 2f5eeb896120355cd001ec31581f0cef5680fea1
5
5
  SHA512:
6
- metadata.gz: 8804b2ea16a1e6b5e1568a683af153a89da87f219ba00cd6b4338d4044c97f92486cfdc7c3f13009c6547b1750d98f1e5574a40f6f97c73435ab314368f6e48b
7
- data.tar.gz: 45928e94fefe7fc5a78609b808666e6805e6a654dabe9b91a964b0c57155641544671848922e1c73434e63fac1e67418beefffebea1da59ec8f58c72efb80b6c
6
+ metadata.gz: 2448dfeac5a8f5db6b65ad949d762edcfe02c6c5e7184447ebfbc4352d1fd681636dd57cbaec4ea43b2819cdb1bf10cbae17737a76797ee559d180da30374294
7
+ data.tar.gz: 062f9ba1b5efbd026c1019cfda465e19b9d60e5cb6adf689dc876888e1a03522ab8ad4818f4a455b573c9636d9a31212c454bc3d50c7c513bd23ab60e04b8284
@@ -26,7 +26,7 @@ module Solargraph
26
26
  unless @workspace.nil?
27
27
  files = Dir[File.join @workspace, 'lib', '**', '*.rb'] + Dir[File.join @workspace, 'app', '**', '*.rb']
28
28
  files.each { |f|
29
- append_file f
29
+ append_file f unless yardoc_has_file?(f)
30
30
  }
31
31
  end
32
32
  end
@@ -47,7 +47,7 @@ module Solargraph
47
47
  def yardoc_has_file?(filename)
48
48
  return false unless has_yardoc?
49
49
  return false if filename.nil?
50
- if filename.start_with?(File.join(workspace, 'lib'), File.join(workspace, 'app'))
50
+ if filename.start_with?(File.join(workspace, 'lib/'), File.join(workspace, 'app/'))
51
51
  return true
52
52
  end
53
53
  false
@@ -7,7 +7,7 @@ module Solargraph
7
7
 
8
8
  include NodeMethods
9
9
 
10
- def initialize code: '', filename: nil, workspace: nil
10
+ def initialize code: '', filename: nil, workspace: nil, api_map: nil
11
11
  unless workspace.nil?
12
12
  workspace = workspace.gsub(File::ALT_SEPARATOR, File::SEPARATOR) unless File::ALT_SEPARATOR.nil?
13
13
  end
@@ -15,16 +15,10 @@ module Solargraph
15
15
  filename = filename.gsub(File::ALT_SEPARATOR, File::SEPARATOR) unless File::ALT_SEPARATOR.nil?
16
16
  workspace = CodeMap.find_workspace(filename)
17
17
  end
18
- if workspace.nil?
19
- @api_map = ApiMap.new(workspace)
20
- else
21
- ser_file = File.join(workspace, '.solargraph.ser')
22
- if File.exist?(ser_file)
23
- begin
24
- @api_map = Marshal.load(File.read(ser_file))
25
- rescue Exception => e
26
- @api_map = ApiMap.new(workspace)
27
- end
18
+ @api_map = api_map
19
+ if @api_map.nil?
20
+ if workspace.nil?
21
+ @api_map = ApiMap.new(workspace)
28
22
  else
29
23
  @api_map = ApiMap.new(workspace)
30
24
  end
@@ -228,14 +222,15 @@ module Solargraph
228
222
  else
229
223
  obj = infer(var.children[1])
230
224
  while parts.length > 0
231
- obj = get_instance_method_return_value obj, ns_here, parts.shift
225
+ meth = parts.shift
226
+ obj = get_instance_method_return_value obj, ns_here, meth
232
227
  end
233
228
  return @api_map.get_instance_methods(obj) unless obj.nil?
234
229
  end
235
230
  end
236
231
 
237
232
  def get_method_return_value namespace, root, method
238
- meths = @api_map.get_methods(namespace, root).delete_if{ |m| m.label != method }
233
+ meths = @api_map.get_methods(namespace, root).delete_if{ |m| m.insert != method }
239
234
  meths.each { |m|
240
235
  unless m.documentation.nil?
241
236
  match = m.documentation.all.match(/@return \[([a-z0-9:_]*)/i)
@@ -247,7 +242,7 @@ module Solargraph
247
242
  end
248
243
 
249
244
  def get_instance_method_return_value namespace, root, method
250
- meths = @api_map.get_instance_methods(namespace, root).delete_if{ |m| m.label != method }
245
+ meths = @api_map.get_instance_methods(namespace, root).delete_if{ |m| m.insert != method }
251
246
  meths.each { |m|
252
247
  unless m.documentation.nil?
253
248
  match = m.documentation.all.match(/@return \[([a-z0-9:_]*)/i)
@@ -1,15 +1,28 @@
1
1
  require 'sinatra/base'
2
+ require 'thread'
2
3
 
3
4
  module Solargraph
4
5
  class Server < Sinatra::Base
5
- set :port, 0
6
+ set :port, 7657
7
+
8
+ @@api_hash = {}
9
+ @@semaphore = Mutex.new
10
+
11
+ post '/prepare' do
12
+ prepare_workspace params['directory']
13
+ end
6
14
 
7
15
  post '/suggest' do
8
16
  content_type :json
9
17
  begin
10
- code_map = CodeMap.new(code: params['text'], filename: params['filename'])
11
- offset = code_map.get_offset(params['line'].to_i, params['col'].to_i)
12
- sugg = code_map.suggest_at(offset, with_snippets: true, filtered: true)
18
+ sugg = []
19
+ workspace = params['workspace'] || CodeMap.find_workspace(params['filename'])
20
+ Server.prepare_workspace workspace unless @@api_hash.has_key?(workspace)
21
+ @@semaphore.synchronize {
22
+ code_map = CodeMap.new(code: params['text'], filename: params['filename'], api_map: @@api_hash[workspace])
23
+ offset = code_map.get_offset(params['line'].to_i, params['column'].to_i)
24
+ sugg = code_map.suggest_at(offset, with_snippets: true, filtered: true)
25
+ }
13
26
  { "status" => "ok", "suggestions" => sugg }.to_json
14
27
  rescue Exception => e
15
28
  STDERR.puts e
@@ -17,5 +30,33 @@ module Solargraph
17
30
  { "status" => "err", "message" => e.message + "\n" + e.backtrace.join("\n") }.to_json
18
31
  end
19
32
  end
33
+
34
+ class << self
35
+ def run!
36
+ constant_updates
37
+ super
38
+ end
39
+
40
+ def prepare_workspace directory
41
+ api_map = Solargraph::ApiMap.new(directory)
42
+ @@semaphore.synchronize {
43
+ @@api_hash[directory] = api_map
44
+ }
45
+ end
46
+
47
+ def constant_updates
48
+ Thread.new {
49
+ loop do
50
+ @@api_hash.keys.each { |k|
51
+ update = Solargraph::ApiMap.new(k)
52
+ @@semaphore.synchronize {
53
+ @@api_hash[k] = update
54
+ }
55
+ }
56
+ sleep 2
57
+ end
58
+ }
59
+ end
60
+ end
20
61
  end
21
62
  end
@@ -42,30 +42,13 @@ module Solargraph
42
42
  end
43
43
  end
44
44
 
45
- desc 'bundled', 'Get a list of bundled gems'
46
- def bundled
47
- Bundler.load.specs.each { |s|
48
- puts s.name
49
- }
50
- end
51
-
52
45
  desc 'server', 'Start a Solargraph server'
46
+ option :port, type: :numeric, aliases: :p, desc: 'The server port', default: 7657
53
47
  def server
48
+ Solargraph::Server.set :port, options[:port]
54
49
  Solargraph::Server.run!
55
50
  end
56
51
 
57
- desc 'serialize DIRECTORY', 'Cache an API map of DIRECTORY'
58
- def serialize directory
59
- api_map = ApiMap.new directory
60
- files = Dir[File.join directory, 'lib', '**', '*.rb'] + Dir[File.join directory, 'app', '**', '*.rb']
61
- files.each { |f|
62
- api_map.append_file f
63
- }
64
- File.open(File.join(directory, '.solargraph.ser'), 'wb') { |file|
65
- file << Marshal.dump(api_map)
66
- }
67
- end
68
-
69
52
  desc 'suggest', 'Get code suggestions for the provided input'
70
53
  long_desc <<-LONGDESC
71
54
  Analyze a Ruby file and output a list of code suggestions in JSON format.
@@ -1,3 +1,3 @@
1
1
  module Solargraph
2
- VERSION = '0.2.2'
2
+ VERSION = '0.3.0'
3
3
  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.2.2
4
+ version: 0.3.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-03-20 00:00:00.000000000 Z
11
+ date: 2017-03-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: parser