@@ -10,6 +10,7 @@ import {dotnetRestoreForProject} from './commands';
1010import { basename } from 'path' ;
1111import * as protocol from '../omnisharp/protocol' ;
1212import * as serverUtils from '../omnisharp/utils' ;
13+ import { debounce } from 'lodash' ;
1314
1415export default function reportStatus ( server : OmnisharpServer ) {
1516 return vscode . Disposable . from (
@@ -42,6 +43,7 @@ class Status {
4243export function reportDocumentStatus ( server : OmnisharpServer ) : vscode . Disposable {
4344
4445 let disposables : vscode . Disposable [ ] = [ ] ;
46+ let localDisposables : vscode . Disposable [ ] ;
4547
4648 let entry = vscode . window . createStatusBarItem ( vscode . StatusBarAlignment . Right , Number . MIN_VALUE ) ;
4749 let defaultStatus = new Status ( defaultSelector ) ;
@@ -107,44 +109,48 @@ export function reportDocumentStatus(server: OmnisharpServer): vscode.Disposable
107109 disposables . push ( server . onServerStop ( ( ) => {
108110 projectStatus = undefined ;
109111 defaultStatus . text = undefined ;
112+
113+ vscode . Disposable . from ( ...localDisposables ) . dispose ( ) ;
114+ localDisposables = undefined ;
110115 } ) ) ;
111116
112117 disposables . push ( server . onServerStart ( path => {
118+ localDisposables = [ ] ;
113119
114120 defaultStatus . text = '$(flame) Running' ;
115121 defaultStatus . command = 'o.pickProjectAndStart' ;
116122 defaultStatus . color = '' ;
117123 render ( ) ;
118124
119- function updateProjectInfo ( ) {
120- serverUtils . requestWorkspaceInformation ( server ) . then ( info => {
121-
125+ function updateProjectInfo ( ) {
126+ serverUtils . requestWorkspaceInformation ( server ) . then ( info => {
127+
122128 interface Project {
123129 Path : string ;
124130 SourceFiles : string [ ] ;
125131 }
126-
132+
127133 let fileNames : vscode . DocumentSelector [ ] = [ ] ;
128134 let label : string ;
129135
130136 function addProjectFileNames ( project : Project ) {
131137 fileNames . push ( { pattern : project . Path } ) ;
132-
138+
133139 if ( project . SourceFiles ) {
134140 for ( let sourceFile of project . SourceFiles ) {
135141 fileNames . push ( { pattern : sourceFile } ) ;
136142 }
137143 }
138144 }
139-
145+
140146 function addDnxOrDotNetProjects ( projects : Project [ ] ) {
141147 let count = 0 ;
142-
148+
143149 for ( let project of projects ) {
144150 count += 1 ;
145151 addProjectFileNames ( project ) ;
146152 }
147-
153+
148154 if ( ! label ) {
149155 if ( count === 1 ) {
150156 label = basename ( projects [ 0 ] . Path ) ; //workspace.getRelativePath(info.Dnx.Projects[0].Path);
@@ -159,7 +165,7 @@ export function reportDocumentStatus(server: OmnisharpServer): vscode.Disposable
159165 if ( info . MsBuild && info . MsBuild . SolutionPath ) {
160166 label = basename ( info . MsBuild . SolutionPath ) ; //workspace.getRelativePath(info.MsBuild.SolutionPath);
161167 fileNames . push ( { pattern : info . MsBuild . SolutionPath } ) ;
162-
168+
163169 for ( let project of info . MsBuild . Projects ) {
164170 addProjectFileNames ( project ) ;
165171 }
@@ -182,9 +188,11 @@ export function reportDocumentStatus(server: OmnisharpServer): vscode.Disposable
182188 } ) ;
183189 }
184190
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 ) ) ;
188196 } ) ) ;
189197
190198 return vscode . Disposable . from ( ...disposables ) ;
0 commit comments