klenod-lsp 0.0.16 → 0.0.17

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: 6c19da186ca2391c2bec38dfa3aa24e17458b7925d9dbb92b3f444e5782297a3
4
- data.tar.gz: dfda5e93c14feb280fb601d1f0234e5f9c25718e9f30eb644845911e3ebfda6e
3
+ metadata.gz: 8177f2a77a4e5e7b60ae1c83dc1d5106ad639b1357291987260e1b7915e4bd6f
4
+ data.tar.gz: 3a84fbf499a587a1592188606bc6be5d354b85f64d8acb8b03fe4eabc77add25
5
5
  SHA512:
6
- metadata.gz: 427d0cc60eaaafcc8418d3456e23f610806ad12327a56e9ae1f8ab0999c016c6bacc2c22c15cd6ff905e0e18895826218b109c6b851e0b581f5ea232e117f239
7
- data.tar.gz: b0b4fac3a4632a9db230f2089b6395a650971cfef7de75b7b7773ac828ad5c3640c571fb924e5dd191c3f0f43ed732f9ce5be36c254f4c2d9651b5382f913a5f
6
+ metadata.gz: 98dc6548b480686f3b577787663feac6a6a4d3e0315eb71a96962986bdb60de975e4078df05369d670a6455733d1028dc89098983e73a4264fcb6ad43089ba53
7
+ data.tar.gz: 1ae98c5232a88076529ed9828a0317dc35a532f65ce850abe88c7b2af016270c6f85c87ee9864b49fb0735065addcc6041de155fa485905794f19b2267333b5e
@@ -58,6 +58,29 @@ module Klenod
58
58
  }.uniq { |diagnostic| [diagnostic.range.start.line, diagnostic.message] }
59
59
  end
60
60
 
61
+ # A failure the graph index recorded while collecting this module that
62
+ # analysis alone cannot see, such as a named import of a constant the
63
+ # target does not define: analysis only transforms and resolves, it never
64
+ # collects the target's record. The index refreshes on save, so the
65
+ # diagnostic is only shown while the document still contains the import
66
+ # it refers to.
67
+ def index_failure(analysis, index, syntax: Languages::Syntax::Ruby)
68
+ error = index&.failed&.[](analysis.module_id.to_s)
69
+ return [] unless error.is_a?(Klenod::Build::MissingExportError)
70
+ return [] unless error.module_id.to_s == analysis.module_id.to_s
71
+
72
+ lines = analysis.lines
73
+ report = error.cause
74
+ span = literal_spans(report.dependency.specifier.to_s, lines, syntax: syntax).find do |candidate|
75
+ named_import_span?(candidate, report.name, lines)
76
+ end
77
+ return [] unless span
78
+
79
+ message = "#{error.kind}: #{error.detail}"
80
+ message = "#{message}\n#{error.hints.join("\n")}" unless error.hints.empty?
81
+ [diagnostic(span, message)]
82
+ end
83
+
61
84
  def resolve_errors(analysis, lines, syntax)
62
85
  analysis.resolve_errors.map do |error|
63
86
  diagnostic(resolve_error_span(error, lines, syntax), error.message)
@@ -93,6 +116,14 @@ module Klenod
93
116
  spans
94
117
  end
95
118
 
119
+ # The same module can be imported more than once with different names.
120
+ # Match the name immediately following this literal rather than selecting
121
+ # the first matching specifier and inspecting its whole line.
122
+ def named_import_span?(span, name, lines)
123
+ suffix = lines[span.start.line].to_s[span.end.character..]
124
+ suffix&.match?(%r{\A["']\s*,\s*:#{Regexp.escape(name.to_s)}(?=\s*\))})
125
+ end
126
+
96
127
  def diagnostic(span, message)
97
128
  Interface::Diagnostic.new(
98
129
  range: span.to_range,
@@ -23,6 +23,7 @@ module Klenod
23
23
 
24
24
  def diagnostics(analysis, workspace = nil, index = nil)
25
25
  diagnostics = Diagnostics.for_analysis(analysis)
26
+ diagnostics.concat(Diagnostics.index_failure(analysis, index))
26
27
  diagnostics.concat(Classes.diagnostics(analysis, workspace, index)) if workspace && index
27
28
  diagnostics.concat(Props.diagnostics(analysis, workspace, index)) if workspace && index
28
29
  diagnostics.concat(unused_binding_diagnostics(analysis))
@@ -15,8 +15,8 @@ module Klenod
15
15
 
16
16
  Interface = LanguageServer::Protocol::Interface
17
17
 
18
- def diagnostics(analysis, _workspace = nil, _index = nil)
19
- Diagnostics.for_analysis(analysis) + unused_binding_diagnostics(analysis)
18
+ def diagnostics(analysis, _workspace = nil, index = nil)
19
+ Diagnostics.for_analysis(analysis) + Diagnostics.index_failure(analysis, index) + unused_binding_diagnostics(analysis)
20
20
  end
21
21
 
22
22
  def document_symbols(analysis)
@@ -371,11 +371,11 @@ module Klenod
371
371
 
372
372
  @pending_collections.delete(document.uri)&.stop
373
373
  @pending_collections[document.uri] =
374
- @task.async do |task|
375
- task.sleep(DIAGNOSTICS_DEBOUNCE)
374
+ @task.async do
375
+ Kernel.sleep(DIAGNOSTICS_DEBOUNCE)
376
376
  publish_diagnostics(document)
377
377
  overlay(document)
378
- task.sleep(COLLECTION_DEBOUNCE - DIAGNOSTICS_DEBOUNCE)
378
+ Kernel.sleep(COLLECTION_DEBOUNCE - DIAGNOSTICS_DEBOUNCE)
379
379
  @pending_collections.delete(document.uri)
380
380
  @index.ensure_collected(document.module_id, force: true)
381
381
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Klenod
4
4
  module LSP
5
- VERSION = "0.0.16"
5
+ VERSION = "0.0.17"
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: klenod-lsp
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.16
4
+ version: 0.0.17
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrés Alin
@@ -15,14 +15,14 @@ dependencies:
15
15
  requirements:
16
16
  - - '='
17
17
  - !ruby/object:Gem::Version
18
- version: 0.0.16
18
+ version: 0.0.17
19
19
  type: :runtime
20
20
  prerelease: false
21
21
  version_requirements: !ruby/object:Gem::Requirement
22
22
  requirements:
23
23
  - - '='
24
24
  - !ruby/object:Gem::Version
25
- version: 0.0.16
25
+ version: 0.0.17
26
26
  - !ruby/object:Gem::Dependency
27
27
  name: language_server-protocol
28
28
  requirement: !ruby/object:Gem::Requirement