Method: ImportJS::Importer#import

Defined in:
lib/import_js/importer.rb

#importObject

Finds variable under the cursor to import. By default, this is bound to ‘<Leader>j`.



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/import_js/importer.rb', line 14

def import
  reload_config
  variable_name = @editor.current_word
  if variable_name.empty?
    message("      No variable to import. Place your cursor on a variable, then try\n      again.\n    EOS\n    return\n  end\n\n  js_module = find_one_js_module(variable_name)\n  return unless js_module\n\n  maintain_cursor_position do\n    old_imports = find_current_imports\n    import_statement = js_module.to_import_statement(variable_name, @config)\n    old_imports[:imports] << import_statement\n    replace_imports(old_imports[:range], old_imports[:imports])\n  end\nend\n".split.join(' '))