@@ -15,7 +15,7 @@ import * as path from 'path';
1515// The extension deactivate method is asynchronous, so we handle the disposables ourselves instead of using extensonContext.subscriptions.
1616let disposables : vscode . Disposable [ ] = [ ] ;
1717
18- export function activate ( ) {
18+ export function initialize ( ) {
1919 // Activate Process Picker Commands
2020 let attachItemsProvider = NativeAttachItemsProviderFactory . Get ( ) ;
2121 let attacher = new AttachPicker ( attachItemsProvider ) ;
@@ -37,13 +37,69 @@ export function activate() {
3737
3838 disposables . push ( vscode . window . onDidChangeActiveTextEditor ( onDidChangeActiveTextEditor ) ) ;
3939 onDidChangeActiveTextEditor ( vscode . window . activeTextEditor ) ;
40+
41+ // Activate Adapter Commands
42+ registerAdapterExecutableCommands ( ) ;
4043}
4144
42- export function deactivate ( ) : void {
45+ export function dispose ( ) : void {
4346 disposables . forEach ( d => d . dispose ( ) ) ;
4447}
4548
4649function onDidChangeActiveTextEditor ( editor : vscode . TextEditor ) : void {
4750 if ( util . getShowReloadPromptOnce ( ) && editor && editor . document . fileName . endsWith ( path . sep + "launch.json" ) )
4851 util . showReloadOrWaitPromptOnce ( ) ;
52+ }
53+
54+ // Registers adapterExecutableCommands for cppdbg and cppvsdbg. If it is not ready, it will prompt waiting for the download.
55+ //
56+ // Note: util.extensionContext.extensionPath is needed for the commands because VsCode does not support relative paths for adapterExecutableComand
57+ function registerAdapterExecutableCommands ( ) : void {
58+ disposables . push ( vscode . commands . registerCommand ( 'extension.cppdbgAdapterExecutableCommand' , ( ) => {
59+ return util . checkInstallLockFile ( ) . then ( ready => {
60+ if ( ready )
61+ {
62+ let command : string = path . join ( util . extensionContext . extensionPath , './debugAdapters/OpenDebugAD7' ) ;
63+
64+ // Windows has the exe in debugAdapters/bin.
65+ if ( os . platform ( ) === 'win32' )
66+ {
67+ command = path . join ( util . extensionContext . extensionPath , "./debugAdapters/bin/OpenDebugAD7.exe" ) ;
68+ }
69+
70+ return {
71+ command : command
72+ }
73+ }
74+ else {
75+ util . showReloadOrWaitPromptOnce ( ) ;
76+ // TODO: VsCode displays null return as "Cannot find executable 'null'". Fix if they have a way to not display their prompt.
77+ return null ;
78+ }
79+ } ) ;
80+ } ) ) ;
81+
82+ disposables . push ( vscode . commands . registerCommand ( 'extension.cppvsdbgAdapterExecutableCommand' , ( ) => {
83+ if ( os . platform ( ) != 'win32' )
84+ {
85+ vscode . window . showErrorMessage ( "Debugger type 'cppvsdbg' is not avaliable for non-Windows machines." ) ;
86+ return null ;
87+ }
88+ else {
89+ return util . checkInstallLockFile ( ) . then ( ready => {
90+ if ( ready )
91+ {
92+ return {
93+ command : path . join ( util . extensionContext . extensionPath , './debugAdapters/vsdbg/bin/vsdbg.exe' ) ,
94+ args : [ '--interpreter=vscode' ]
95+ }
96+ }
97+ else {
98+ util . showReloadOrWaitPromptOnce ( ) ;
99+ // TODO: VsCode displays null return as "Cannot find executable 'null'". Fix if they have a way to not display their prompt.
100+ return null ;
101+ }
102+ } ) ;
103+ }
104+ } ) ) ;
49105}
0 commit comments