def run(self, edit): """Called when the command is run.""" self.edit = edit cursor = self.view.sel()[0] word_region = self.view.word(cursor) word_text = self.view.substr(word_region) import_undefined_vars = utils.get_project_pref('import_undefined_vars', view=self.view) self.module_loader = ModuleLoader(self.view.file_name()) self.files = self.module_loader.get_file_list() words = [word_text] if cursor.empty() and import_undefined_vars: undef_vars = self.find_undefined_vars() if undef_vars: words = undef_vars for word in words: module = utils.best_fuzzy_match(self.files, word) self.view.run_command('require_insert_helper', {'args': { 'module': module, 'type': 'word' }})
def run(self, edit): """Called when the command is run.""" self.edit = edit cursor = self.view.sel()[0] word_region = self.view.word(cursor) word_text = self.view.substr(word_region) import_undefined_vars = utils.get_project_pref('import_undefined_vars', view=self.view) self.module_loader = ModuleLoader(self.view.file_name()) self.files = self.module_loader.get_file_list() words = [word_text] if cursor.empty() and import_undefined_vars: undef_vars = self.find_undefined_vars() if undef_vars: words = undef_vars for word in words: module = utils.best_fuzzy_match(self.files, word) self.view.run_command('require_insert_helper', { 'args': { 'module': module, 'type': 'word' } })
def get_module_info(module_path, view): """Get a dictionary with keys for the module_path and the module_name. In the case that the module is a node core module, the module_path and module_name are the same. """ aliased_to = utils.aliased(module_path, view=view) omit_extensions = utils.get_project_pref('omit_extensions', view=view) if aliased_to: module_name = aliased_to else: module_name = os.path.basename(module_path) module_name, extension = os.path.splitext(module_name) # When requiring an index.js file, rename the # var as the directory directly above if module_name == 'index' and extension == ".js": module_path = os.path.dirname(module_path) module_name = os.path.split(module_path)[-1] if module_name == '': current_file = view.file_module_name() directory = os.path.dirname(current_file) module_name = os.path.split(directory)[-1] # Depending on preferences, remove the file extension elif omit_extensions and module_path.endswith(tuple(omit_extensions)): module_path = os.path.splitext(module_path)[0] # Capitalize modules named with dashes # i.e. some-thing => SomeThing dash_index = module_name.find('-') while dash_index > 0: first = module_name[:dash_index].capitalize() second = module_name[dash_index + 1:].capitalize() module_name = '{fst}{snd}'.format(fst=first, snd=second) dash_index = module_name.find('-') # Fix paths for windows if os.sep != '/': module_path = module_path.replace(os.sep, '/') return { 'module_path': module_path, 'module_name': module_name }
def get_module_info(module_path, view): """Gets a dictionary with keys for the module_path and the module_name. In the case that the module is a node core module, the module_path and module_name are the same.""" aliased_to = utils.aliased(module_path, view=view) omit_extensions = utils.get_project_pref('omit_extensions', view=view) if aliased_to: module_name = aliased_to else: module_name = os.path.basename(module_path) module_name, extension = os.path.splitext(module_name) # When requiring an index.js file, rename the # var as the directory directly above if module_name == 'index' and extension == ".js": module_path = os.path.dirname(module_path) module_name = os.path.split(module_path)[-1] if module_name == '': current_file = view.file_module_name() directory = os.path.dirname(current_file) module_name = os.path.split(directory)[-1] # Depending on preferences, remove the file extension elif omit_extensions and module_path.endswith(tuple(omit_extensions)): module_path = os.path.splitext(module_path)[0] # Capitalize modules named with dashes # i.e. some-thing => SomeThing dash_index = module_name.find('-') while dash_index > 0: first = module_name[:dash_index].capitalize() second = module_name[dash_index + 1:].capitalize() module_name = '{fst}{snd}'.format(fst=first, snd=second) dash_index = module_name.find('-') # Fix paths for windows if os.sep != '/': module_path = module_path.replace(os.sep, '/') return { 'module_path': module_path, 'module_name': module_name }