6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
|
# File 'lib/puppet-languageserver/epp/validation_provider.rb', line 6
def self.validate(content, _max_problems = 100)
result = []
_problems = 0
begin
parser = Puppet::Pops::Parser::EvaluatingParser::EvaluatingEppParser.new
parser.parse_string(content, nil)
rescue StandardError => e
e = e.cause if !e.respond_to?(:line) && e.respond_to?(:cause)
ex_line = e.respond_to?(:line) && !e.line.nil? ? e.line - 1 : nil ex_pos = e.respond_to?(:pos) && !e.pos.nil? ? e.pos : nil
message = e.respond_to?(:message) ? e.message : nil
message = e.basic_message if message.nil? && e.respond_to?(:basic_message)
unless ex_line.nil? || ex_pos.nil? || message.nil?
result << LSP::Diagnostic.new('severity' => LSP::DiagnosticSeverity::ERROR,
'range' => LSP.create_range(ex_line, ex_pos, ex_line, ex_pos + 1),
'source' => 'Puppet',
'message' => message)
end
end
result
end
|