Class: ThemeCheck::LanguageServer::DiagnosticsEngine

Inherits:
Object
  • Object
show all
Includes:
URIHelper
Defined in:
lib/theme_check/language_server/diagnostics_engine.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from URIHelper

#file_path, #file_uri

Constructor Details

#initialize(storage, bridge, diagnostics_manager = DiagnosticsManager.new) ⇒ DiagnosticsEngine

Returns a new instance of DiagnosticsEngine.



10
11
12
13
14
15
16
# File 'lib/theme_check/language_server/diagnostics_engine.rb', line 10

def initialize(storage, bridge, diagnostics_manager = DiagnosticsManager.new)
  @diagnostics_lock = Mutex.new
  @diagnostics_manager = diagnostics_manager
  @storage = storage
  @bridge = bridge
  @token = 0
end

Instance Attribute Details

#storageObject (readonly)

Returns the value of attribute storage.



8
9
10
# File 'lib/theme_check/language_server/diagnostics_engine.rb', line 8

def storage
  @storage
end

Instance Method Details

#analyze_and_send_offenses(absolute_path, config, force: false, only_single_file: false) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/theme_check/language_server/diagnostics_engine.rb', line 22

def analyze_and_send_offenses(absolute_path, config, force: false, only_single_file: false)
  return unless @diagnostics_lock.try_lock
  @token += 1
  @bridge.send_create_work_done_progress_request(@token)
  theme = ThemeCheck::Theme.new(storage)
  analyzer = ThemeCheck::Analyzer.new(theme, config.enabled_checks)

  if (!only_single_file && @diagnostics_manager.first_run?) || force
    @bridge.send_work_done_progress_begin(@token, "Full theme check")
    @bridge.log("Checking #{storage.root}")
    offenses = nil
    time = Benchmark.measure do
      offenses = analyzer.analyze_theme do |path, i, total|
        @bridge.send_work_done_progress_report(@token, "#{i}/#{total} #{path}", (i.to_f / total * 100.0).to_i)
      end
    end
    end_message = "Found #{offenses.size} offenses in #{format("%0.2f", time.real)}s"
    @bridge.send_work_done_progress_end(@token, end_message)
    @bridge.log(end_message)
    send_diagnostics(offenses)
  else
    # Analyze selected files
    relative_path = Pathname.new(storage.relative_path(absolute_path))
    file = theme[relative_path]
    # Skip if not a theme file
    if file
      @bridge.send_work_done_progress_begin(@token, "Partial theme check")
      offenses = nil
      time = Benchmark.measure do
        offenses = analyzer.analyze_files([file], only_single_file: only_single_file) do |path, i, total|
          @bridge.send_work_done_progress_report(@token, "#{i}/#{total} #{path}", (i.to_f / total * 100.0).to_i)
        end
      end
      end_message = "Found #{offenses.size} new offenses in #{format("%0.2f", time.real)}s"
      @bridge.send_work_done_progress_end(@token, end_message)
      @bridge.log(end_message)
      send_diagnostics(offenses, [relative_path], only_single_file: only_single_file)
    end
  end
  @diagnostics_lock.unlock
end

#first_run?Boolean

Returns:

  • (Boolean)


18
19
20
# File 'lib/theme_check/language_server/diagnostics_engine.rb', line 18

def first_run?
  @diagnostics_manager.first_run?
end