Skip to content

Commit

Permalink
JumpToDependency: Support Sass. Fixes #45
Browse files Browse the repository at this point in the history
  • Loading branch information
Joel Kemp committed Dec 11, 2014
1 parent ed641b3 commit cdab878
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 20 deletions.
15 changes: 2 additions & 13 deletions Dependents.py
Original file line number Diff line number Diff line change
Expand Up @@ -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=''):
Expand All @@ -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):
Expand Down Expand Up @@ -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'
27 changes: 21 additions & 6 deletions JumpToDependency.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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 += '/'
Expand Down Expand Up @@ -57,30 +59,38 @@ 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):
# Is relative to the module
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)

Expand All @@ -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()
Expand Down Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions changelogs/2.1.0.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
New Feature
---

Jump to SASS dependents.
12 changes: 12 additions & 0 deletions is_sass_file.py
Original file line number Diff line number Diff line change
@@ -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'
3 changes: 2 additions & 1 deletion messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}

0 comments on commit cdab878

Please sign in to comment.