Skip to content

Commit

Permalink
Merge pull request #49 from puremourning/go
Browse files Browse the repository at this point in the history
Go support using vscode-go
  • Loading branch information
mergify[bot] authored Jul 31, 2019
2 parents 77e250b + 553eb3c commit f8fc171
Show file tree
Hide file tree
Showing 7 changed files with 113 additions and 24 deletions.
28 changes: 28 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ on a best-efforts basis:

- Java (see caveats)
- C# (c-sharp) using dotnet core
- Go (requires separate installation of [Delve][])

## Languages known not to work

Expand Down Expand Up @@ -158,6 +159,7 @@ The debug adapters themselves have certain runtime dependencies:
| Bourne Shell | Experimental | `--all` or `--enable-bash` | vscode-bash-debug | Bash v?? |
| C# (dotnet core) | Experimental | `--force-enable-csharp` | netcoredbg | DotNet core |
| C# (mono) | Experimental | `--force-enable-csharp` | vscode-mono-debug | Mono |
| Go | Experimental | `--enable-go` | vscode-go | Go, [Delve][] |

For other languages, you'll need some other way to install the gadget.

Expand Down Expand Up @@ -579,6 +581,30 @@ Requires `install_gadget.py --force-enable-c-sharp`.
}
```

* Go

Requires:

* `install_gadget.py --enable-go`
* [Delve][delve-install] installed, e.g. `go get -u github.com/go-delve/delve/cmd/dlv`
* Delve to be in your PATH, or specify the `dlvToolPath` launch option

```json
{
"configurations": {
"run": {
"adapter": "vscode-go",
"configuration": {
"request": "launch",
"program": "${fileDirname}",
"mode": "debug",
"dlvToolPath": "$HOME/go/bin/dlv"
}
}
}
}
```

Also the mock debugger, but that isn't actually useful.

## Partially supported
Expand Down Expand Up @@ -610,3 +636,5 @@ Copyright © 2018 Ben Jackson
[gitter]: https://gitter.im/vimspector/Lobby?utm_source=share-link&utm_medium=link&utm_campaign=share-link
[java-debug-server]: https://github.com/Microsoft/java-debug
[website]: https://puremourning.github.io/vimspector-web/
[delve]: https://github.com/go-delve/delve
[delve-install]: https://github.com/go-delve/delve/tree/master/Documentation/installation
40 changes: 31 additions & 9 deletions install_gadget.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@
'vscode-cpptools': {
'language': 'c',
'download': {
'url': ( 'https://github.com/Microsoft/vscode-cpptools/releases/download/'
'${version}/${file_name}' ),
'url': 'https://github.com/Microsoft/vscode-cpptools/releases/download/'
'${version}/${file_name}',
},
'do': lambda name, root: InstallCppTools( name, root ),
'all': {
Expand Down Expand Up @@ -80,8 +80,8 @@
'vscode-python': {
'language': 'python',
'download': {
'url': ( 'https://github.com/Microsoft/vscode-python/releases/download/'
'${version}/${file_name}' ),
'url': 'https://github.com/Microsoft/vscode-python/releases/download/'
'${version}/${file_name}',
},
'all': {
'version': '2019.5.17059',
Expand Down Expand Up @@ -111,8 +111,8 @@
'language': 'csharp',
'enabled': False,
'download': {
'url': ( 'https://github.com/Samsung/netcoredbg/releases/download/latest/'
'${file_name}' ),
'url': 'https://github.com/Samsung/netcoredbg/releases/download/latest/'
'${file_name}',
'format': 'tar',
},
'all': {
Expand Down Expand Up @@ -175,15 +175,37 @@
'vscode-bash-debug': {
'language': 'bash',
'download': {
'url': ( 'https://github.com/rogalmic/vscode-bash-debug/releases/'
'download/${version}/${file_name}' ),
'url': 'https://github.com/rogalmic/vscode-bash-debug/releases/'
'download/${version}/${file_name}',
},
'all': {
'file_name': 'bash-debug-0.3.5.vsix',
'version': 'v0.3.5',
'checksum': '',
}
}
},
'vscode-go': {
'language': 'go',
'download': {
'url': 'https://github.com/microsoft/vscode-go/releases/download/'
'${version}/${file_name}'
},
'all': {
'version': '0.11.4',
'file_name': 'Go-0.11.4.vsix',
'checksum':
'ff7d7b944da5448974cb3a0086f4a2fd48e2086742d9c013d6964283d416027e'
},
'adapters': {
'vscode-go': {
'name': 'delve',
'command': [
'node',
'${gadgetDir}/vscode-go/out/src/debugAdapter/goDebug.js'
],
},
},
},
}


Expand Down
25 changes: 21 additions & 4 deletions python3/vimspector/breakpoints.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,12 +187,23 @@ def SetBreakpointsHandler( self, handler ):
self._breakpoints_handler = handler


def SendBreakpoints( self ):
def SendBreakpoints( self, doneHandler = None ):
assert self._breakpoints_handler is not None

# Clear any existing breakpoints prior to sending new ones
self._breakpoints_handler.ClearBreakpoints()

awaiting = 0

def response_handler( source, msg ):
if msg:
self._breakpoints_handler.AddBreakpoints( source, msg )
nonlocal awaiting
awaiting = awaiting - 1
if awaiting == 0 and doneHandler:
doneHandler()


for file_name, line_breakpoints in self._line_breakpoints.items():
breakpoints = []
for bp in line_breakpoints:
Expand All @@ -211,8 +222,9 @@ def SendBreakpoints( self ):
'path': file_name,
}

awaiting = awaiting + 1
self._connection.DoRequest(
lambda msg: self._breakpoints_handler.AddBreakpoints( source, msg ),
lambda msg: response_handler( source, msg ),
{
'command': 'setBreakpoints',
'arguments': {
Expand All @@ -224,8 +236,9 @@ def SendBreakpoints( self ):
)

if self._server_capabilities.get( 'supportsFunctionBreakpoints' ):
awaiting = awaiting + 1
self._connection.DoRequest(
lambda msg: self._breakpoints_handler.AddBreakpoints( None, msg ),
lambda msg: response_handler( None, msg ),
{
'command': 'setFunctionBreakpoints',
'arguments': {
Expand All @@ -241,14 +254,18 @@ def SendBreakpoints( self ):
self._SetUpExceptionBreakpoints()

if self._exceptionBreakpoints:
awaiting = awaiting + 1
self._connection.DoRequest(
None, # There is nothing on the response to this
lambda msg: response_handler( None, None ),
{
'command': 'setExceptionBreakpoints',
'arguments': self._exceptionBreakpoints
}
)

if awaiting == 0 and doneHandler:
doneHandler()


def _SetUpExceptionBreakpoints( self ):
exceptionBreakpointFilters = self._server_capabilities.get(
Expand Down
23 changes: 12 additions & 11 deletions python3/vimspector/debug_session.py
Original file line number Diff line number Diff line change
Expand Up @@ -683,18 +683,19 @@ def OnEvent_capabilities( self, msg ):


def OnEvent_initialized( self, message ):
def onBreakpointsDone():
if self._server_capabilities.get( 'supportsConfigurationDoneRequest' ):
self._connection.DoRequest(
lambda msg: self._OnInitializeComplete(),
{
'command': 'configurationDone',
}
)
else:
self._OnInitializeComplete()

self._codeView.ClearBreakpoints()
self._breakpoints.SendBreakpoints()

if self._server_capabilities.get( 'supportsConfigurationDoneRequest' ):
self._connection.DoRequest(
lambda msg: self._OnInitializeComplete(),
{
'command': 'configurationDone',
}
)
else:
self._OnInitializeComplete()
self._breakpoints.SendBreakpoints( onBreakpointsDone )

def OnEvent_thread( self, message ):
self._stackTraceView.OnThreadEvent( message[ 'body' ] )
Expand Down
1 change: 1 addition & 0 deletions support/test/go/hello_world/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
hello_world
14 changes: 14 additions & 0 deletions support/test/go/hello_world/.vimspector.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"configurations": {
"run": {
"adapter": "vscode-go",
"configuration": {
"request": "launch",
"program": "${workspaceRoot}/hello-world.go",
"mode": "debug",
"dlvToolPath": "$HOME/go/bin/dlv",
"trace": true
}
}
}
}
6 changes: 6 additions & 0 deletions support/test/go/hello_world/hello-world.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package main
import "fmt"
func main() {
var v = "test"
fmt.Println("hello world: " + v)
}

0 comments on commit f8fc171

Please sign in to comment.