Module: Kapusta::LSP::Definition
- Defined in:
- lib/kapusta/lsp/definition.rb
Class Method Summary collapse
- .binding_range(binding) ⇒ Object
- .find(uri, text, line_zero, character, workspace_index:) ⇒ Object
- .location_for_binding(uri, binding) ⇒ Object
- .locations_for_constant(prefix, workspace_index) ⇒ Object
- .locations_for_macro(uri, binding, workspace_index) ⇒ Object
- .locations_for_toplevel(name, workspace_index) ⇒ Object
Class Method Details
.binding_range(binding) ⇒ Object
58 59 60 61 62 63 64 |
# File 'lib/kapusta/lsp/definition.rb', line 58 def binding_range(binding) line = binding.line - 1 { start: { line:, character: binding.column - 1 }, end: { line:, character: binding.end_column - 1 } } end |
.find(uri, text, line_zero, character, workspace_index:) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/kapusta/lsp/definition.rb', line 10 def find(uri, text, line_zero, character, workspace_index:) target = Rename.locate(text, line_zero, character) return unless target case target.kind when :local, :toplevel_fn, :constant location_for_binding(uri, target.binding) if target.binding when :macro locations_for_macro(uri, target.binding, workspace_index) when :free_toplevel locations_for_toplevel(target.name, workspace_index) when :free_constant locations_for_constant(target.segment_prefix, workspace_index) end end |
.location_for_binding(uri, binding) ⇒ Object
40 41 42 |
# File 'lib/kapusta/lsp/definition.rb', line 40 def location_for_binding(uri, binding) { uri:, range: binding_range(binding) } end |
.locations_for_constant(prefix, workspace_index) ⇒ Object
51 52 53 54 55 56 |
# File 'lib/kapusta/lsp/definition.rb', line 51 def locations_for_constant(prefix, workspace_index) defs = workspace_index.constant_definitions_with_prefix(prefix) return if defs.empty? defs.map { |uri, b| { uri:, range: binding_range(b) } } end |
.locations_for_macro(uri, binding, workspace_index) ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/kapusta/lsp/definition.rb', line 26 def locations_for_macro(uri, binding, workspace_index) return unless binding case binding.kind when :macro location_for_binding(uri, binding) when :macro_import def_uri, def_binding = workspace_index.find_macro_definition( uri, binding.import_module, binding.import_key ) location_for_binding(def_uri, def_binding) if def_uri && def_binding end end |
.locations_for_toplevel(name, workspace_index) ⇒ Object
44 45 46 47 48 49 |
# File 'lib/kapusta/lsp/definition.rb', line 44 def locations_for_toplevel(name, workspace_index) defs = workspace_index.toplevel_fn_definitions(name) return if defs.empty? defs.map { |uri, b| { uri:, range: binding_range(b) } } end |