solargraph 0.18.3 → 0.19.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.
Files changed (62) hide show
  1. checksums.yaml +4 -4
  2. data/lib/solargraph/api_map/probe.rb +222 -0
  3. data/lib/solargraph/api_map/source_to_yard.rb +3 -3
  4. data/lib/solargraph/api_map/store.rb +135 -0
  5. data/lib/solargraph/api_map.rb +169 -609
  6. data/lib/solargraph/diagnostics/rubocop.rb +4 -4
  7. data/lib/solargraph/language_server/host.rb +53 -19
  8. data/lib/solargraph/language_server/message/extended/document.rb +1 -1
  9. data/lib/solargraph/language_server/message/extended/search.rb +1 -1
  10. data/lib/solargraph/language_server/message/method_not_found.rb +1 -1
  11. data/lib/solargraph/language_server/message/text_document/definition.rb +2 -15
  12. data/lib/solargraph/language_server/message/text_document/document_symbol.rb +2 -15
  13. data/lib/solargraph/language_server/message/workspace/workspace_symbol.rb +3 -15
  14. data/lib/solargraph/language_server/message_types.rb +10 -0
  15. data/lib/solargraph/language_server.rb +1 -0
  16. data/lib/solargraph/library.rb +8 -0
  17. data/lib/solargraph/node_methods.rb +6 -1
  18. data/lib/solargraph/page.rb +2 -1
  19. data/lib/solargraph/pin/attribute.rb +8 -12
  20. data/lib/solargraph/pin/base.rb +20 -95
  21. data/lib/solargraph/pin/base_variable.rb +15 -74
  22. data/lib/solargraph/pin/block.rb +21 -0
  23. data/lib/solargraph/pin/block_parameter.rb +30 -44
  24. data/lib/solargraph/pin/class_variable.rb +3 -0
  25. data/lib/solargraph/pin/constant.rb +4 -8
  26. data/lib/solargraph/pin/conversions.rb +4 -3
  27. data/lib/solargraph/pin/documenting.rb +27 -0
  28. data/lib/solargraph/pin/global_variable.rb +3 -0
  29. data/lib/solargraph/pin/instance_variable.rb +5 -4
  30. data/lib/solargraph/pin/local_variable.rb +8 -15
  31. data/lib/solargraph/pin/localized.rb +12 -0
  32. data/lib/solargraph/pin/method.rb +6 -67
  33. data/lib/solargraph/pin/method_parameter.rb +24 -11
  34. data/lib/solargraph/pin/namespace.rb +26 -35
  35. data/lib/solargraph/pin/reference.rb +15 -8
  36. data/lib/solargraph/pin/symbol.rb +34 -3
  37. data/lib/solargraph/pin/yard_object.rb +11 -4
  38. data/lib/solargraph/pin.rb +16 -2
  39. data/lib/solargraph/server.rb +2 -2
  40. data/lib/solargraph/source/change.rb +10 -13
  41. data/lib/solargraph/source/fragment.rb +42 -94
  42. data/lib/solargraph/source/location.rb +13 -0
  43. data/lib/solargraph/source/mapper.rb +426 -0
  44. data/lib/solargraph/source/position.rb +1 -0
  45. data/lib/solargraph/source/range.rb +11 -3
  46. data/lib/solargraph/source.rb +93 -284
  47. data/lib/solargraph/version.rb +1 -1
  48. data/lib/solargraph/views/_method.erb +59 -60
  49. data/lib/solargraph/views/_name_type_tag.erb +10 -0
  50. data/lib/solargraph/views/_namespace.erb +26 -26
  51. data/lib/solargraph/views/document.erb +23 -16
  52. data/lib/solargraph/views/layout.erb +38 -10
  53. data/lib/solargraph/views/search.erb +12 -11
  54. data/lib/solargraph/workspace/config.rb +27 -6
  55. data/lib/solargraph/workspace.rb +10 -2
  56. data/lib/solargraph.rb +10 -2
  57. data/lib/yard-solargraph.rb +3 -0
  58. metadata +25 -20
  59. data/lib/solargraph/pin/directed/attribute.rb +0 -20
  60. data/lib/solargraph/pin/directed/method.rb +0 -22
  61. data/lib/solargraph/pin/directed.rb +0 -9
  62. data/lib/solargraph/pin/parameter.rb +0 -23
@@ -1,26 +1,26 @@
1
- <h2>
2
- Overview:
3
- </h2>
4
- <%= htmlify object.docstring %>
5
- <h2>
6
- Class Methods
7
- </h2>
8
- <ul class="doc-list">
9
- <% object.meths(scope: :class).sort{|a, b| a.name <=> b.name}.each do |meth| %>
10
- <li>
11
- <% esc = URI.escape("\"solargraph:/document?#{meth.path}\"").gsub('%23', URI.escape('%23')) %>
12
- <a href="command:solargraph._openDocument?<%= esc %>"><%= meth.name %></a>
13
- </li>
14
- <% end %>
15
- </ul>
16
- <h2>
17
- Instance Methods
18
- </h2>
19
- <ul class="doc-list">
20
- <% object.meths(scope: :instance).sort{|a, b| a.name <=> b.name}.each do |meth| %>
21
- <li>
22
- <% esc = URI.escape("\"solargraph:/document?#{meth.path}\"").gsub('%23', URI.escape('%23')) %>
23
- <a href="command:solargraph._openDocument?<%= esc %>"><%= meth.name %></a>
24
- </li>
25
- <% end %>
26
- </ul>
1
+ <h2>
2
+ Overview:
3
+ </h2>
4
+ <%= htmlify object.docstring %>
5
+ <h2>
6
+ Class Methods
7
+ </h2>
8
+ <ul class="doc-list">
9
+ <% object.meths(scope: :class).sort{|a, b| a.name <=> b.name}.each do |meth| %>
10
+ <li>
11
+ <% esc = URI.escape("\"solargraph:/document?query=#{meth.path}\"").gsub('%23', URI.escape('%23')) %>
12
+ <a href="command:solargraph._openDocument?<%= esc %>"><%= meth.name %></a>
13
+ </li>
14
+ <% end %>
15
+ </ul>
16
+ <h2>
17
+ Instance Methods
18
+ </h2>
19
+ <ul class="doc-list">
20
+ <% object.meths(scope: :instance).sort{|a, b| a.name <=> b.name}.each do |meth| %>
21
+ <li>
22
+ <% esc = URI.escape("\"solargraph:/document?query=#{meth.path}\"").gsub('%23', URI.escape('%23')) %>
23
+ <a href="command:solargraph._openDocument?<%= esc %>"><%= meth.name %></a>
24
+ </li>
25
+ <% end %>
26
+ </ul>
@@ -1,16 +1,23 @@
1
- <% @objects.reverse.each do |object| %>
2
- <h1>
3
- <%= object.name %>
4
- </h1>
5
- <h2>
6
- Defined in:
7
- </h2>
8
- <p>
9
- <%= object.files.join(', ') %>
10
- </p>
11
- <% if object.kind_of?(YARD::CodeObjects::NamespaceObject) %>
12
- <%= erb :_namespace, layout: false, locals: {object: object} %>
13
- <% elsif object.kind_of?(YARD::CodeObjects::MethodObject) %>
14
- <%= erb :_method, layout: false, locals: {object: object} %>
15
- <% end %>
16
- <% end %>
1
+ <% objects.reverse.each do |object| %>
2
+ <h1>
3
+ <%= object.name %>
4
+ <% if object.kind_of?(YARD::CodeObjects::MethodObject) and !object.parameters.empty? %>
5
+ <small>(<%= object.parameters.map {|p| "#{p[0]}#{p[1] and p[0].end_with?(':') ? ' ' : (p[1] ? ' = ' : '')}#{p[1]}"}.join(', ') %>)</small>
6
+ <% end %>
7
+ </h1>
8
+ <% unless object.files.empty? %>
9
+ <h2>
10
+ Defined in:
11
+ </h2>
12
+ <ul>
13
+ <% object.files.each do |f| %>
14
+ <li><%= f %></li>
15
+ <% end %>
16
+ </ul>
17
+ <% end %>
18
+ <% if object.kind_of?(YARD::CodeObjects::NamespaceObject) %>
19
+ <%= erb :_namespace, layout: false, locals: {object: object} %>
20
+ <% elsif object.kind_of?(YARD::CodeObjects::MethodObject) %>
21
+ <%= erb :_method, layout: false, locals: {object: object} %>
22
+ <% end %>
23
+ <% end %>
@@ -1,10 +1,38 @@
1
- <!DOCTYPE html>
2
- <html>
3
- <head>
4
- <title>Layout</title>
5
- </head>
6
- <body>
7
- <h1>Layout</h1>
8
- <%= yield %>
9
- </body>
10
- </html>
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>Solargraph</title>
5
+ <style>
6
+ a {
7
+ color: inherit;
8
+ text-decoration: underline;
9
+ }
10
+ h2 {
11
+ font-size: 110%;
12
+ margin: 1.5em 0 1em 0;
13
+ }
14
+ pre {
15
+ margin: 1em;
16
+ padding: 0.5em;
17
+ overflow: auto;
18
+ border: 1px solid gray;
19
+ }
20
+ ul.doc-list {
21
+ margin: 1em 0 1em 0.5em;
22
+ padding: 0;
23
+ }
24
+ ul.doc-list li {
25
+ list-style: none;
26
+ margin: 0.25em 0 0.25em 0;
27
+ padding: 0;
28
+ }
29
+ h1 small {
30
+ font-size: 75%;
31
+ font-weight: normal;
32
+ }
33
+ </style>
34
+ </head>
35
+ <body>
36
+ <%= yield %>
37
+ </body>
38
+ </html>
@@ -1,11 +1,12 @@
1
- <h1>Search Results for <kbd><%= params['query'] %></kbd></h1>
2
-
3
- <% unless @results.empty? %>
4
- <ul>
5
- <% @results.each do |result| %>
6
- <li>
7
- <a href="#"><%= result %></a>
8
- </li>
9
- <% end %>
10
- </ul>
11
- <% end %>
1
+ <h1>Search Results for <kbd><%= query %></kbd></h1>
2
+
3
+ <% unless results.empty? %>
4
+ <ul class="doc-list">
5
+ <% results.each do |result| %>
6
+ <li>
7
+ <%# esc = URI.escape("\"solargraph:/document?query=#{result}\"").gsub('%23', URI.escape('%23')) %>
8
+ <a href="solargraph:/document?query=<%= URI.escape(result) %>"><%= result %></a>
9
+ </li>
10
+ <% end %>
11
+ </ul>
12
+ <% end %>
@@ -9,6 +9,7 @@ module Solargraph
9
9
  # @return [Hash]
10
10
  attr_reader :raw_data
11
11
 
12
+ # @param workspace [String]
12
13
  def initialize workspace = nil
13
14
  @workspace = workspace
14
15
  include_globs = ['**/*.rb']
@@ -28,6 +29,8 @@ module Solargraph
28
29
  @raw_data['domains'] ||= []
29
30
  @raw_data['required'] ||= []
30
31
  @raw_data['plugins'] ||= []
32
+ included
33
+ excluded
31
34
  end
32
35
 
33
36
  # An array of files included in the workspace (before calculating excluded files).
@@ -35,8 +38,7 @@ module Solargraph
35
38
  # @return [Array<String>]
36
39
  def included
37
40
  return [] if workspace.nil?
38
- #@included ||= process_globs(@raw_data['include'])
39
- process_globs(@raw_data['include'])
41
+ @included ||= process_globs(@raw_data['include'])
40
42
  end
41
43
 
42
44
  # An array of files excluded from the workspace.
@@ -44,16 +46,14 @@ module Solargraph
44
46
  # @return [Array<String>]
45
47
  def excluded
46
48
  return [] if workspace.nil?
47
- #@excluded ||= process_globs(@raw_data['exclude'])
48
- process_globs(@raw_data['exclude'])
49
+ @excluded ||= process_exclusions(@raw_data['exclude'])
49
50
  end
50
51
 
51
52
  # The calculated array of (included - excluded) files in the workspace.
52
53
  #
53
54
  # @return [Array<String>]
54
55
  def calculated
55
- #@calculated ||= (included - excluded)
56
- included - excluded
56
+ @calculated ||= included - excluded
57
57
  end
58
58
 
59
59
  # @return [Array<String>]
@@ -80,6 +80,27 @@ module Solargraph
80
80
  end
81
81
  result
82
82
  end
83
+
84
+ def process_exclusions globs
85
+ remainder = globs.select do |glob|
86
+ if glob_is_directory?(glob)
87
+ exdir = File.realdirpath(File.join(workspace, glob_to_directory(glob)))
88
+ included.delete_if { |file| file.start_with?(exdir) }
89
+ false
90
+ else
91
+ true
92
+ end
93
+ end
94
+ process_globs remainder
95
+ end
96
+
97
+ def glob_is_directory? glob
98
+ File.directory?(glob) or File.directory?(glob_to_directory(glob))
99
+ end
100
+
101
+ def glob_to_directory glob
102
+ glob.gsub(/(\/\*|\/\*\*\/\*\*?)$/, '')
103
+ end
83
104
  end
84
105
  end
85
106
  end
@@ -9,8 +9,14 @@ module Solargraph
9
9
  # @return [String]
10
10
  attr_reader :directory
11
11
 
12
- def initialize directory
12
+ MAX_WORKSPACE_SIZE = 5000
13
+
14
+ # @param directory [String]
15
+ def initialize directory, config = nil
16
+ # @todo Convert to an absolute path?
13
17
  @directory = directory
18
+ @directory = nil if @directory == ''
19
+ @config = config
14
20
  load_sources
15
21
  end
16
22
 
@@ -94,7 +100,9 @@ module Solargraph
94
100
  def load_sources
95
101
  source_hash.clear
96
102
  unless directory.nil?
97
- config(true).calculated.each do |filename|
103
+ size = config.calculated.length
104
+ raise WorkspaceTooLargeError.new(size) if size > MAX_WORKSPACE_SIZE
105
+ config.calculated.each do |filename|
98
106
  src = Solargraph::Source.load(filename)
99
107
  source_hash[filename] = src
100
108
  end
data/lib/solargraph.rb CHANGED
@@ -5,9 +5,16 @@ require 'yard-solargraph'
5
5
  module Solargraph
6
6
  class InvalidOffsetError < RangeError; end
7
7
  class DiagnosticsError < RuntimeError; end
8
- class FileNotFoundError < Exception; end
8
+ class FileNotFoundError < RuntimeError; end
9
9
  class SourceNotAvailableError < StandardError; end
10
- '—'
10
+
11
+ class WorkspaceTooLargeError < RuntimeError
12
+ attr_reader :size
13
+ def initialize size
14
+ @size = size
15
+ end
16
+ end
17
+
11
18
  autoload :Shell, 'solargraph/shell'
12
19
  autoload :Source, 'solargraph/source'
13
20
  autoload :ApiMap, 'solargraph/api_map'
@@ -28,6 +35,7 @@ module Solargraph
28
35
 
29
36
  YARDOC_PATH = File.join(File.realpath(File.dirname(__FILE__)), '..', 'yardoc')
30
37
  YARD_EXTENSION_FILE = File.join(File.realpath(File.dirname(__FILE__)), 'yard-solargraph.rb')
38
+ VIEWS_PATH = File.join(File.realpath(File.dirname(__FILE__)), 'solargraph', 'views')
31
39
  end
32
40
 
33
41
  Solargraph::YardMap::CoreDocs.require_minimum
@@ -1,6 +1,9 @@
1
1
  require 'yard'
2
+ require 'yard/templates/helpers/markup_helper'
3
+ require 'yard/templates/helpers/html_helper'
2
4
 
3
5
  # Define a @type tag for documenting variables
4
6
  YARD::Tags::Library.define_tag("Type", :type, :with_types_and_name)
5
7
  # Define a @yieldself tag for documenting block contexts
6
8
  YARD::Tags::Library.define_tag("Yieldself", :yieldself, :with_types)
9
+ Solargraph
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.18.3
4
+ version: 0.19.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: 2018-04-11 00:00:00.000000000 Z
11
+ date: 2018-04-16 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: rubocop
91
- requirement: !ruby/object:Gem::Requirement
92
- requirements:
93
- - - "~>"
94
- - !ruby/object:Gem::Version
95
- version: '0.52'
96
- type: :runtime
97
- prerelease: false
98
- version_requirements: !ruby/object:Gem::Requirement
99
- requirements:
100
- - - "~>"
101
- - !ruby/object:Gem::Version
102
- version: '0.52'
103
89
  - !ruby/object:Gem::Dependency
104
90
  name: eventmachine
105
91
  requirement: !ruby/object:Gem::Requirement
@@ -194,6 +180,20 @@ dependencies:
194
180
  - - "~>"
195
181
  - !ruby/object:Gem::Version
196
182
  version: '1.1'
183
+ - !ruby/object:Gem::Dependency
184
+ name: rubocop
185
+ requirement: !ruby/object:Gem::Requirement
186
+ requirements:
187
+ - - "~>"
188
+ - !ruby/object:Gem::Version
189
+ version: '0.52'
190
+ type: :runtime
191
+ prerelease: false
192
+ version_requirements: !ruby/object:Gem::Requirement
193
+ requirements:
194
+ - - "~>"
195
+ - !ruby/object:Gem::Version
196
+ version: '0.52'
197
197
  - !ruby/object:Gem::Dependency
198
198
  name: rspec
199
199
  requirement: !ruby/object:Gem::Requirement
@@ -285,7 +285,9 @@ files:
285
285
  - lib/solargraph/api_map.rb
286
286
  - lib/solargraph/api_map/cache.rb
287
287
  - lib/solargraph/api_map/completion.rb
288
+ - lib/solargraph/api_map/probe.rb
288
289
  - lib/solargraph/api_map/source_to_yard.rb
290
+ - lib/solargraph/api_map/store.rb
289
291
  - lib/solargraph/core_fills.rb
290
292
  - lib/solargraph/diagnostics.rb
291
293
  - lib/solargraph/diagnostics/rubocop.rb
@@ -326,6 +328,7 @@ files:
326
328
  - lib/solargraph/language_server/message/workspace/did_change_configuration.rb
327
329
  - lib/solargraph/language_server/message/workspace/did_change_watched_files.rb
328
330
  - lib/solargraph/language_server/message/workspace/workspace_symbol.rb
331
+ - lib/solargraph/language_server/message_types.rb
329
332
  - lib/solargraph/language_server/symbol_kinds.rb
330
333
  - lib/solargraph/language_server/transport.rb
331
334
  - lib/solargraph/language_server/transport/socket.rb
@@ -339,22 +342,21 @@ files:
339
342
  - lib/solargraph/pin/attribute.rb
340
343
  - lib/solargraph/pin/base.rb
341
344
  - lib/solargraph/pin/base_variable.rb
345
+ - lib/solargraph/pin/block.rb
342
346
  - lib/solargraph/pin/block_parameter.rb
343
347
  - lib/solargraph/pin/class_variable.rb
344
348
  - lib/solargraph/pin/constant.rb
345
349
  - lib/solargraph/pin/conversions.rb
346
- - lib/solargraph/pin/directed.rb
347
- - lib/solargraph/pin/directed/attribute.rb
348
- - lib/solargraph/pin/directed/method.rb
350
+ - lib/solargraph/pin/documenting.rb
349
351
  - lib/solargraph/pin/global_variable.rb
350
352
  - lib/solargraph/pin/helper.rb
351
353
  - lib/solargraph/pin/instance_variable.rb
352
354
  - lib/solargraph/pin/keyword.rb
353
355
  - lib/solargraph/pin/local_variable.rb
356
+ - lib/solargraph/pin/localized.rb
354
357
  - lib/solargraph/pin/method.rb
355
358
  - lib/solargraph/pin/method_parameter.rb
356
359
  - lib/solargraph/pin/namespace.rb
357
- - lib/solargraph/pin/parameter.rb
358
360
  - lib/solargraph/pin/plugin/method.rb
359
361
  - lib/solargraph/pin/reference.rb
360
362
  - lib/solargraph/pin/symbol.rb
@@ -371,12 +373,15 @@ files:
371
373
  - lib/solargraph/source/change.rb
372
374
  - lib/solargraph/source/flawed_builder.rb
373
375
  - lib/solargraph/source/fragment.rb
376
+ - lib/solargraph/source/location.rb
377
+ - lib/solargraph/source/mapper.rb
374
378
  - lib/solargraph/source/position.rb
375
379
  - lib/solargraph/source/range.rb
376
380
  - lib/solargraph/source/updater.rb
377
381
  - lib/solargraph/suggestion.rb
378
382
  - lib/solargraph/version.rb
379
383
  - lib/solargraph/views/_method.erb
384
+ - lib/solargraph/views/_name_type_tag.erb
380
385
  - lib/solargraph/views/_namespace.erb
381
386
  - lib/solargraph/views/document.erb
382
387
  - lib/solargraph/views/layout.erb
@@ -1,20 +0,0 @@
1
- module Solargraph
2
- module Pin
3
- module Directed
4
- class Attribute < Solargraph::Pin::Attribute
5
- def initialize source, node, namespace, access, docstring, name
6
- super(source, node, namespace, access, docstring)
7
- @name = name
8
- end
9
-
10
- def name
11
- @name
12
- end
13
-
14
- def completion_item_kind
15
- Solargraph::LanguageServer::CompletionItemKinds::METHOD
16
- end
17
- end
18
- end
19
- end
20
- end
@@ -1,22 +0,0 @@
1
- module Solargraph
2
- module Pin
3
- module Directed
4
- class Method < Solargraph::Pin::Method
5
- def initialize source, node, namespace, scope, visibility, docstring, name, return_type = nil
6
- super(source, node, namespace, scope, visibility)
7
- @docstring = docstring
8
- @name = name
9
- @return_type = return_type
10
- end
11
-
12
- def name
13
- @name
14
- end
15
-
16
- def completion_item_kind
17
- Solargraph::LanguageServer::CompletionItemKinds::METHOD
18
- end
19
- end
20
- end
21
- end
22
- end
@@ -1,9 +0,0 @@
1
- module Solargraph
2
- module Pin
3
- # Directed pins are defined by YARD directives instead of code.
4
- module Directed
5
- autoload :Attribute, 'solargraph/pin/directed/attribute'
6
- autoload :Method, 'solargraph/pin/directed/method'
7
- end
8
- end
9
- end
@@ -1,23 +0,0 @@
1
- module Solargraph
2
- module Pin
3
- class Parameter < Base
4
- def initialize source, node, namespace, name, return_type
5
- super(source, node, namespace)
6
- @name = name
7
- @return_type = return_type
8
- end
9
-
10
- def name
11
- @name
12
- end
13
-
14
- def return_type
15
- @return_type
16
- end
17
-
18
- def completion_item_kind
19
- Solargraph::LanguageServer::CompletionItemKinds::PROPERTY
20
- end
21
- end
22
- end
23
- end