Skip to content

Commit

Permalink
Merge pull request #104 from varp/master
Browse files Browse the repository at this point in the history
feat: new implementation for NodeTextCommand.get_working_dir()
  • Loading branch information
varp authored Apr 23, 2020
2 parents 97d9974 + 5551750 commit 46f9973
Showing 2 changed files with 22 additions and 15 deletions.
35 changes: 21 additions & 14 deletions lib/nodejs_base.py
Original file line number Diff line number Diff line change
@@ -138,24 +138,19 @@ def active_view(self):

def _active_file_name(self):
view = self.active_view()
view_file_name = None
if view and view.file_name() and len(view.file_name()) > 0:
return view.file_name()
view_file_name = view.file_name()

debug('NodeWindowCommand: _active_file_name: view_file_name', view_file_name)
return view_file_name

def is_enabled(self):
return True # A better test should be made. Fx. is this a js file?
return False

def get_file_name(self):
return ''

# If there is a file in the active view use that file's directory to
# search for the Git root. Otherwise, use the only folder that is
# open.
def get_working_dir(self):
file_name = self._active_file_name()
if file_name:
return os.path.dirname(file_name)
else:
return self.window.folders()[0]

def get_window(self):
return self.window
@@ -189,9 +184,6 @@ def is_enabled(self):
def get_file_name(self):
return os.path.basename(self.view.file_name())

def get_working_dir(self):
return os.path.dirname(self.view.file_name())

def get_window(self):
# Fun discovery: if you switch tabs while a command is working,
# self.view.window() is None. (Admittedly this is a consequence
@@ -203,3 +195,18 @@ def get_window(self):
# the case of the quick panel.
# So, this is not necessarily ideal, but it does work.
return self.view.window() or sublime.active_window()


# If there is a file in the active view use that file's directory to
# search for the Git root. Otherwise, use the only folder that is
# open.
def get_working_dir(self):
file_name = self._active_file_name()
dir_name = None
if file_name:
dir_name = os.path.dirname(file_name)
else:
dir_name = self.get_window().folders()[0]

debug('NodeWindowCommand: get_working_dir: file_name', dir_name)
return dir_name
2 changes: 1 addition & 1 deletion lib/nodejs_constants.py
Original file line number Diff line number Diff line change
@@ -3,7 +3,7 @@
# when sublime loads a plugin it's cd'd into the plugin directory. Thus
# __file__ is useless for my purposes. What I want is "Packages/Git", but
# allowing for the possibility that someone has renamed the file.
PLUGIN_VERSION = '2.0.0'
PLUGIN_VERSION = '2.0.5'

PLUGIN_PATH = PLUGIN_DIRECTORY = os.path.split(os.path.dirname(__file__))[0]
PLUGIN_LIB_DIR = os.path.join(PLUGIN_PATH, "lib")

0 comments on commit 46f9973

Please sign in to comment.