Module: Ibex::LSP::DocumentStoreDiagnostics

Included in:
DocumentStore
Defined in:
lib/ibex/lsp/document_store_diagnostics.rb,
sig/ibex/lsp/document_store_diagnostics.rbs

Overview

Owns per-document and per-root diagnostic aggregation for DocumentStore.

Instance Method Summary collapse

Instance Method Details

#aggregated_diagnostics(path) ⇒ Array[WorkspaceAnalyzer::lsp_diagnostic]

RBS:

  • (String path) -> Array[WorkspaceAnalyzer::lsp_diagnostic]

Parameters:

  • path (String)

Returns:

  • (Array[WorkspaceAnalyzer::lsp_diagnostic])


29
30
31
32
33
34
35
36
# File 'lib/ibex/lsp/document_store_diagnostics.rb', line 29

def aggregated_diagnostics(path)
  # @type self: DocumentStore
  diagnostics = @document_diagnostics.fetch(path, empty_diagnostics).dup
  @root_diagnostics.each_value do |owned|
    diagnostics.concat(owned.fetch(path, empty_diagnostics))
  end
  diagnostics.uniq
end

#empty_diagnosticsArray[WorkspaceAnalyzer::lsp_diagnostic]

RBS:

  • () -> Array[WorkspaceAnalyzer::lsp_diagnostic]

Returns:

  • (Array[WorkspaceAnalyzer::lsp_diagnostic])


39
40
41
# File 'lib/ibex/lsp/document_store_diagnostics.rb', line 39

def empty_diagnostics
  [] #: Array[WorkspaceAnalyzer::lsp_diagnostic]
end

#replace_root_diagnostics(root, files, analyzed, errors) ⇒ void

This method returns an undefined value.

RBS:

  • (String root, Array[String] files, Hash[String, WorkspaceAnalyzer::analyzed_document] analyzed, Array[WorkspaceAnalyzer::lsp_diagnostic] errors) -> void

Parameters:

  • root (String)
  • files (Array[String])
  • analyzed (Hash[String, WorkspaceAnalyzer::analyzed_document])
  • errors (Array[WorkspaceAnalyzer::lsp_diagnostic])


11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/ibex/lsp/document_store_diagnostics.rb', line 11

def replace_root_diagnostics(root, files, analyzed, errors)
  # @type self: DocumentStore
  owned = {} #: Hash[String, Array[WorkspaceAnalyzer::lsp_diagnostic]]
  files.each { |path| owned[path] = analyzed.dig(path, :diagnostics) || [] }
  errors.each do |diagnostic|
    file = diagnostic.dig("data", "file")
    next unless file

    existing = owned[file] || []
    duplicate = existing.any? do |entry|
      entry["range"] == diagnostic["range"] && entry["message"] == diagnostic["message"]
    end
    owned[file] = existing + [diagnostic] unless duplicate
  end
  @root_diagnostics[root] = owned
end