Class: Spoom::Cli::LSP

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

Instance Method Summary collapse

Methods included from Helper

#color?, #colorize, #exec_path, #in_sorbet_project!, #in_sorbet_project?, #say_error, #sorbet_config

Instance Method Details

#defs(file, line, col) ⇒ Object

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



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

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

#find(query) ⇒ Object

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



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

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

#hover(file, line, col) ⇒ Object

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



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

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
      puts "<no data>"
    end
  end
end

#listObject

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



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

def list
  run do |client|
    printer = symbol_printer
    Dir["**/*.rb"].each do |file|
      res = client.document_symbols(to_uri(file))
      next if res.empty?
      puts "Symbols from `#{file}`:"
      printer.print_objects(res)
    end
  end
end

#refs(file, line, col) ⇒ Object

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



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

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

#showObject



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

def show
  in_sorbet_project!
  lsp = lsp_client
  # TODO: run interactive mode
  puts lsp
end

#sigs(file, line, col) ⇒ Object

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



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

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

#symbols(file) ⇒ Object

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



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

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

#types(file, line, col) ⇒ Object

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



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

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