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 212212 }
213213 },
214214 "commands" : [
215+ {
216+ "command" : " go.debug.openVariableAsDoc" ,
217+ "title" : " Go: Open in new Document"
218+ },
215219 {
216220 "command" : " go.gopath" ,
217221 "title" : " Go: Current GOPATH" ,
34903494 "when" : " debugType == 'go' && callStackItemType == 'stackFrame' || (callStackItemType == 'thread' && callStackItemStopped)"
34913495 }
34923496 ],
3497+ "debug/variables/context" : [
3498+ {
3499+ "command" : " go.debug.openVariableAsDoc" ,
3500+ "when" : " debugType=='go'" ,
3501+ "group" : " navigation"
3502+ }
3503+ ],
34933504 "editor/context" : [
34943505 {
34953506 "when" : " editorTextFocus && config.go.editorContextMenuCommands.toggleTestFile && resourceLangId == go" ,
36863697 }
36873698 ]
36883699 }
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';
3434import { createRegisterCommand } from './commands' ;
3535import { GoExtensionContext } from './context' ;
3636import { spawn } from 'child_process' ;
37+ import { registerGoDebugCommands } from './goDebugCommands' ;
3738
3839let dlvDAPVersionChecked = false ;
3940
@@ -45,6 +46,7 @@ export class GoDebugConfigurationProvider implements vscode.DebugConfigurationPr
4546 const registerCommand = createRegisterCommand ( ctx , goCtx ) ;
4647 registerCommand ( 'go.debug.pickProcess' , ( ) => pickProcess ) ;
4748 registerCommand ( 'go.debug.pickGoProcess' , ( ) => pickGoProcess ) ;
49+ registerGoDebugCommands ( ctx ) ;
4850 }
4951
5052 constructor ( private defaultDebugAdapterType : string = 'go' ) { }
You can’t perform that action at this time.
0 commit comments