Skip to content

Commit

Permalink
Merge pull request #85 from varp/master
Browse files Browse the repository at this point in the history
Bringing new functionality
  • Loading branch information
varp authored Jan 9, 2018
2 parents 1ebcb91 + 524a2e1 commit 0b5e683
Show file tree
Hide file tree
Showing 8 changed files with 36 additions and 12 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ env:
- NVM_SYMLINK_CURRENT=true
- PACKAGE="Nodejs" # Package name
- SUBLIME_TEXT_VERSION="3"
- PLUGIN_VERSION="2.0.3"
# use UNITTESTING_TAG to specific tag of UnitTesting
# - UNITTESTING_TAG="master"

branches:
only:
- master
- kill-only-node-started-by-plugin

# mutliple os matrix
# https://docs.travis-ci.com/user/multi-os/#Python-example-(unsupported-languages)
Expand Down
4 changes: 2 additions & 2 deletions appveyor.yml
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
environment:
global:
PACKAGE: "Nodejs"
PLUGIN_VERSION: "2.0.3"
SUBLIME_TEXT_VERSION : "3"

matrix:
- nodejs_version: "6"
- nodejs_version: "8"


branches:
only:
- master
- kill-only-node-started-by-plugin

install:
- ps: Install-Product node $env:nodejs_version
Expand All @@ -24,6 +23,7 @@ build: off
test_script:
- node --version
- npm --version
- ps: New-Item c:\st\data\packages\nodejs\.debug_plugin -type file -force
- ps: .\appveyor.ps1 "run_tests" -coverage -verbose

on_failure:
Expand Down
14 changes: 14 additions & 0 deletions lib/nodejs_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ class NodeCommand(sublime_plugin.TextCommand):

def run_command(self, command, callback=None, show_status=True,
filter_empty_args=True, **kwargs):

shell = False

if filter_empty_args:
command = [arg for arg in command if arg]

Expand All @@ -42,6 +45,17 @@ def run_command(self, command, callback=None, show_status=True,
if not callback:
callback = self.generic_done

if os.name == 'nt':
shell = True
# doing exception for debugger commands to be able
# get PID of node.exe on Windows not cmd.exe
debug("NodeCommand: run_command: class name", self.__class__.__name__)
if self.__class__.__name__.lower().find("drun") != -1:
shell = False

kwargs['shell'] = shell
debug("NodeCommand: run_command: kwargs", kwargs)

thread = CommandThread(command, callback, **kwargs)
thread.start()

Expand Down
15 changes: 9 additions & 6 deletions lib/nodejs_command_thread.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def run_os_command(cmd):
class CommandThread(threading.Thread):

def __init__(self, command, on_done, working_dir="",
fallback_encoding="", env={}, write_pid=False):
fallback_encoding="", env={}, shell=False):

threading.Thread.__init__(self)
self.command = command
Expand All @@ -70,6 +70,7 @@ def __init__(self, command, on_done, working_dir="",
self.fallback_encoding = fallback_encoding
self.env = os.environ.copy()
self.env.update(env)
self.shell = shell

self.pid_file_name = '.debugger.pid'

Expand All @@ -81,6 +82,7 @@ def __init__(self, command, on_done, working_dir="",
def _write_pid(self):
with open(os.path.join(PLUGIN_PATH, self.pid_file_name), 'w') as f:
f.write(str(self.proc.pid))
debug("_write_pid: debugger pid:", str(self.proc.pid))

def _read_pid(self):
with open(os.path.join(PLUGIN_PATH, self.pid_file_name), 'r') as f:
Expand All @@ -94,9 +96,10 @@ def _kill_debugger(self):

try:
p = psutil.Process(int(debugger_pid))
debug("_kill_debugger: process:", p)
p.kill()
debug('_kill_node_processes', 'after call')
except psutil.NoSuchProcess:
except psutil.NoSuchProcess as e:
debug("_kill_debugger: NoSuchProcess exception is occurred", e)
return

def run(self):
Expand All @@ -106,17 +109,17 @@ def run(self):

# Per http://bugs.python.org/issue8557 shell=True is required to
# get $PATH on Windows. Yay portable code.
shell = os.name == 'nt'
debug("CommandThread: run: self.shell", self.shell)
if self.working_dir != "":
os.chdir(self.working_dir)

self.proc = subprocess.Popen(self.command,
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT,
shell=shell,
shell=self.shell,
universal_newlines=False,
env=self.env)

debug("CommandThread: run: self.proc.pid", self.proc.pid)

try:
output = self.proc.communicate(timeout=5)[0].decode()
Expand Down
2 changes: 1 addition & 1 deletion lib/nodejs_nvm.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import shellenv

from .nodejs_debug import debug
from .nodejs_command_thread import run_os_command


class Nvm(object):
"""
Expand Down
3 changes: 2 additions & 1 deletion messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@
"1.5.5": "messages/1.5.5.txt",
"1.5.6": "messages/1.5.6.txt",
"2.0.0": "messages/2.0.0.txt",
"2.0.2": "messages/2.0.2.txt"
"2.0.2": "messages/2.0.2.txt",
"2.0.3": "messages/2.0.3.txt",
}
6 changes: 6 additions & 0 deletions messages/2.0.3.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Version 2.0.3
-------------
This is a new release version

* Fix. Kill only Nodejs process started by the plugin not all Nodejs processes
in OS. Now works on Windows platform.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "sublime-nodejs",
"version": "2.0.2",
"version": "2.0.3",
"description": "NPM Support file for the Sublime Text 3 Nodejs Plugin",
"dependencies": {
"commander": "^2.9.0",
Expand Down

0 comments on commit 0b5e683

Please sign in to comment.