Class: Spoom::Cli::LSP

Inherits:
Thor
  • Object
show all
Includes:
Helper
Defined in:
lib/spoom/cli/lsp.rb

Constant Summary

Constants included from Helper

Helper::HIGHLIGHT_COLOR

Instance Method Summary collapse

Methods included from Helper

#blue, #color?, #colorize, #context, #context_requiring_sorbet!, #cyan, #exec_path, #gray, #green, #highlight, #red, #say, #say_error, #yellow

Methods included from Spoom::Colorize

#set_color

Instance Method Details

#defs(file, line, col) ⇒ Object

TODO: options, filter, limit, kind etc.. filter rbi



55
56
57
58
59
60
61
# File 'lib/spoom/cli/lsp.rb', line 55

def defs(file, line, col)
  run do |client|
    res = client.definitions(to_uri(file), line.to_i, col.to_i)
    say("Definitions for `#{file}:#{line}:#{col}`:")
    symbol_printer.print_list(res)
  end
end

#find(query) ⇒ Object

TODO: options, filter, limit, kind etc.. filter rbi



65
66
67
68
69
70
71
# File 'lib/spoom/cli/lsp.rb', line 65

def find(query)
  run do |client|
    res = client.symbols(query).reject { |symbol| symbol.location.uri.start_with?("https") }
    say("Symbols matching `#{query}`:")
    symbol_printer.print_objects(res)
  end
end

#hover(file, line, col) ⇒ Object

TODO: options, filter, limit, kind etc.. filter rbi



41
42
43
44
45
46
47
48
49
50
51
# File 'lib/spoom/cli/lsp.rb', line 41

def hover(file, line, col)
  run do |client|
    res = client.hover(to_uri(file), line.to_i, col.to_i)
    say("Hovering `#{file}:#{line}:#{col}`:")
    if res
      symbol_printer.print_object(res)
    else
      say("<no data>")
    end
  end
end

#listObject

TODO: options, filter, limit, kind etc.. filter rbi



26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/spoom/cli/lsp.rb', line 26

def list
  run do |client|
    printer = symbol_printer
    Dir["**/*.rb"].each do |file|
      res = client.document_symbols(to_uri(file))
      next if res.empty?

      say("Symbols from `#{file}`:")
      printer.print_objects(res)
    end
  end
end

#refs(file, line, col) ⇒ Object

TODO: options, filter, limit, kind etc.. filter rbi



85
86
87
88
89
90
91
# File 'lib/spoom/cli/lsp.rb', line 85

def refs(file, line, col)
  run do |client|
    res = client.references(to_uri(file), line.to_i, col.to_i)
    say("References to `#{file}:#{line}:#{col}`:")
    symbol_printer.print_list(res)
  end
end

#showObject



16
17
18
19
20
21
22
# File 'lib/spoom/cli/lsp.rb', line 16

def show
  context_requiring_sorbet!

  lsp = lsp_client
  # TODO: run interactive mode
  puts lsp
end

#sigs(file, line, col) ⇒ Object

TODO: options, filter, limit, kind etc.. filter rbi



95
96
97
98
99
100
101
# File 'lib/spoom/cli/lsp.rb', line 95

def sigs(file, line, col)
  run do |client|
    res = client.signatures(to_uri(file), line.to_i, col.to_i)
    say("Signature for `#{file}:#{line}:#{col}`:")
    symbol_printer.print_list(res)
  end
end

#symbols(file) ⇒ Object

TODO: options, filter, limit, kind etc.. filter rbi



75
76
77
78
79
80
81
# File 'lib/spoom/cli/lsp.rb', line 75

def symbols(file)
  run do |client|
    res = client.document_symbols(to_uri(file))
    say("Symbols from `#{file}`:")
    symbol_printer.print_objects(res)
  end
end

#types(file, line, col) ⇒ Object

TODO: options, filter, limit, kind etc.. filter rbi



105
106
107
108
109
110
111
# File 'lib/spoom/cli/lsp.rb', line 105

def types(file, line, col)
  run do |client|
    res = client.type_definitions(to_uri(file), line.to_i, col.to_i)
    say("Type for `#{file}:#{line}:#{col}`:")
    symbol_printer.print_list(res)
  end
end