Skip to content

Commit fbbf5a1

Browse files
Merge pull request #754 from eamodio/bug-#735
Fixes #735 - "Running" forever for folder with multiple .NET Core projects
2 parents 716f2f5 + a060446 commit fbbf5a1

File tree

4 files changed

+18582
-28
lines changed

4 files changed

+18582
-28
lines changed

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
"fs-extra-promise": "^0.3.1",
3131
"http-proxy-agent": "^1.0.0",
3232
"https-proxy-agent": "^1.0.0",
33+
"lodash": "^4.15.0",
3334
"open": "*",
3435
"semver": "*",
3536
"tmp": "0.0.28",
@@ -691,4 +692,4 @@
691692
}
692693
]
693694
}
694-
}
695+
}

src/assets.ts

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import * as vscode from 'vscode';
1111
import * as tasks from 'vscode-tasks';
1212
import {OmnisharpServer} from './omnisharp/server';
1313
import * as serverUtils from './omnisharp/utils';
14-
import * as protocol from './omnisharp/protocol.ts'
14+
import * as protocol from './omnisharp/protocol'
1515

1616
interface DebugConfiguration {
1717
name: string,
@@ -60,7 +60,7 @@ interface Paths {
6060

6161
function getPaths(): Paths {
6262
const vscodeFolder = path.join(vscode.workspace.rootPath, '.vscode');
63-
63+
6464
return {
6565
vscodeFolder: vscodeFolder,
6666
tasksJsonPath: path.join(vscodeFolder, 'tasks.json'),
@@ -83,7 +83,7 @@ function hasOperations(operations: Operations) {
8383
function getOperations() {
8484
const paths = getPaths();
8585

86-
return getBuildOperations(paths.tasksJsonPath).then(operations =>
86+
return getBuildOperations(paths.tasksJsonPath).then(operations =>
8787
getLaunchOperations(paths.launchJsonPath, operations));
8888
}
8989

@@ -95,7 +95,7 @@ function getBuildOperations(tasksJsonPath: string) {
9595
const text = buffer.toString();
9696
const tasksJson: tasks.TaskConfiguration = JSON.parse(text);
9797
const buildTask = tasksJson.tasks.find(td => td.taskName === 'build');
98-
98+
9999
resolve({ updateTasksJson: (buildTask === undefined) });
100100
});
101101
}
@@ -123,7 +123,7 @@ function getLaunchOperations(launchJsonPath: string, operations: Operations) {
123123
function promptToAddAssets() {
124124
return new Promise<boolean>((resolve, reject) => {
125125
const item = { title: 'Yes' }
126-
126+
127127
vscode.window.showInformationMessage('Required assets to build and debug are missing from your project. Add them?', item).then(selection => {
128128
return selection
129129
? resolve(true)
@@ -139,7 +139,7 @@ function computeProgramPath(projectData: TargetProjectData) {
139139
}
140140

141141
let result = '${workspaceRoot}';
142-
142+
143143
if (projectData.projectPath) {
144144
result = path.join(result, path.relative(vscode.workspace.rootPath, projectData.projectPath.fsPath));
145145
}
@@ -258,10 +258,10 @@ function addTasksJsonIfNecessary(projectData: TargetProjectData, paths: Paths, o
258258
if (!operations.addTasksJson) {
259259
return resolve();
260260
}
261-
261+
262262
const tasksJson = createTasksConfiguration(projectData);
263263
const tasksJsonText = JSON.stringify(tasksJson, null, ' ');
264-
264+
265265
return fs.writeFileAsync(paths.tasksJsonPath, tasksJsonText);
266266
});
267267
}
@@ -341,13 +341,13 @@ function hasWebServerDependency(targetProjectData: TargetProjectData): boolean {
341341
if (projectJsonObject == null) {
342342
return false;
343343
}
344-
344+
345345
for (var key in projectJsonObject.dependencies) {
346346
if (key.toLowerCase().startsWith("microsoft.aspnetcore.server")) {
347347
return true;
348348
}
349349
}
350-
350+
351351
return false;
352352
}
353353

@@ -360,7 +360,7 @@ function addLaunchJsonIfNecessary(projectData: TargetProjectData, paths: Paths,
360360
const isWebProject = hasWebServerDependency(projectData);
361361
const launchJson = createLaunchJson(projectData, isWebProject);
362362
const launchJsonText = JSON.stringify(launchJson, null, ' ');
363-
363+
364364
return fs.writeFileAsync(paths.launchJsonPath, launchJsonText);
365365
});
366366
}
@@ -369,23 +369,23 @@ export function addAssetsIfNecessary(server: OmnisharpServer) {
369369
if (!vscode.workspace.rootPath) {
370370
return;
371371
}
372-
372+
373373
return serverUtils.requestWorkspaceInformation(server).then(info => {
374374
// If there are no .NET Core projects, we won't bother offering to add assets.
375375
if ('DotNet' in info && info.DotNet.Projects.length > 0) {
376376
return getOperations().then(operations => {
377377
if (!hasOperations(operations)) {
378378
return;
379379
}
380-
380+
381381
promptToAddAssets().then(addAssets => {
382382
if (!addAssets) {
383383
return;
384384
}
385-
385+
386386
const data = findTargetProjectData(info.DotNet.Projects);
387387
const paths = getPaths();
388-
388+
389389
return fs.ensureDirAsync(paths.vscodeFolder).then(() => {
390390
return Promise.all([
391391
addTasksJsonIfNecessary(data, paths, operations),

src/features/status.ts

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import {dotnetRestoreForProject} from './commands';
1010
import {basename} from 'path';
1111
import * as protocol from '../omnisharp/protocol';
1212
import * as serverUtils from '../omnisharp/utils';
13+
import {debounce} from 'lodash';
1314

1415
export default function reportStatus(server: OmnisharpServer) {
1516
return vscode.Disposable.from(
@@ -42,6 +43,7 @@ class Status {
4243
export 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

Comments
 (0)