Module: Ibex::LSP::NavigationHandlers

Includes:
RequestSupport
Included in:
RequestHandlers
Defined in:
lib/ibex/lsp/navigation_handlers.rb,
sig/ibex/lsp/navigation_handlers.rbs

Overview

Serves symbol navigation, rename, and hover requests.

Instance Method Summary collapse

Methods included from RequestSupport

#hash_member, #integer_member, #params_hash, #publish, #require_running!, #require_state!, #stale_publication?, #store, #string_member, #workspace

Instance Method Details

#definition(raw_params) ⇒ Array[Hash[String, untyped]]

RBS:

  • (untyped raw_params) -> Array[Hash[String, untyped]]

Parameters:

  • raw_params (Object)

Returns:

  • (Array[Hash[String, untyped]])


12
13
14
# File 'lib/ibex/lsp/navigation_handlers.rb', line 12

def definition(raw_params)
  with_index(raw_params) { |index, path, position| index.definition(path, position) }
end

#hover(raw_params) ⇒ Hash[String, untyped]?

RBS:

  • (untyped raw_params) -> Hash[String, untyped]?

Parameters:

  • raw_params (Object)

Returns:

  • (Hash[String, untyped], nil)


39
40
41
# File 'lib/ibex/lsp/navigation_handlers.rb', line 39

def hover(raw_params)
  with_index(raw_params) { |index, path, position| index.hover(path, position) }
end

#prepare_rename(raw_params) ⇒ Hash[String, untyped]?

RBS:

  • (untyped raw_params) -> Hash[String, untyped]?

Parameters:

  • raw_params (Object)

Returns:

  • (Hash[String, untyped], nil)


27
28
29
# File 'lib/ibex/lsp/navigation_handlers.rb', line 27

def prepare_rename(raw_params)
  with_index(raw_params) { |index, path, position| index.prepare_rename(path, position) }
end

#references(raw_params) ⇒ Array[Hash[String, untyped]]

RBS:

  • (untyped raw_params) -> Array[Hash[String, untyped]]

Parameters:

  • raw_params (Object)

Returns:

  • (Array[Hash[String, untyped]])


17
18
19
20
21
22
23
24
# File 'lib/ibex/lsp/navigation_handlers.rb', line 17

def references(raw_params)
  params = params_hash(raw_params)
  context = hash_member(params, "context")
  include_declaration = context["includeDeclaration"] == true
  with_index(params) do |index, path, position|
    index.references(path, position, include_declaration: include_declaration)
  end
end

#rename(raw_params) ⇒ Hash[String, untyped]

RBS:

  • (untyped raw_params) -> Hash[String, untyped]

Parameters:

  • raw_params (Object)

Returns:

  • (Hash[String, untyped])


32
33
34
35
36
# File 'lib/ibex/lsp/navigation_handlers.rb', line 32

def rename(raw_params)
  params = params_hash(raw_params)
  new_name = string_member(params, "newName")
  with_index(params) { |index, path, position| index.rename(path, position, new_name) }
end

#with_index(raw_params) {|arg0, arg1, arg2| ... } ⇒ Object

RBS:

  • (untyped raw_params) { (SymbolIndex, String, Hash[String, untyped]) -> untyped } -> untyped

Parameters:

  • raw_params (Object)

Yields:

Yield Parameters:

  • arg0 (SymbolIndex)
  • arg1 (String)
  • arg2 (Hash[String, untyped])

Yield Returns:

  • (Object)

Returns:

  • (Object)


44
45
46
47
48
49
50
51
52
53
# File 'lib/ibex/lsp/navigation_handlers.rb', line 44

def with_index(raw_params)
  require_running!
  params = params_hash(raw_params)
  document = hash_member(params, "textDocument")
  path = workspace.path(string_member(document, "uri"))
  position = hash_member(params, "position")
  yield SymbolIndex.new(store, path), path, position
rescue ArgumentError => e
  raise ProtocolError.new(e.message, code: -32_602)
end