diff --git a/Dependents.py b/Dependents.py index 589d4aa8..8c1a6e68 100644 --- a/Dependents.py +++ b/Dependents.py @@ -9,6 +9,7 @@ from .node_dependents import get_dependents from .project_settings import get_project_settings from .show_error import show_error +from .is_sass_file import is_sass_file class DependentsCommand(sublime_plugin.WindowCommand): def run(self, modifier=''): @@ -35,12 +36,11 @@ def run(self, modifier=''): # The part of the path before the root self.view.path = base_path self.view.modifier = modifier - self.view.isSassFile = isSassFile(self.view.filename) # All subsequent actions will be about the sass_root so just # switch the root to reduce the redundant checking if we should # use root or sass_root - if self.view.isSassFile: + if is_sass_file(self.view.filename): self.window.root = self.window.sass_root if not met(self.view.path): @@ -155,14 +155,3 @@ def open(): def cant_find_file(): show_error('Can\'t find that file') - -def isSassFile(filename): - """ - Whether or not the given filename is a Sass file - """ - - extension = os.path.splitext(filename)[1] - print('ext: ', extension) - print('filename: ', filename) - - return extension == '.scss' or extension == '.sass' diff --git a/JumpToDependency.py b/JumpToDependency.py index fcfac66e..dde1d428 100644 --- a/JumpToDependency.py +++ b/JumpToDependency.py @@ -11,6 +11,7 @@ from .node_dependents import alias_lookup from .project_settings import get_project_settings from .show_error import show_error +from .is_sass_file import is_sass_file class JumpToDependencyCommand(sublime_plugin.WindowCommand): def run(self): @@ -19,6 +20,7 @@ def run(self): settings = get_project_settings(base_path) self.window.root = settings['root'] + self.window.sass_root = settings['sass_root'] if self.window.root[-1] != '/': self.window.root += '/' @@ -57,22 +59,30 @@ def run(self): module = self.view.substr(region).strip() module = re.sub('[\'",]', '', module) + print('JumpToDependency: Extracted modulepath: ', module) module = self.handleRelativePaths(module) # Lookup the module name, if aliased if self.window.config: result = self.aliasLookup(module, self.window.config) - print('Lookup Result:', result) + print('JumpToDependency: Lookup Result:', result) if result: module = result extension = os.path.splitext(module)[1] + print('JumpToDependency: Extension found: ', extension) # Use the current file's extension if not supplied if not extension: extension = os.path.splitext(self.view.filename)[1] + module_with_extension = module + extension + else: + module_with_extension = module - file_to_open = self.get_absolute_path(module + extension) + print('JumpToDependency: Before abs path resolution: ', module_with_extension) + + file_to_open = self.get_absolute_path(module_with_extension) + print('JumpToDependency: After abs path resolution: ', file_to_open) # Our guess at the extension failed if not os.path.isfile(file_to_open): @@ -80,7 +90,7 @@ def run(self): actual_file = find_file_like(module) if actual_file: extension = os.path.splitext(actual_file)[1] - file_to_open = self.get_absolute_path(module + extension) + file_to_open = self.get_absolute_path(module_with_extension) self.open_file(file_to_open) @@ -90,7 +100,7 @@ def open_file(self, filename): if the file cannot be found """ - print('Opening: ', filename) + print('JumpToDependency: Opening: ', filename) if not os.path.isfile(filename): cant_find_file() @@ -143,11 +153,16 @@ def get_absolute_path(self, module): """ filename = '' + root = self.window.root + + if is_sass_file(self.view.filename): + root = self.window.sass_root + # If it's an absolute path already, it was probably a module that uses plugin loader if self.view.path not in module: filename += self.view.path - if self.window.root not in module and self.view.path != self.window.root: - filename += self.window.root + if root not in module and self.view.path != root: + filename += root filename += module return filename diff --git a/changelogs/2.1.0.txt b/changelogs/2.1.0.txt new file mode 100644 index 00000000..ad03ddc2 --- /dev/null +++ b/changelogs/2.1.0.txt @@ -0,0 +1,4 @@ +New Feature +--- + +Jump to SASS dependents. diff --git a/is_sass_file.py b/is_sass_file.py new file mode 100644 index 00000000..161c5fbb --- /dev/null +++ b/is_sass_file.py @@ -0,0 +1,12 @@ +import os + +def is_sass_file(filename): + """ + Whether or not the given filename is a Sass file + """ + + extension = os.path.splitext(filename)[1] + print('ext: ', extension) + print('filename: ', filename) + + return extension == '.scss' or extension == '.sass' diff --git a/messages.json b/messages.json index 46f10e0d..65024a8a 100644 --- a/messages.json +++ b/messages.json @@ -25,5 +25,6 @@ "2.0.1": "changelogs/2.0.1.txt", "2.0.2": "changelogs/2.0.2.txt", "2.0.3": "changelogs/2.0.3.txt", - "2.0.4": "changelogs/2.0.4.txt" + "2.0.4": "changelogs/2.0.4.txt", + "2.1.0": "changelogs/2.1.0.txt" }