@@ -10,6 +10,7 @@ import {dotnetRestoreForProject} from './commands';
10
10
import { basename } from 'path' ;
11
11
import * as protocol from '../omnisharp/protocol' ;
12
12
import * as serverUtils from '../omnisharp/utils' ;
13
+ import { debounce } from 'lodash' ;
13
14
14
15
export default function reportStatus ( server : OmnisharpServer ) {
15
16
return vscode . Disposable . from (
@@ -42,6 +43,7 @@ class Status {
42
43
export function reportDocumentStatus ( server : OmnisharpServer ) : vscode . Disposable {
43
44
44
45
let disposables : vscode . Disposable [ ] = [ ] ;
46
+ let localDisposables : vscode . Disposable [ ] ;
45
47
46
48
let entry = vscode . window . createStatusBarItem ( vscode . StatusBarAlignment . Right , Number . MIN_VALUE ) ;
47
49
let defaultStatus = new Status ( defaultSelector ) ;
@@ -107,44 +109,48 @@ export function reportDocumentStatus(server: OmnisharpServer): vscode.Disposable
107
109
disposables . push ( server . onServerStop ( ( ) => {
108
110
projectStatus = undefined ;
109
111
defaultStatus . text = undefined ;
112
+
113
+ vscode . Disposable . from ( ...localDisposables ) . dispose ( ) ;
114
+ localDisposables = undefined ;
110
115
} ) ) ;
111
116
112
117
disposables . push ( server . onServerStart ( path => {
118
+ localDisposables = [ ] ;
113
119
114
120
defaultStatus . text = '$(flame) Running' ;
115
121
defaultStatus . command = 'o.pickProjectAndStart' ;
116
122
defaultStatus . color = '' ;
117
123
render ( ) ;
118
124
119
- function updateProjectInfo ( ) {
120
- serverUtils . requestWorkspaceInformation ( server ) . then ( info => {
121
-
125
+ function updateProjectInfo ( ) {
126
+ serverUtils . requestWorkspaceInformation ( server ) . then ( info => {
127
+
122
128
interface Project {
123
129
Path : string ;
124
130
SourceFiles : string [ ] ;
125
131
}
126
-
132
+
127
133
let fileNames : vscode . DocumentSelector [ ] = [ ] ;
128
134
let label : string ;
129
135
130
136
function addProjectFileNames ( project : Project ) {
131
137
fileNames . push ( { pattern : project . Path } ) ;
132
-
138
+
133
139
if ( project . SourceFiles ) {
134
140
for ( let sourceFile of project . SourceFiles ) {
135
141
fileNames . push ( { pattern : sourceFile } ) ;
136
142
}
137
143
}
138
144
}
139
-
145
+
140
146
function addDnxOrDotNetProjects ( projects : Project [ ] ) {
141
147
let count = 0 ;
142
-
148
+
143
149
for ( let project of projects ) {
144
150
count += 1 ;
145
151
addProjectFileNames ( project ) ;
146
152
}
147
-
153
+
148
154
if ( ! label ) {
149
155
if ( count === 1 ) {
150
156
label = basename ( projects [ 0 ] . Path ) ; //workspace.getRelativePath(info.Dnx.Projects[0].Path);
@@ -159,7 +165,7 @@ export function reportDocumentStatus(server: OmnisharpServer): vscode.Disposable
159
165
if ( info . MsBuild && info . MsBuild . SolutionPath ) {
160
166
label = basename ( info . MsBuild . SolutionPath ) ; //workspace.getRelativePath(info.MsBuild.SolutionPath);
161
167
fileNames . push ( { pattern : info . MsBuild . SolutionPath } ) ;
162
-
168
+
163
169
for ( let project of info . MsBuild . Projects ) {
164
170
addProjectFileNames ( project ) ;
165
171
}
@@ -182,9 +188,11 @@ export function reportDocumentStatus(server: OmnisharpServer): vscode.Disposable
182
188
} ) ;
183
189
}
184
190
185
- disposables . push ( server . onProjectAdded ( updateProjectInfo ) ) ;
186
- disposables . push ( server . onProjectChange ( updateProjectInfo ) ) ;
187
- disposables . push ( server . onProjectRemoved ( updateProjectInfo ) ) ;
191
+ // Don't allow the same request to slam the server within a "short" window
192
+ let debouncedUpdateProjectInfo = debounce ( updateProjectInfo , 1500 , { leading : true } ) ;
193
+ localDisposables . push ( server . onProjectAdded ( debouncedUpdateProjectInfo ) ) ;
194
+ localDisposables . push ( server . onProjectChange ( debouncedUpdateProjectInfo ) ) ;
195
+ localDisposables . push ( server . onProjectRemoved ( debouncedUpdateProjectInfo ) ) ;
188
196
} ) ) ;
189
197
190
198
return vscode . Disposable . from ( ...disposables ) ;
0 commit comments