Skip to content

Commit

Permalink
Fixes #735 - "Running" forever for folder with multiple .NET Core pro…
Browse files Browse the repository at this point in the history
…jects

Also stops multiple duplicate requests from hitting server within a short window
  • Loading branch information
Eric Amodio committed Sep 13, 2016
1 parent 8b8dba6 commit a060446
Show file tree
Hide file tree
Showing 3 changed files with 18,567 additions and 13 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
"fs-extra-promise": "^0.3.1",
"http-proxy-agent": "^1.0.0",
"https-proxy-agent": "^1.0.0",
"lodash": "^4.15.0",
"open": "*",
"semver": "*",
"tmp": "0.0.28",
Expand Down Expand Up @@ -691,4 +692,4 @@
}
]
}
}
}
32 changes: 20 additions & 12 deletions src/features/status.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {dotnetRestoreForProject} from './commands';
import {basename} from 'path';
import * as protocol from '../omnisharp/protocol';
import * as serverUtils from '../omnisharp/utils';
import {debounce} from 'lodash';

export default function reportStatus(server: OmnisharpServer) {
return vscode.Disposable.from(
Expand Down Expand Up @@ -42,6 +43,7 @@ class Status {
export function reportDocumentStatus(server: OmnisharpServer): vscode.Disposable {

let disposables: vscode.Disposable[] = [];
let localDisposables: vscode.Disposable[];

let entry = vscode.window.createStatusBarItem(vscode.StatusBarAlignment.Right, Number.MIN_VALUE);
let defaultStatus = new Status(defaultSelector);
Expand Down Expand Up @@ -107,44 +109,48 @@ export function reportDocumentStatus(server: OmnisharpServer): vscode.Disposable
disposables.push(server.onServerStop(() => {
projectStatus = undefined;
defaultStatus.text = undefined;

vscode.Disposable.from(...localDisposables).dispose();
localDisposables = undefined;
}));

disposables.push(server.onServerStart(path => {
localDisposables = [];

defaultStatus.text = '$(flame) Running';
defaultStatus.command = 'o.pickProjectAndStart';
defaultStatus.color = '';
render();

function updateProjectInfo() {
serverUtils.requestWorkspaceInformation(server).then(info => {
function updateProjectInfo() {
serverUtils.requestWorkspaceInformation(server).then(info => {

interface Project {
Path: string;
SourceFiles: string[];
}

let fileNames: vscode.DocumentSelector[] = [];
let label: string;

function addProjectFileNames(project: Project) {
fileNames.push({ pattern: project.Path });

if (project.SourceFiles) {
for (let sourceFile of project.SourceFiles) {
fileNames.push({ pattern: sourceFile });
}
}
}

function addDnxOrDotNetProjects(projects: Project[]) {
let count = 0;

for (let project of projects) {
count += 1;
addProjectFileNames(project);
}

if (!label) {
if (count === 1) {
label = basename(projects[0].Path); //workspace.getRelativePath(info.Dnx.Projects[0].Path);
Expand All @@ -159,7 +165,7 @@ export function reportDocumentStatus(server: OmnisharpServer): vscode.Disposable
if (info.MsBuild && info.MsBuild.SolutionPath) {
label = basename(info.MsBuild.SolutionPath); //workspace.getRelativePath(info.MsBuild.SolutionPath);
fileNames.push({ pattern: info.MsBuild.SolutionPath });

for (let project of info.MsBuild.Projects) {
addProjectFileNames(project);
}
Expand All @@ -182,9 +188,11 @@ export function reportDocumentStatus(server: OmnisharpServer): vscode.Disposable
});
}

disposables.push(server.onProjectAdded(updateProjectInfo));
disposables.push(server.onProjectChange(updateProjectInfo));
disposables.push(server.onProjectRemoved(updateProjectInfo));
// Don't allow the same request to slam the server within a "short" window
let debouncedUpdateProjectInfo = debounce(updateProjectInfo, 1500, { leading: true });
localDisposables.push(server.onProjectAdded(debouncedUpdateProjectInfo));
localDisposables.push(server.onProjectChange(debouncedUpdateProjectInfo));
localDisposables.push(server.onProjectRemoved(debouncedUpdateProjectInfo));
}));

return vscode.Disposable.from(...disposables);
Expand Down
Loading

0 comments on commit a060446

Please sign in to comment.