Module: Canopus::Workspace::ProblemsAware

Defined in:
lib/canopus/workspace/problems_aware.rb

Constant Summary collapse

PROBLEM_LABEL_LIMIT =
200
PROBLEM_FILTER_LIMIT =
4_096

Instance Method Summary collapse

Instance Method Details

#filter_problems(severity: nil, source: nil, text: nil) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/canopus/workspace/problems_aware.rb', line 16

def filter_problems(severity: nil, source: nil, text: nil)
  severity = Diagnostics::SEVERITIES.fetch(severity, severity) if severity.is_a?(Symbol)
  unless severity.nil? || severity.is_a?(Integer) && severity.between?(1, 4)
    raise ArgumentError, "invalid problem severity"
  end
  unless source.nil? || Diagnostics::SOURCES.include?(source)
    raise ArgumentError, "invalid problem source"
  end
  unless text.nil? || text.is_a?(String) && text.encoding == Encoding::UTF_8 && text.valid_encoding? &&
      text.bytesize <= PROBLEM_FILTER_LIMIT && !text.include?("\0")
    raise ArgumentError, "invalid problem text"
  end

  @problem_filter = {severity: severity, source: source, text: text&.downcase}.freeze
  refresh_problems
  @problem_filter
end

#problems_tree ⇒ Object



10
11
12
13
14
# File 'lib/canopus/workspace/problems_aware.rb', line 10

def problems_tree
  @problems_tree ||= Zaniah::UI::TreeView.new(problem_nodes, height: 320).on_select do |value, _event, _context|
    select_problem(value)
  end
end

#show_problem_filter ⇒ Object



34
35
36
# File 'lib/canopus/workspace/problems_aware.rb', line 34

def show_problem_filter
  self.palette = {kind: :problem_filter, query: +(@problem_filter_query || ""), index: 0, matches: []}
end