Class: NvimContext::DataExtractor
- Inherits:
-
Object
- Object
- NvimContext::DataExtractor
- Defined in:
- lib/nvim_context/data_extractor.rb
Class Method Summary collapse
- .cursor(client:) ⇒ Object
- .diagnostics(client:) ⇒ Object
- .file(client:) ⇒ Object
- .visual_selection(client:) ⇒ Object
Class Method Details
.cursor(client:) ⇒ Object
5 6 7 8 9 10 11 12 |
# File 'lib/nvim_context/data_extractor.rb', line 5 def self.cursor(client:) cursor = client.current.window.cursor { line: cursor[0], col: cursor[1] } rescue StandardError => e raise ContextError, "Failed to get cursor info: #{e.}", e.backtrace end |
.diagnostics(client:) ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/nvim_context/data_extractor.rb', line 32 def self.diagnostics(client:) client.eval("vim.diagnostic.get(0)").map do |diagnostic| { line: diagnostic["lnum"] + 1, col: diagnostic["col"] + 1, message: diagnostic["message"], severity: diagnostic["severity"] } end rescue StandardError [] end |
.file(client:) ⇒ Object
14 15 16 17 18 19 20 |
# File 'lib/nvim_context/data_extractor.rb', line 14 def self.file(client:) client.current.buffer.name rescue StandardError => e raise ContextError, "Failed to get file info: #{e.}", e.backtrace end |
.visual_selection(client:) ⇒ Object
22 23 24 25 26 27 28 29 30 |
# File 'lib/nvim_context/data_extractor.rb', line 22 def self.visual_selection(client:) return nil unless visual_mode?(client) marks = visual_marks(client) text = selected_text(client, marks) build_selection_info(marks, text) rescue StandardError nil end |