Skip to content

Commit

Permalink
Merge pull request #754 from eamodio/bug-#735
Browse files Browse the repository at this point in the history
Fixes #735 - "Running" forever for folder with multiple .NET Core projects
  • Loading branch information
DustinCampbell authored Sep 13, 2016
2 parents 716f2f5 + a060446 commit fbbf5a1
Show file tree
Hide file tree
Showing 4 changed files with 18,582 additions and 28 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 @@
}
]
}
}
}
30 changes: 15 additions & 15 deletions src/assets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import * as vscode from 'vscode';
import * as tasks from 'vscode-tasks';
import {OmnisharpServer} from './omnisharp/server';
import * as serverUtils from './omnisharp/utils';
import * as protocol from './omnisharp/protocol.ts'
import * as protocol from './omnisharp/protocol'

interface DebugConfiguration {
name: string,
Expand Down Expand Up @@ -60,7 +60,7 @@ interface Paths {

function getPaths(): Paths {
const vscodeFolder = path.join(vscode.workspace.rootPath, '.vscode');

return {
vscodeFolder: vscodeFolder,
tasksJsonPath: path.join(vscodeFolder, 'tasks.json'),
Expand All @@ -83,7 +83,7 @@ function hasOperations(operations: Operations) {
function getOperations() {
const paths = getPaths();

return getBuildOperations(paths.tasksJsonPath).then(operations =>
return getBuildOperations(paths.tasksJsonPath).then(operations =>
getLaunchOperations(paths.launchJsonPath, operations));
}

Expand All @@ -95,7 +95,7 @@ function getBuildOperations(tasksJsonPath: string) {
const text = buffer.toString();
const tasksJson: tasks.TaskConfiguration = JSON.parse(text);
const buildTask = tasksJson.tasks.find(td => td.taskName === 'build');

resolve({ updateTasksJson: (buildTask === undefined) });
});
}
Expand Down Expand Up @@ -123,7 +123,7 @@ function getLaunchOperations(launchJsonPath: string, operations: Operations) {
function promptToAddAssets() {
return new Promise<boolean>((resolve, reject) => {
const item = { title: 'Yes' }

vscode.window.showInformationMessage('Required assets to build and debug are missing from your project. Add them?', item).then(selection => {
return selection
? resolve(true)
Expand All @@ -139,7 +139,7 @@ function computeProgramPath(projectData: TargetProjectData) {
}

let result = '${workspaceRoot}';

if (projectData.projectPath) {
result = path.join(result, path.relative(vscode.workspace.rootPath, projectData.projectPath.fsPath));
}
Expand Down Expand Up @@ -258,10 +258,10 @@ function addTasksJsonIfNecessary(projectData: TargetProjectData, paths: Paths, o
if (!operations.addTasksJson) {
return resolve();
}

const tasksJson = createTasksConfiguration(projectData);
const tasksJsonText = JSON.stringify(tasksJson, null, ' ');

return fs.writeFileAsync(paths.tasksJsonPath, tasksJsonText);
});
}
Expand Down Expand Up @@ -341,13 +341,13 @@ function hasWebServerDependency(targetProjectData: TargetProjectData): boolean {
if (projectJsonObject == null) {
return false;
}

for (var key in projectJsonObject.dependencies) {
if (key.toLowerCase().startsWith("microsoft.aspnetcore.server")) {
return true;
}
}

return false;
}

Expand All @@ -360,7 +360,7 @@ function addLaunchJsonIfNecessary(projectData: TargetProjectData, paths: Paths,
const isWebProject = hasWebServerDependency(projectData);
const launchJson = createLaunchJson(projectData, isWebProject);
const launchJsonText = JSON.stringify(launchJson, null, ' ');

return fs.writeFileAsync(paths.launchJsonPath, launchJsonText);
});
}
Expand All @@ -369,23 +369,23 @@ export function addAssetsIfNecessary(server: OmnisharpServer) {
if (!vscode.workspace.rootPath) {
return;
}

return serverUtils.requestWorkspaceInformation(server).then(info => {
// If there are no .NET Core projects, we won't bother offering to add assets.
if ('DotNet' in info && info.DotNet.Projects.length > 0) {
return getOperations().then(operations => {
if (!hasOperations(operations)) {
return;
}

promptToAddAssets().then(addAssets => {
if (!addAssets) {
return;
}

const data = findTargetProjectData(info.DotNet.Projects);
const paths = getPaths();

return fs.ensureDirAsync(paths.vscodeFolder).then(() => {
return Promise.all([
addTasksJsonIfNecessary(data, paths, operations),
Expand Down
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 fbbf5a1

Please sign in to comment.