Module: Kapusta::LSP::Diagnostics
- Defined in:
- lib/kapusta/lsp/diagnostics.rb
Constant Summary collapse
- SEVERITY_ERROR =
1
Class Method Summary collapse
- .collect(text, path) ⇒ Object
- .diagnostic_from(error, text) ⇒ Object
- .token_length(text, line, column) ⇒ Object
Class Method Details
.collect(text, path) ⇒ Object
10 11 12 13 14 15 |
# File 'lib/kapusta/lsp/diagnostics.rb', line 10 def collect(text, path) Kapusta.compile(text, path: path || '(buffer)') [] rescue Kapusta::Error => e [diagnostic_from(e, text)] end |
.diagnostic_from(error, text) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/kapusta/lsp/diagnostics.rb', line 17 def diagnostic_from(error, text) line = [(error.line || 1) - 1, 0].max column = [(error.column || 1) - 1, 0].max { range: { start: { line:, character: column }, end: { line:, character: column + token_length(text, line, column) } }, severity: SEVERITY_ERROR, source: 'kapusta-ls', message: error.reason } end |
.token_length(text, line, column) ⇒ Object
32 33 34 35 36 37 38 39 |
# File 'lib/kapusta/lsp/diagnostics.rb', line 32 def token_length(text, line, column) source_line = text.lines[line] return 1 unless source_line tail = source_line[column..] || '' match = tail.match(/\A[^\s()\[\]{}";`,]+/) match && match[0].length.positive? ? match[0].length : 1 end |