File tree Expand file tree Collapse file tree 3 files changed +55
-1
lines changed Expand file tree Collapse file tree 3 files changed +55
-1
lines changed Original file line number Diff line number Diff line change 212
212
}
213
213
},
214
214
"commands" : [
215
+ {
216
+ "command" : " go.debug.openVariableAsDoc" ,
217
+ "title" : " Go: Open in new Document"
218
+ },
215
219
{
216
220
"command" : " go.gopath" ,
217
221
"title" : " Go: Current GOPATH" ,
3490
3494
"when" : " debugType == 'go' && callStackItemType == 'stackFrame' || (callStackItemType == 'thread' && callStackItemStopped)"
3491
3495
}
3492
3496
],
3497
+ "debug/variables/context" : [
3498
+ {
3499
+ "command" : " go.debug.openVariableAsDoc" ,
3500
+ "when" : " debugType=='go'" ,
3501
+ "group" : " navigation"
3502
+ }
3503
+ ],
3493
3504
"editor/context" : [
3494
3505
{
3495
3506
"when" : " editorTextFocus && config.go.editorContextMenuCommands.toggleTestFile && resourceLangId == go" ,
3686
3697
}
3687
3698
]
3688
3699
}
3689
- }
3700
+ }
Original file line number Diff line number Diff line change
1
+ import * as vscode from 'vscode' ;
2
+
3
+ export function registerGoDebugCommands ( ctx : vscode . ExtensionContext ) {
4
+ ctx . subscriptions . push (
5
+ vscode . commands . registerCommand (
6
+ 'go.debug.openVariableAsDoc' ,
7
+ async ( args : any ) => {
8
+ const variable = args . variable ;
9
+
10
+ let raw = variable . value . trim ( ) ;
11
+ if (
12
+ ( raw . startsWith ( '"' ) && raw . endsWith ( '"' ) ) ||
13
+ ( raw . startsWith ( '`' ) && raw . endsWith ( '`' ) )
14
+ ) {
15
+ raw = raw . slice ( 1 , - 1 ) ;
16
+ }
17
+
18
+ let text : string ;
19
+ try {
20
+ text = JSON . parse ( `"${ raw . replace ( / " / g, '\\"' ) } "` ) ;
21
+ } catch {
22
+ text = raw
23
+ . replace ( / \\ r / g, '\r' )
24
+ . replace ( / \\ n / g, '\n' )
25
+ . replace ( / \\ t / g, '\t' )
26
+ . replace ( / \\ " / g, '"' )
27
+ . replace ( / \\ \\ / g, '\\' ) ;
28
+ }
29
+
30
+ const doc = await vscode . workspace . openTextDocument ( {
31
+ language : 'plaintext' ,
32
+ content : text
33
+ } ) ;
34
+
35
+ const editor = await vscode . window . showTextDocument ( doc ) ;
36
+
37
+ await vscode . commands . executeCommand ( 'workbench.action.editor.changeLanguageMode' ) ;
38
+ }
39
+ )
40
+ )
41
+ }
Original file line number Diff line number Diff line change @@ -34,6 +34,7 @@ import { resolveHomeDir } from './utils/pathUtils';
34
34
import { createRegisterCommand } from './commands' ;
35
35
import { GoExtensionContext } from './context' ;
36
36
import { spawn } from 'child_process' ;
37
+ import { registerGoDebugCommands } from './goDebugCommands' ;
37
38
38
39
let dlvDAPVersionChecked = false ;
39
40
@@ -45,6 +46,7 @@ export class GoDebugConfigurationProvider implements vscode.DebugConfigurationPr
45
46
const registerCommand = createRegisterCommand ( ctx , goCtx ) ;
46
47
registerCommand ( 'go.debug.pickProcess' , ( ) => pickProcess ) ;
47
48
registerCommand ( 'go.debug.pickGoProcess' , ( ) => pickGoProcess ) ;
49
+ registerGoDebugCommands ( ctx ) ;
48
50
}
49
51
50
52
constructor ( private defaultDebugAdapterType : string = 'go' ) { }
You can’t perform that action at this time.
0 commit comments