@@ -9,7 +9,6 @@ import {OmnisharpServer} from '../omnisharpServer';
9
9
import * as serverUtils from '../omnisharpUtils' ;
10
10
import findLaunchTargets from '../launchTargetFinder' ;
11
11
import { runInTerminal } from 'run-in-terminal' ;
12
- import * as fs from 'fs-extra-promise' ;
13
12
import * as path from 'path' ;
14
13
import * as vscode from 'vscode' ;
15
14
@@ -18,17 +17,14 @@ const isWindows = process.platform === 'win32';
18
17
export default function registerCommands ( server : OmnisharpServer , extensionPath : string ) {
19
18
let d1 = vscode . commands . registerCommand ( 'o.restart' , ( ) => server . restart ( ) ) ;
20
19
let d2 = vscode . commands . registerCommand ( 'o.pickProjectAndStart' , ( ) => pickProjectAndStart ( server ) ) ;
21
- let d3 = vscode . commands . registerCommand ( 'o.restore' , ( ) => dnxRestoreForAll ( server ) ) ;
22
- let d4 = vscode . commands . registerCommand ( 'o.execute' , ( ) => dnxExecuteCommand ( server ) ) ;
23
- let d5 = vscode . commands . registerCommand ( 'o.execute-last-command' , ( ) => dnxExecuteLastCommand ( server ) ) ;
24
- let d6 = vscode . commands . registerCommand ( 'o.showOutput' , ( ) => server . getChannel ( ) . show ( vscode . ViewColumn . Three ) ) ;
25
- let d7 = vscode . commands . registerCommand ( 'dotnet.restore' , ( ) => dotnetRestore ( server ) ) ;
20
+ let d3 = vscode . commands . registerCommand ( 'o.showOutput' , ( ) => server . getChannel ( ) . show ( vscode . ViewColumn . Three ) ) ;
21
+ let d4 = vscode . commands . registerCommand ( 'dotnet.restore' , ( ) => dotnetRestoreAllProjects ( server ) ) ;
26
22
27
23
// register empty handler for csharp.installDebugger
28
24
// running the command activates the extension, which is all we need for installation to kickoff
29
- let d8 = vscode . commands . registerCommand ( 'csharp.downloadDebugger' , ( ) => { } ) ;
25
+ let d5 = vscode . commands . registerCommand ( 'csharp.downloadDebugger' , ( ) => { } ) ;
30
26
31
- return vscode . Disposable . from ( d1 , d2 , d3 , d4 , d5 , d6 , d7 , d8 ) ;
27
+ return vscode . Disposable . from ( d1 , d2 , d3 , d4 , d5 ) ;
32
28
}
33
29
34
30
function pickProjectAndStart ( server : OmnisharpServer ) {
@@ -61,17 +57,7 @@ interface Command {
61
57
execute ( ) : Thenable < any > ;
62
58
}
63
59
64
- let lastCommand : Command ;
65
-
66
- function dnxExecuteLastCommand ( server : OmnisharpServer ) {
67
- if ( lastCommand ) {
68
- lastCommand . execute ( ) ;
69
- } else {
70
- dnxExecuteCommand ( server ) ;
71
- }
72
- }
73
-
74
- function dnxExecuteCommand ( server : OmnisharpServer ) {
60
+ export function dotnetRestoreAllProjects ( server : OmnisharpServer ) {
75
61
76
62
if ( ! server . isRunning ( ) ) {
77
63
return Promise . reject ( 'OmniSharp server is not running.' ) ;
@@ -80,38 +66,20 @@ function dnxExecuteCommand(server: OmnisharpServer) {
80
66
return serverUtils . requestWorkspaceInformation ( server ) . then ( info => {
81
67
82
68
let commands : Command [ ] = [ ] ;
83
-
84
- info . Dnx . Projects . forEach ( project => {
85
- Object . keys ( project . Commands ) . forEach ( key => {
86
-
87
- commands . push ( {
88
- label : `dnx ${ key } - (${ project . Name || path . basename ( project . Path ) } )` ,
89
- description : path . dirname ( project . Path ) ,
90
- execute ( ) {
91
- lastCommand = this ;
92
-
93
- let command = path . join ( info . Dnx . RuntimePath , 'bin/dnx' ) ;
94
- let args = [ key ] ;
95
-
96
- // dnx-beta[1-6] needs a leading dot, like 'dnx . run'
97
- if ( / - b e t a [ 1 - 6 ] / . test ( info . Dnx . RuntimePath ) ) {
98
- args . unshift ( '.' ) ;
99
- }
100
-
101
- if ( isWindows ) {
102
- command += '.exe' ;
103
- }
104
-
105
- return runInTerminal ( command , args , {
106
- cwd : path . dirname ( project . Path ) ,
107
- env : {
108
- // KRE_COMPILATION_SERVER_PORT: workspace.DesignTimeHostPort
109
- }
110
- } ) ;
111
- }
112
- } ) ;
113
- } ) ;
114
- } ) ;
69
+
70
+ if ( 'DotNet' in info && info . DotNet . Projects . length > 0 ) {
71
+ for ( let project of info . DotNet . Projects ) {
72
+ commands . push ( {
73
+ label : `dotnet restor - (${ project . Name || path . basename ( project . Path ) } )` ,
74
+ description : path . dirname ( project . Path ) ,
75
+ execute ( ) {
76
+ return runInTerminal ( 'dotnet' , [ 'restore' ] , {
77
+ cwd : path . dirname ( project . Path )
78
+ } ) ;
79
+ }
80
+ } ) ;
81
+ }
82
+ }
115
83
116
84
return vscode . window . showQuickPick ( commands ) . then ( command => {
117
85
if ( command ) {
@@ -121,84 +89,19 @@ function dnxExecuteCommand(server: OmnisharpServer) {
121
89
} ) ;
122
90
}
123
91
124
- export function dnxRestoreForAll ( server : OmnisharpServer ) {
125
-
126
- if ( ! server . isRunning ( ) ) {
127
- return Promise . reject ( 'OmniSharp server is not running.' ) ;
128
- }
92
+ export function dotnetRestoreForProject ( server : OmnisharpServer , fileName : string ) {
129
93
130
94
return serverUtils . requestWorkspaceInformation ( server ) . then ( info => {
131
-
132
- let commands :Command [ ] = [ ] ;
133
-
134
- info . Dnx . Projects . forEach ( project => {
135
- commands . push ( {
136
- label : `dnu restore - (${ project . Name || path . basename ( project . Path ) } )` ,
137
- description : path . dirname ( project . Path ) ,
138
- execute ( ) {
139
-
140
- let command = path . join ( info . Dnx . RuntimePath , 'bin/dnu' ) ;
141
- if ( isWindows ) {
142
- command += '.cmd' ;
143
- }
144
-
145
- return runInTerminal ( command , [ 'restore' ] , {
146
- cwd : path . dirname ( project . Path )
147
- } ) ;
148
- }
149
- } ) ;
150
- } ) ;
151
-
152
- return vscode . window . showQuickPick ( commands ) . then ( command => {
153
- if ( command ) {
154
- return command . execute ( ) ;
155
- }
156
- } ) ;
157
- } ) ;
158
- }
159
-
160
- export function dnxRestoreForProject ( server : OmnisharpServer , fileName : string ) {
161
-
162
- return serverUtils . requestWorkspaceInformation ( server ) . then ( ( info ) :Promise < any > => {
163
- for ( let project of info . Dnx . Projects ) {
164
- if ( project . Path === fileName ) {
165
- let command = path . join ( info . Dnx . RuntimePath , 'bin/dnu' ) ;
166
- if ( isWindows ) {
167
- command += '.cmd' ;
168
- }
169
-
170
- return runInTerminal ( command , [ 'restore' ] , {
171
- cwd : path . dirname ( project . Path )
172
- } ) ;
173
- }
174
- }
175
-
176
- return Promise . reject ( `Failed to execute restore, try to run 'dnu restore' manually for ${ fileName } .` ) ;
95
+ if ( 'DotNet' in info && info . DotNet . Projects . length > 0 ) {
96
+ for ( let project of info . DotNet . Projects ) {
97
+ if ( project . Path === path . dirname ( fileName ) ) {
98
+ return runInTerminal ( 'dotnet' , [ 'restore' , fileName ] , {
99
+ cwd : path . dirname ( project . Path )
100
+ } ) ;
101
+ }
102
+ }
103
+ }
104
+
105
+ return Promise . reject ( `Failed to execute restore, try to run 'dotnet restore' manually for ${ fileName } .` ) ;
177
106
} ) ;
178
- }
179
-
180
- function dotnetRestore ( server : OmnisharpServer ) {
181
-
182
- if ( ! server . isRunning ( ) ) {
183
- return Promise . reject ( 'OmniSharp server is not running.' ) ;
184
- }
185
-
186
- let solutionPathOrFolder = server . getSolutionPathOrFolder ( ) ;
187
- if ( ! solutionPathOrFolder ) {
188
- return Promise . reject ( 'No solution or folder open.' ) ;
189
- }
190
-
191
- getFolderPath ( solutionPathOrFolder ) . then ( folder => {
192
- return runInTerminal ( 'dotnet' , [ 'restore' ] , {
193
- cwd : folder
194
- } ) ;
195
- } ) ;
196
- }
197
-
198
- function getFolderPath ( fileOrFolderPath : string ) : Promise < string > {
199
- return fs . lstatAsync ( fileOrFolderPath ) . then ( stats => {
200
- return stats . isFile ( )
201
- ? path . dirname ( fileOrFolderPath )
202
- : fileOrFolderPath ;
203
- } ) ;
204
107
}
0 commit comments