solargraph 0.8.6 → 0.9.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: 02c54193138513541a17e784338430260259b223
4
- data.tar.gz: f464a3a964e88b6f82d250e065d92e0062c3a135
3
+ metadata.gz: de6f8c27644254cbf44fabf999b5e7d9c54361d5
4
+ data.tar.gz: e823050e40e151659b89be427a8039165c5a315c
5
5
  SHA512:
6
- metadata.gz: b548477ca4dc01db1785654d68d779a1ae3e29fb29c7702efc006ce2abfd8101df8735395328bb11db9a19abfc568d93896fadc392c8eb9af4126450fb7df162
7
- data.tar.gz: dd27df9547f7dddfff89b98af23cf61d9dfaeb5937f790885c30607b7ccc7f3d5151132fb1affa8183b4f766d257731129b504a1dbcc43c1791deec07f719a7c
6
+ metadata.gz: 1312f30cabb2d18635ea4e48900226318476ac7d53022b46b72afcc2696451154e9fc9718b1f74026ceb2cae6c4afc04b2904f28d3b9c02d555ef410904c53d2
7
+ data.tar.gz: 2c05df4a956bdb87868e6d624c72fc232a35599d0abd8763286b0db389f559e4b160747f6c6a3c43b1a2c2d7d8659b840ddd00465a69e57f327e2b0858dd4663
@@ -5,6 +5,8 @@ require 'yaml'
5
5
 
6
6
  module Solargraph
7
7
  class ApiMap
8
+ autoload :Config, 'solargraph/api_map/config'
9
+
8
10
  KEYWORDS = [
9
11
  '__ENCODING__', '__LINE__', '__FILE__', 'BEGIN', 'END', 'alias', 'and',
10
12
  'begin', 'break', 'case', 'class', 'def', 'defined?', 'do', 'else',
@@ -26,20 +28,11 @@ module Solargraph
26
28
  @workspace = workspace.gsub(/\\/, '/') unless workspace.nil?
27
29
  clear
28
30
  unless @workspace.nil?
29
- extra = File.join(@workspace, '.solargraph')
30
- if File.exist?(extra)
31
- append_file(extra)
32
- end
33
- files = []
34
- opts = yard_options
35
- (opts[:include] - opts[:exclude]).each { |glob|
36
- files += Dir[File.join @workspace, glob]
37
- }
38
- opts[:exclude].each { |glob|
39
- files -= Dir[File.join @workspace, glob]
40
- }
41
- files.uniq.each { |f|
42
- append_file f if File.file?(f)
31
+ config = ApiMap::Config.new(@workspace)
32
+ config.included.each { |f|
33
+ unless config.excluded.include?(f)
34
+ append_file f
35
+ end
43
36
  }
44
37
  end
45
38
  end
@@ -62,8 +55,13 @@ module Solargraph
62
55
  end
63
56
 
64
57
  def append_source text, filename = nil
65
- node, comments = Parser::CurrentRuby.parse_with_comments(text)
66
- append_node(node, comments, filename)
58
+ begin
59
+ node, comments = Parser::CurrentRuby.parse_with_comments(text)
60
+ append_node(node, comments, filename)
61
+ rescue Parser::SyntaxError => e
62
+ STDERR.puts "Error parsing '#{filename}': #{e.message}"
63
+ nil
64
+ end
67
65
  end
68
66
 
69
67
  def append_node node, comments, filename = nil
@@ -82,11 +80,23 @@ module Solargraph
82
80
  yard_hash = {}
83
81
  comment_hash.each_pair { |k, v|
84
82
  ctxt = ''
83
+ num = nil
84
+ started = false
85
85
  v.each { |l|
86
- ctxt += l.text.gsub(/^# /, '') + "\n"
86
+ # Trim the comment and minimum leading whitespace
87
+ p = l.text.gsub(/^#/, '')
88
+ if num.nil? and !p.strip.empty?
89
+ num = p.index(/[^ ]/)
90
+ started = true
91
+ elsif started and !p.strip.empty?
92
+ cur = p.index(/[^ ]/)
93
+ num = cur if cur < num
94
+ end
95
+ if started
96
+ ctxt += "#{p[num..-1]}\n"
97
+ end
87
98
  }
88
- parser = YARD::DocstringParser.new
89
- yard_hash[k] = parser.parse(ctxt).to_docstring
99
+ yard_hash[k] = YARD::Docstring.parser.parse(ctxt).to_docstring
90
100
  }
91
101
  yard_hash
92
102
  end
@@ -405,7 +415,6 @@ module Solargraph
405
415
  }
406
416
  return args if list.nil?
407
417
  list.children.each { |c|
408
- STDERR.puts "Args child is #{c.type}"
409
418
  if c.type == :arg
410
419
  args.push c.children[0]
411
420
  elsif c.type == :optarg
@@ -480,7 +489,7 @@ module Solargraph
480
489
  if workspace.nil?
481
490
  STDERR.puts "No workspace specified for yardoc update."
482
491
  else
483
- Thread.new {
492
+ Thread.new do
484
493
  Dir.chdir(workspace) do
485
494
  STDERR.puts "Updating the yardoc for #{workspace}..."
486
495
  cmd = "yardoc -e #{Solargraph::YARD_EXTENSION_FILE}"
@@ -490,7 +499,7 @@ module Solargraph
490
499
  STDERR.puts "There was an error processing the workspace yardoc."
491
500
  end
492
501
  end
493
- }
502
+ end
494
503
  end
495
504
  end
496
505
 
@@ -563,6 +572,9 @@ module Solargraph
563
572
  # TODO: Determine the current scope so we can decide whether to
564
573
  # exclude protected or private methods. Right now we're just
565
574
  # assuming public only
575
+ elsif c.kind_of?(AST::Node) and c.type == :send and c.children[1] == :include
576
+ fqmod = find_fully_qualified_namespace(const_from(c.children[2]), root)
577
+ meths += get_instance_methods(fqmod) unless fqmod.nil? or skip.include?(fqmod)
566
578
  elsif current_scope == :public
567
579
  if c.kind_of?(AST::Node) and c.type == :def
568
580
  cmnt = get_comment_for(c)
@@ -0,0 +1,37 @@
1
+ module Solargraph
2
+ class ApiMap
3
+ class Config
4
+ attr_reader :workspace
5
+ attr_reader :included
6
+ attr_reader :excluded
7
+
8
+ def initialize workspace = nil
9
+ @workspace = workspace
10
+ @included = []
11
+ @excluded = []
12
+ include_globs = ['**/*.rb']
13
+ exclude_globs = ['spec/**/*']
14
+ unless @workspace.nil?
15
+ sfile = File.join(@workspace, '.solargraph.yml')
16
+ if File.file?(sfile)
17
+ conf = YAML.load(File.read(sfile))
18
+ include_globs = conf['include'] || include_globs
19
+ exclude_globs = conf['exclude'] || []
20
+ end
21
+ end
22
+ include_globs.each { |g| @included.concat process_glob(g) }
23
+ exclude_globs.each { |g| @excluded.concat process_glob(g) }
24
+ end
25
+
26
+ private
27
+
28
+ def process_glob glob
29
+ result = []
30
+ Dir[glob].each do |f|
31
+ result.push File.realdirpath(f)
32
+ end
33
+ result
34
+ end
35
+ end
36
+ end
37
+ end
@@ -11,6 +11,10 @@ module Solargraph
11
11
  @@api_hash = {}
12
12
  @@semaphore = Mutex.new
13
13
 
14
+ after do
15
+ GC.start
16
+ end
17
+
14
18
  post '/prepare' do
15
19
  STDERR.puts "Preparing #{params['workspace']}"
16
20
  Server.prepare_workspace params['workspace']
@@ -79,5 +79,16 @@ module Solargraph
79
79
  STDOUT.puts result
80
80
  end
81
81
  end
82
+
83
+ desc 'config [DIRECTORY]', 'Create or overwrite a default configuration file'
84
+ def config(directory = '.')
85
+ File.open(File.join(directory, '.solargraph'), 'w') do |file|
86
+ file.puts "include:",
87
+ " - ./**/*.rb",
88
+ "exclude:",
89
+ " - spec/**/*"
90
+ end
91
+ STDOUT.puts "Configuration file initialized."
92
+ end
82
93
  end
83
94
  end
@@ -1,3 +1,3 @@
1
1
  module Solargraph
2
- VERSION = '0.8.6'
2
+ VERSION = '0.9.0'
3
3
  end
@@ -37,10 +37,16 @@ module Solargraph
37
37
  end
38
38
 
39
39
  def load_yardoc y
40
- if y.kind_of?(Array)
41
- YARD::Registry.load y, true
42
- else
43
- YARD::Registry.load! y
40
+ begin
41
+ if y.kind_of?(Array)
42
+ YARD::Registry.load y, true
43
+ else
44
+ YARD::Registry.load! y
45
+ end
46
+ rescue Exception => e
47
+ STDERR.puts "Error loading yardoc '#{y}' #{e.class} #{e.message}"
48
+ yardocs.delete y
49
+ nil
44
50
  end
45
51
  end
46
52
 
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.8.6
4
+ version: 0.9.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-06-14 00:00:00.000000000 Z
11
+ date: 2017-07-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: parser
@@ -136,6 +136,7 @@ files:
136
136
  - bin/solargraph
137
137
  - lib/solargraph.rb
138
138
  - lib/solargraph/api_map.rb
139
+ - lib/solargraph/api_map/config.rb
139
140
  - lib/solargraph/code_map.rb
140
141
  - lib/solargraph/mapper.rb
141
142
  - lib/solargraph/node_methods.rb