diff --git a/README.md b/README.md index 599842f..6a9d8f3 100644 --- a/README.md +++ b/README.md @@ -88,6 +88,7 @@ on a best-efforts basis: - C# (c-sharp) using dotnet core - Go (requires separate installation of [Delve][]) - Node.js (requires node <12 for installation) +- Anything running in chrome (i.e. javascript). ## Languages known not to work @@ -162,6 +163,7 @@ The debug adapters themselves have certain runtime dependencies: | C# (mono) | Experimental | `--force-enable-csharp` | vscode-mono-debug | Mono | | Go | Experimental | `--enable-go` | vscode-go | Go, [Delve][] | | Node.js | Experimental | `--force-enable-node` | vscode-node-debug2 | 6 < Node < 12, Npm | +| Javascript | Experimental | `--force-enable-chrome` | debugger-for-chrome | Chrome | For other languages, you'll need some other way to install the gadget. @@ -615,9 +617,9 @@ Requires: * For installation, a Node.js environemt that is < node 12. I believe this is an incompatibility with gulp. Advice, use [nvm][] with `nvm install --lts 10; nvm use --lts 10; ./install_gadget.py --force-enable-node ...` - * Options described here: https://code.visualstudio.com/docs/nodejs/nodejs-debugging +* Example: `support/test/node/simple` ```json { @@ -637,6 +639,31 @@ Requires: } ``` +* Chrome + +This uses the chrome debugger, see +https://marketplace.visualstudio.com/items?itemName=msjsdiag.debugger-for-chrome. + +It allows you to debug scripts running inside chrome from within Vim. + +* `./install_gadget.py --force-enable-chrome` +* Example: `support/test/chrome` + +```json +{ + "configurations": { + "launch": { + "adapter": "chrome", + "configuration": { + "request": "launch", + "url": "http://localhost:1234/", + "webRoot": "${workspaceRoot}/www" + } + } + } +} +``` + Also the mock debugger, but that isn't actually useful. ## Partially supported diff --git a/install_gadget.py b/install_gadget.py index 1e47501..9603a26 100755 --- a/install_gadget.py +++ b/install_gadget.py @@ -225,6 +225,32 @@ GADGETS = { }, }, }, + 'debugger-for-chrome': { + 'language': 'typescript', + 'enabled': False, + 'download': { + 'url': 'https://marketplace.visualstudio.com/_apis/public/gallery/' + 'publishers/msjsdiag/vsextensions/' + 'debugger-for-chrome/${version}/vspackage', + 'target': 'msjsdiag.debugger-for-chrome-4.12.0.tar.gz', + 'format': 'tar', + }, + 'all': { + 'version': '4.12.0', + 'file_name': 'msjsdiag.debugger-for-chrome-4.12.0.vsix', + 'checksum': '' + }, + 'adapters': { + 'chrome': { + 'name': 'debugger-for-chrome', + 'type': 'chrome', + 'command': [ + 'node', + '${gadgetDir}/debugger-for-chrome/out/src/chromeDebug.js' + ], + }, + }, + }, } diff --git a/python3/vimspector/code.py b/python3/vimspector/code.py index 2e60a0e..f28a1b5 100644 --- a/python3/vimspector/code.py +++ b/python3/vimspector/code.py @@ -73,7 +73,15 @@ class CodeView( object ): return False # SIC: column is 0-based, line is 1-based in vim. Why? Nobody knows. - self._window.cursor = ( frame[ 'line' ], frame[ 'column' ] - 1 ) + try: + self._window.cursor = ( frame[ 'line' ], frame[ 'column' ] - 1 ) + except vim.error: + self._logger.exception( "Unable to jump to %s:%s in %s, maybe the file " + "doesn't exist", + frame[ 'line' ], + frame[ 'column' ], + frame[ 'source' ][ 'path' ] ) + return False self._signs[ 'vimspectorPC' ] = self._next_sign_id self._next_sign_id += 1 diff --git a/python3/vimspector/stack_trace.py b/python3/vimspector/stack_trace.py index 9849131..d68e6e9 100644 --- a/python3/vimspector/stack_trace.py +++ b/python3/vimspector/stack_trace.py @@ -162,8 +162,9 @@ class StackTraceView( object ): self._LoadStackTrace( thread, False ) def _JumpToFrame( self, frame ): - self._currentFrame = frame - return self._session.SetCurrentFrame( self._currentFrame ) + if 'line' in frame and frame[ 'line' ]: + self._currentFrame = frame + return self._session.SetCurrentFrame( self._currentFrame ) def OnStopped( self, event ): if 'threadId' in event: @@ -226,10 +227,19 @@ class StackTraceView( object ): if 'name' not in source: source[ 'name' ] = os.path.basename( source[ 'path' ] ) - line = utils.AppendToBuffer( - self._buf, - ' {0}: {1}@{2}:{3}'.format( frame[ 'id' ], - frame[ 'name' ], - source[ 'name' ], - frame[ 'line' ] ) ) + if frame.get( 'presentationHint' ) == 'label': + # Sigh. FOr some reason, it's OK for debug adapters to completely ignore + # the protocol; it seems that the chrome adapter sets 'label' and + # doesn't set 'line' + line = utils.AppendToBuffer( + self._buf, + ' {0}: {1}'.format( frame[ 'id' ], frame[ 'name' ] ) ) + else: + line = utils.AppendToBuffer( + self._buf, + ' {0}: {1}@{2}:{3}'.format( frame[ 'id' ], + frame[ 'name' ], + source[ 'name' ], + frame[ 'line' ] ) ) + self._line_to_frame[ line ] = frame diff --git a/python3/vimspector/variables.py b/python3/vimspector/variables.py index 73ceb1c..d9882c8 100644 --- a/python3/vimspector/variables.py +++ b/python3/vimspector/variables.py @@ -116,6 +116,8 @@ class VariablesView( object ): elif not scope.get( 'expensive' ): # Expand any non-expensive scope unless manually collapsed scope[ '_expanded' ] = True + else: + scope[ '_expanded' ] = False self._scopes.append( scope ) if scope[ '_expanded' ]: diff --git a/support/test/chrome/.tern-project b/support/test/chrome/.tern-project new file mode 100644 index 0000000..e968b1f --- /dev/null +++ b/support/test/chrome/.tern-project @@ -0,0 +1,5 @@ +{ + "plugins": { + "browser": {} + } +} diff --git a/support/test/chrome/.vimspector.json b/support/test/chrome/.vimspector.json new file mode 100644 index 0000000..41d8a3e --- /dev/null +++ b/support/test/chrome/.vimspector.json @@ -0,0 +1,12 @@ +{ + "configurations": { + "launch": { + "adapter": "chrome", + "configuration": { + "request": "launch", + "url": "http://localhost:1234/", + "webRoot": "${workspaceRoot}/www" + } + } + } +} diff --git a/support/test/chrome/www/index.html b/support/test/chrome/www/index.html new file mode 100644 index 0000000..637a46d --- /dev/null +++ b/support/test/chrome/www/index.html @@ -0,0 +1,24 @@ + + +
+ + + + + + + +