solargraph 0.30.0 → 0.30.1

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
  SHA256:
3
- metadata.gz: 82f40642bcf02b95ca838da6a0ed6ff66ac9d0e8ef42ee8bf8643866342ffb39
4
- data.tar.gz: e1e30bd1a35dfdfd1b17d74d70ab8afef82c701fdbffb4d4f08455511df95673
3
+ metadata.gz: f109fbce413be0100575d4375ff3bd0592626852334dfcb41161f7d7bbe6e67f
4
+ data.tar.gz: 5fa2251f2b60f03c627add65eef3e42adf16e75cc579c36e581dc7972312b750
5
5
  SHA512:
6
- metadata.gz: 67ace010ea2017c9d35c2d8aa8229187ff39c27f926c388eba9105e067088c31ed46a7dadaef787c5845eb838b9c347744cfc48e47dea480558a8d5f05c15ee7
7
- data.tar.gz: eef1f9e7c56e8623fe44227fedd16b89a0d277ac29ac3005ade6b98387596daff15c0743deb8de8b99ff4950c72b504c4f31e0e44faf075de14fc662efa14449
6
+ metadata.gz: 2017a0eaea2090e26a3f99f0e8d9734e40b6f9692dfcdef8bcb2c424ba3180604807c3cceb49f029fc87fa25e17e6212a79e97e62f6fd570fc2a8f6a8a75652b
7
+ data.tar.gz: e386dcd357c431214a64e1774097a61827c9d54f70b290313868250a392095a520d87788c0741bc660ceb1ceb114f16c71a54923fbfe3755dd84776c9c64e6a0
@@ -176,6 +176,8 @@ module Solargraph
176
176
  library = library_for(params['textDocument']['uri'])
177
177
  updater = generate_updater(params)
178
178
  library.update updater
179
+ # @todo Since Library#checkout already catalogs, this cataloging
180
+ # might not be necessary.
179
181
  cataloger.ping(library) unless library.synchronized?
180
182
  diagnoser.schedule params['textDocument']['uri']
181
183
  end
@@ -342,6 +344,8 @@ module Solargraph
342
344
  end
343
345
  end
344
346
 
347
+ # True if the specified LSP method can be dynamically registered.
348
+ #
345
349
  # @param method [String]
346
350
  # @return [Boolean]
347
351
  def can_register? method
@@ -370,26 +374,42 @@ module Solargraph
370
374
  @stopped
371
375
  end
372
376
 
377
+ # Locate a pin based on the location of a completion item, or nil if the
378
+ # library does not have a source at that location.
379
+ #
380
+ # @param params [Hash] A hash representation of a completion item
381
+ # @return [Pin::Base, nil]
373
382
  def locate_pin params
374
- pin = nil
375
- unless params['data']['location'].nil?
376
- library = library_for(file_to_uri(params['data']['location']['filename']))
377
- location = Location.new(
378
- params['data']['location']['filename'],
379
- Range.from_to(
380
- params['data']['location']['range']['start']['line'],
381
- params['data']['location']['range']['start']['character'],
382
- params['data']['location']['range']['end']['line'],
383
- params['data']['location']['range']['end']['character']
384
- )
383
+ return nil unless params['data'] && params['data']['uri'] && params['data']['location']
384
+ library = library_for(params['data']['uri'])
385
+ location = Location.new(
386
+ params['data']['location']['filename'],
387
+ Range.from_to(
388
+ params['data']['location']['range']['start']['line'],
389
+ params['data']['location']['range']['start']['character'],
390
+ params['data']['location']['range']['end']['line'],
391
+ params['data']['location']['range']['end']['character']
385
392
  )
386
- pin = library.locate_pin(location)
393
+ )
394
+ library.locate_pin(location)
395
+ end
396
+
397
+ # Locate multiple pins that match a completion item. The first match is
398
+ # based on the corresponding location in a library source if available
399
+ # (see #locate_pin). Subsequent matches are based on path.
400
+ #
401
+ # @param params [Hash] A hash representation of a completion item
402
+ # @return [Array<Pin::Base>]
403
+ def locate_pins params
404
+ return [] unless params['data'] && params['data']['uri']
405
+ exact = locate_pin(params)
406
+ library = library_for(params['data']['uri'])
407
+ result = []
408
+ unless params['data']['path'].nil?
409
+ result.concat library.path_pins(params['data']['path']).reject{|pin| pin == exact}
387
410
  end
388
- # @todo Improve pin location
389
- # if pin.nil? or pin.path != params['data']['path']
390
- # pin = library.path_pins(params['data']['path']).first
391
- # end
392
- pin
411
+ result.unshift exact unless exact.nil?
412
+ result
393
413
  end
394
414
 
395
415
  # @param uri [String]
@@ -6,14 +6,22 @@ module Solargraph
6
6
  #
7
7
  class Resolve < Base
8
8
  def process
9
- pin = host.locate_pin params
10
- if pin.nil?
11
- set_result params
12
- else
13
- set_result(
14
- params.merge(pin.resolve_completion_item)
15
- )
16
- end
9
+ pins = host.locate_pins(params)
10
+ set_result merge(pins)
11
+ end
12
+
13
+ private
14
+
15
+ # @param pins [Array<Pin::Base>]
16
+ # @return [Hash]
17
+ def merge pins
18
+ return params if pins.empty?
19
+ docs = pins
20
+ .reject { |pin| pin.documentation.empty? }
21
+ .map { |pin| pin.resolve_completion_item[:documentation] }
22
+ params
23
+ .merge(pins.first.resolve_completion_item)
24
+ .merge(documentation: docs.join("\n\n"))
17
25
  end
18
26
  end
19
27
  end
@@ -1,5 +1,3 @@
1
- require 'time'
2
-
3
1
  module Solargraph
4
2
  module LanguageServer
5
3
  module Message
@@ -33,6 +31,7 @@ module Solargraph
33
31
  },
34
32
  sortText: "#{idx.to_s.rjust(4, '0')}#{pin.name}"
35
33
  })
34
+ items.last[:data][:uri] = params['textDocument']['uri']
36
35
  last_context = pin.context
37
36
  end
38
37
  set_result(
@@ -16,6 +16,7 @@ module Solargraph
16
16
  @name = name
17
17
  api_map.catalog bundle
18
18
  @synchronized = true
19
+ @catalog_mutex = Mutex.new
19
20
  end
20
21
 
21
22
  # True if the ApiMap is up to date with the library's workspace and open
@@ -35,21 +36,21 @@ module Solargraph
35
36
  # @return [void]
36
37
  def open filename, text, version
37
38
  mutex.synchronize do
39
+ @synchronized = false
38
40
  source = Solargraph::Source.load_string(text, filename, version)
39
41
  workspace.merge source
40
42
  open_file_hash[filename] = source
41
43
  checkout filename
42
- catalog
43
44
  end
44
45
  end
45
46
 
46
47
  def open_from_disk filename
47
48
  mutex.synchronize do
49
+ @synchronized = false
48
50
  source = Solargraph::Source.load(filename)
49
51
  workspace.merge source
50
52
  open_file_hash[filename] = source
51
53
  checkout filename
52
- catalog
53
54
  end
54
55
  end
55
56
 
@@ -80,6 +81,7 @@ module Solargraph
80
81
  result = false
81
82
  mutex.synchronize do
82
83
  next unless contain?(filename) || open?(filename) || workspace.would_merge?(filename)
84
+ @synchronized = false
83
85
  source = Solargraph::Source.load_string(text, filename)
84
86
  workspace.merge(source)
85
87
  catalog
@@ -98,6 +100,7 @@ module Solargraph
98
100
  mutex.synchronize do
99
101
  next if File.directory?(filename) || !File.exist?(filename)
100
102
  next unless contain?(filename) || open?(filename) || workspace.would_merge?(filename)
103
+ @synchronized = false
101
104
  source = Solargraph::Source.load_string(File.read(filename), filename)
102
105
  workspace.merge(source)
103
106
  open_file_hash[filename] = source if open_file_hash.key?(filename)
@@ -116,6 +119,7 @@ module Solargraph
116
119
  # @return [void]
117
120
  def delete filename
118
121
  mutex.synchronize do
122
+ @synchronized = false
119
123
  open_file_hash.delete filename
120
124
  workspace.remove filename
121
125
  catalog
@@ -129,6 +133,7 @@ module Solargraph
129
133
  # @return [void]
130
134
  def close filename
131
135
  mutex.synchronize do
136
+ @synchronized = false
132
137
  open_file_hash.delete filename
133
138
  catalog
134
139
  end
@@ -182,6 +187,7 @@ module Solargraph
182
187
  # @return [Array<Solargraph::Range>]
183
188
  # @todo Take a Location instead of filename/line/column
184
189
  def references_from filename, line, column, strip: false
190
+ checkout filename
185
191
  cursor = api_map.cursor_at(filename, Position.new(line, column))
186
192
  clip = api_map.clip(cursor)
187
193
  pins = clip.define
@@ -235,7 +241,9 @@ module Solargraph
235
241
  # @param filename [String]
236
242
  # @return [Source]
237
243
  def checkout filename
238
- @current = read(filename)
244
+ checked = read(filename)
245
+ @synchronized = (checked.filename == @current.filename) if synchronized?
246
+ @current = checked
239
247
  catalog
240
248
  @current
241
249
  end
@@ -243,12 +251,14 @@ module Solargraph
243
251
  # @param query [String]
244
252
  # @return [Array<YARD::CodeObject::Base>]
245
253
  def document query
254
+ catalog
246
255
  api_map.document query
247
256
  end
248
257
 
249
258
  # @param query [String]
250
259
  # @return [Array<String>]
251
260
  def search query
261
+ catalog
252
262
  api_map.search query
253
263
  end
254
264
 
@@ -257,6 +267,7 @@ module Solargraph
257
267
  # @param query [String]
258
268
  # @return [Array<Pin::Base>]
259
269
  def query_symbols query
270
+ catalog
260
271
  api_map.query_symbols query
261
272
  end
262
273
 
@@ -269,6 +280,7 @@ module Solargraph
269
280
  # @param filename [String]
270
281
  # @return [Array<Solargraph::Pin::Base>]
271
282
  def document_symbols filename
283
+ checkout filename
272
284
  return [] unless open_file_hash.key?(filename)
273
285
  api_map.document_symbols(filename)
274
286
  end
@@ -276,13 +288,14 @@ module Solargraph
276
288
  # @param path [String]
277
289
  # @return [Array<Solargraph::Pin::Base>]
278
290
  def path_pins path
291
+ catalog
279
292
  api_map.get_path_suggestions(path)
280
293
  end
281
294
 
282
295
  # Update a source in the library from the provided updater.
283
296
  #
284
297
  # @note This method will not update the library's ApiMap. See
285
- # Library#ynchronized? and Library#catalog for more information.
298
+ # Library#synchronized? and Library#catalog for more information.
286
299
  #
287
300
  #
288
301
  # @raise [FileNotFoundError] if the updater's file is not available.
@@ -334,9 +347,12 @@ module Solargraph
334
347
  #
335
348
  # @return [void]
336
349
  def catalog
337
- logger.info "Cataloging #{workspace.directory.empty? ? 'generic workspace' : workspace.directory}"
338
- api_map.catalog bundle
339
- @synchronized = true
350
+ @catalog_mutex.synchronize do
351
+ break if synchronized?
352
+ logger.info "Cataloging #{workspace.directory.empty? ? 'generic workspace' : workspace.directory}"
353
+ api_map.catalog bundle
354
+ @synchronized = true
355
+ end
340
356
  end
341
357
 
342
358
  def folding_ranges filename
@@ -1,3 +1,3 @@
1
1
  module Solargraph
2
- VERSION = '0.30.0'
2
+ VERSION = '0.30.1'
3
3
  end
@@ -8,8 +8,7 @@
8
8
  <ul class="doc-list">
9
9
  <% object.meths(scope: :class).sort{|a, b| a.name <=> b.name}.each do |meth| %>
10
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>
11
+ <a href="solargraph:/document?query=<%= URI.escape(meth.path) %>"><%= meth.name %></a>
13
12
  </li>
14
13
  <% end %>
15
14
  </ul>
@@ -19,8 +18,7 @@
19
18
  <ul class="doc-list">
20
19
  <% object.meths(scope: :instance).sort{|a, b| a.name <=> b.name}.each do |meth| %>
21
20
  <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>
21
+ <a href="solargraph:/document?query=<%= URI.escape(meth.path) %>"><%= meth.name %></a>
24
22
  </li>
25
23
  <% end %>
26
24
  </ul>
@@ -4,8 +4,7 @@
4
4
  <ul class="doc-list">
5
5
  <% results.each do |result| %>
6
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>
7
+ <a href="solargraph:/document?query=<%= CGI.escape(result) %>"><%= result %></a>
9
8
  </li>
10
9
  <% end %>
11
10
  </ul>
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.30.0
4
+ version: 0.30.1
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-12-26 00:00:00.000000000 Z
11
+ date: 2018-12-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: backport