Class: Mbeditor::JsDefinitionService

Inherits:
Object
  • Object
show all
Defined in:
app/services/mbeditor/js_definition_service.rb

Overview

Searches JS/JSX/TS/TSX files in the workspace for definitions of a named JavaScript global (variable, function, class, or window property assignment).

Uses ripgrep (falling back to grep) to locate lines matching common definition patterns, then returns workspace-relative results.

Returns an array of hashes:

{ file: String, line: Integer, snippet: String }

Constant Summary collapse

MAX_RESULTS =
20
JS_GLOBS =
%w[*.js *.jsx *.ts *.tsx *.js.jsx *.js.erb *.jsx.erb].freeze

Instance Method Summary collapse

Constructor Details

#initialize(symbol, workspace_root) ⇒ JsDefinitionService

Returns a new instance of JsDefinitionService.



19
20
21
22
# File 'app/services/mbeditor/js_definition_service.rb', line 19

def initialize(symbol, workspace_root)
  @symbol         = symbol.to_s
  @workspace_root = workspace_root.to_s.chomp("/")
end

Instance Method Details

#callObject



24
25
26
27
28
29
30
31
# File 'app/services/mbeditor/js_definition_service.rb', line 24

def call
  return [] if @symbol.empty? || @workspace_root.empty?
  return [] unless File.directory?(@workspace_root)

  pattern = build_pattern
  lines   = run_search(pattern)
  parse_results(lines)
end