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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
|
# File 'lib/platformos_check/language_server/diagnostics_manager.rb', line 36
def build_diagnostics(offenses, analyzed_files: nil, only_single_file: false)
@mutex.synchronize do
full_check = analyzed_files.nil?
analyzed_paths = analyzed_files.map { |path| Pathname.new(path) } unless full_check
current_diagnostics = offenses
.select(&:app_file)
.group_by(&:app_file)
.transform_keys { |app_file| Pathname.new(app_file.relative_path) }
.transform_values do |app_file_offenses|
app_file_offenses.map { |o| Diagnostic.new(o) }
end
previous_paths = paths(@latest_diagnostics)
current_paths = paths(current_diagnostics)
diagnostics_update = (current_paths + previous_paths).map do |path|
if only_single_file && analyzed_paths.include?(path)
single_file_diagnostics = current_diagnostics[path] || NO_DIAGNOSTICS
whole_platformos_app_diagnostics = whole_platformos_app_diagnostics(path) || NO_DIAGNOSTICS
[path, single_file_diagnostics + whole_platformos_app_diagnostics]
elsif only_single_file
[path, previous_diagnostics(path) || NO_DIAGNOSTICS]
elsif full_check
[path, current_diagnostics[path] || NO_DIAGNOSTICS]
else
new_diagnostics = current_diagnostics[path] || NO_DIAGNOSTICS
should_use_cached_results = !analyzed_paths.include?(path)
old_diagnostics = should_use_cached_results ? single_file_diagnostics(path) : []
[path, new_diagnostics + old_diagnostics]
end
end.to_h
@latest_diagnostics = diagnostics_update
.reject { |_, v| v.empty? }
@first_run = false
diagnostics_update
.reject { |p, _| only_single_file && !analyzed_paths.include?(p) }
end
end
|