@@ -13,134 +13,139 @@ import * as fs from 'fs-extra-promise';
1313import * as path from 'path' ;
1414import * as protocol from '../protocol' ;
1515import * as vscode from 'vscode' ;
16+ import * as dotnetTest from './dotnetTest'
1617
1718let channel = vscode . window . createOutputChannel ( '.NET' ) ;
1819
1920export default function registerCommands ( server : OmnisharpServer , extensionPath : string ) {
20- let d1 = vscode . commands . registerCommand ( 'o.restart' , ( ) => server . restart ( ) ) ;
21- let d2 = vscode . commands . registerCommand ( 'o.pickProjectAndStart' , ( ) => pickProjectAndStart ( server ) ) ;
22- let d3 = vscode . commands . registerCommand ( 'o.showOutput' , ( ) => server . getChannel ( ) . show ( vscode . ViewColumn . Three ) ) ;
23- let d4 = vscode . commands . registerCommand ( 'dotnet.restore' , ( ) => dotnetRestoreAllProjects ( server ) ) ;
24-
21+ let d1 = vscode . commands . registerCommand ( 'o.restart' , ( ) => server . restart ( ) ) ;
22+ let d2 = vscode . commands . registerCommand ( 'o.pickProjectAndStart' , ( ) => pickProjectAndStart ( server ) ) ;
23+ let d3 = vscode . commands . registerCommand ( 'o.showOutput' , ( ) => server . getChannel ( ) . show ( vscode . ViewColumn . Three ) ) ;
24+ let d4 = vscode . commands . registerCommand ( 'dotnet.restore' , ( ) => dotnetRestoreAllProjects ( server ) ) ;
25+
2526 // register empty handler for csharp.installDebugger
2627 // running the command activates the extension, which is all we need for installation to kickoff
2728 let d5 = vscode . commands . registerCommand ( 'csharp.downloadDebugger' , ( ) => { } ) ;
28-
29- return vscode . Disposable . from ( d1 , d2 , d3 , d4 , d5 ) ;
29+
30+ // register two commands for running and debugging xunit tests
31+ let d6 = dotnetTest . registerDotNetTestRunCommand ( server ) ;
32+ let d7 = dotnetTest . registerDotNetTestDebugCommand ( server ) ;
33+
34+ return vscode . Disposable . from ( d1 , d2 , d3 , d4 , d5 , d6 , d7 ) ;
3035}
3136
3237function pickProjectAndStart ( server : OmnisharpServer ) {
3338
34- return findLaunchTargets ( ) . then ( targets => {
35-
36- let currentPath = server . getSolutionPathOrFolder ( ) ;
37- if ( currentPath ) {
38- for ( let target of targets ) {
39- if ( target . target . fsPath === currentPath ) {
40- target . label = `\u2713 ${ target . label } ` ;
41- }
42- }
43- }
44-
45- return vscode . window . showQuickPick ( targets , {
46- matchOnDescription : true ,
47- placeHolder : `Select 1 of ${ targets . length } projects`
48- } ) . then ( target => {
49- if ( target ) {
50- return server . restart ( target . target . fsPath ) ;
51- }
52- } ) ;
53- } ) ;
39+ return findLaunchTargets ( ) . then ( targets => {
40+
41+ let currentPath = server . getSolutionPathOrFolder ( ) ;
42+ if ( currentPath ) {
43+ for ( let target of targets ) {
44+ if ( target . target . fsPath === currentPath ) {
45+ target . label = `\u2713 ${ target . label } ` ;
46+ }
47+ }
48+ }
49+
50+ return vscode . window . showQuickPick ( targets , {
51+ matchOnDescription : true ,
52+ placeHolder : `Select 1 of ${ targets . length } projects`
53+ } ) . then ( target => {
54+ if ( target ) {
55+ return server . restart ( target . target . fsPath ) ;
56+ }
57+ } ) ;
58+ } ) ;
5459}
5560
5661interface Command {
57- label : string ;
58- description : string ;
59- execute ( ) : Thenable < any > ;
62+ label : string ;
63+ description : string ;
64+ execute ( ) : Thenable < any > ;
6065}
6166
6267function projectsToCommands ( projects : protocol . DotNetProject [ ] ) : Promise < Command > [ ] {
63- return projects . map ( project => {
64- let projectDirectory = project . Path ;
65-
66- return fs . lstatAsync ( projectDirectory ) . then ( stats => {
67- if ( stats . isFile ( ) ) {
68- projectDirectory = path . dirname ( projectDirectory ) ;
69- }
70-
71- return {
72- label : `dotnet restore - (${ project . Name || path . basename ( project . Path ) } )` ,
73- description : projectDirectory ,
74- execute ( ) {
75- return runDotnetRestore ( projectDirectory ) ;
76- }
77- } ;
78- } ) ;
79- } ) ;
68+ return projects . map ( project => {
69+ let projectDirectory = project . Path ;
70+
71+ return fs . lstatAsync ( projectDirectory ) . then ( stats => {
72+ if ( stats . isFile ( ) ) {
73+ projectDirectory = path . dirname ( projectDirectory ) ;
74+ }
75+
76+ return {
77+ label : `dotnet restore - (${ project . Name || path . basename ( project . Path ) } )` ,
78+ description : projectDirectory ,
79+ execute ( ) {
80+ return runDotnetRestore ( projectDirectory ) ;
81+ }
82+ } ;
83+ } ) ;
84+ } ) ;
8085}
8186
8287export function dotnetRestoreAllProjects ( server : OmnisharpServer ) {
8388
84- if ( ! server . isRunning ( ) ) {
85- return Promise . reject ( 'OmniSharp server is not running.' ) ;
86- }
87-
88- return serverUtils . requestWorkspaceInformation ( server ) . then ( info => {
89-
90- if ( ! ( 'DotNet in info' ) || info . DotNet . Projects . length < 1 ) {
91- return Promise . reject ( "No .NET Core projects found" ) ;
92- }
93-
94- let commandPromises = projectsToCommands ( info . DotNet . Projects ) ;
95-
96- return Promise . all ( commandPromises ) . then ( commands => {
97- return vscode . window . showQuickPick ( commands ) ;
98- } ) . then ( command => {
99- if ( command ) {
100- return command . execute ( ) ;
101- }
102- } ) ;
103- } ) ;
89+ if ( ! server . isRunning ( ) ) {
90+ return Promise . reject ( 'OmniSharp server is not running.' ) ;
91+ }
92+
93+ return serverUtils . requestWorkspaceInformation ( server ) . then ( info => {
94+
95+ if ( ! ( 'DotNet in info' ) || info . DotNet . Projects . length < 1 ) {
96+ return Promise . reject ( "No .NET Core projects found" ) ;
97+ }
98+
99+ let commandPromises = projectsToCommands ( info . DotNet . Projects ) ;
100+
101+ return Promise . all ( commandPromises ) . then ( commands => {
102+ return vscode . window . showQuickPick ( commands ) ;
103+ } ) . then ( command => {
104+ if ( command ) {
105+ return command . execute ( ) ;
106+ }
107+ } ) ;
108+ } ) ;
104109}
105110
106111export function dotnetRestoreForProject ( server : OmnisharpServer , fileName : string ) {
107112
108- if ( ! server . isRunning ( ) ) {
109- return Promise . reject ( 'OmniSharp server is not running.' ) ;
110- }
111-
112- return serverUtils . requestWorkspaceInformation ( server ) . then ( info => {
113-
114- if ( ! ( 'DotNet in info' ) || info . DotNet . Projects . length < 1 ) {
115- return Promise . reject ( "No .NET Core projects found" ) ;
116- }
117-
118- let directory = path . dirname ( fileName ) ;
119-
120- for ( let project of info . DotNet . Projects ) {
121- if ( project . Path === directory ) {
122- return runDotnetRestore ( directory , fileName ) ;
123- }
124- }
125- } ) ;
113+ if ( ! server . isRunning ( ) ) {
114+ return Promise . reject ( 'OmniSharp server is not running.' ) ;
115+ }
116+
117+ return serverUtils . requestWorkspaceInformation ( server ) . then ( info => {
118+
119+ if ( ! ( 'DotNet in info' ) || info . DotNet . Projects . length < 1 ) {
120+ return Promise . reject ( "No .NET Core projects found" ) ;
121+ }
122+
123+ let directory = path . dirname ( fileName ) ;
124+
125+ for ( let project of info . DotNet . Projects ) {
126+ if ( project . Path === directory ) {
127+ return runDotnetRestore ( directory , fileName ) ;
128+ }
129+ }
130+ } ) ;
126131}
127132
128133function runDotnetRestore ( cwd : string , fileName ?: string ) {
129- return new Promise < cp . ChildProcess > ( ( resolve , reject ) => {
130- channel . clear ( ) ;
131- channel . show ( ) ;
132-
133- let cmd = 'dotnet restore' ;
134- if ( fileName ) {
135- cmd = `${ cmd } "${ fileName } "`
136- }
137-
138- return cp . exec ( cmd , { cwd : cwd , env : process . env } , ( err , stdout , stderr ) => {
139- channel . append ( stdout . toString ( ) ) ;
140- channel . append ( stderr . toString ( ) ) ;
141- if ( err ) {
142- channel . append ( 'ERROR: ' + err ) ;
143- }
144- } ) ;
145- } ) ;
134+ return new Promise < cp . ChildProcess > ( ( resolve , reject ) => {
135+ channel . clear ( ) ;
136+ channel . show ( ) ;
137+
138+ let cmd = 'dotnet restore' ;
139+ if ( fileName ) {
140+ cmd = `${ cmd } "${ fileName } "`
141+ }
142+
143+ return cp . exec ( cmd , { cwd : cwd , env : process . env } , ( err , stdout , stderr ) => {
144+ channel . append ( stdout . toString ( ) ) ;
145+ channel . append ( stderr . toString ( ) ) ;
146+ if ( err ) {
147+ channel . append ( 'ERROR: ' + err ) ;
148+ }
149+ } ) ;
150+ } ) ;
146151}
0 commit comments