Class: Mbeditor::JsDefinitionService
- Inherits:
-
Object
- Object
- Mbeditor::JsDefinitionService
- 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
- #call ⇒ Object
-
#initialize(symbol, workspace_root) ⇒ JsDefinitionService
constructor
A new instance of JsDefinitionService.
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
#call ⇒ Object
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 |