Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update to support new OmniSharp release #139

Merged
merged 5 commits into from
Apr 5, 2016
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .vscodeignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ src/**
**/*.map

.vscode/**
.omnisharp/**

coreclr-debug/debugAdapters/**
coreclr-debug/bin/**
Expand Down
12 changes: 0 additions & 12 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,6 @@
"onLanguage:csharp",
"onCommand:o.restart",
"onCommand:o.pickProjectAndStart",
"onCommand:o.restore",
"onCommand:o.execute",
"onCommand:o.showOutput",
"onCommand:o.execute-last-command",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove execute-last-command also?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch -- thanks!

"onCommand:dotnet.restore",
Expand Down Expand Up @@ -92,16 +90,6 @@
"title": "Select Project",
"category": "OmniSharp"
},
{
"command": "o.restore",
"title": "Restore Packages",
"category": "dnx"
},
{
"command": "o.execute",
"title": "Run Command",
"category": "dnx"
},
{
"command": "dotnet.restore",
"title": "Restore Packages",
Expand Down
24 changes: 18 additions & 6 deletions src/assets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -228,12 +228,24 @@ function addLaunchJsonIfNecessary(info: protocol.DotNetWorkspaceInformation, pat

let targetFramework = '<target-framework>';
let executableName = '<project-name.dll>';

let projectWithEntryPoint = info.Projects.find(project => project.EmitEntryPoint === true);

if (projectWithEntryPoint) {
targetFramework = projectWithEntryPoint.TargetFramework.ShortName;
executableName = path.basename(projectWithEntryPoint.CompilationOutputAssemblyFile);
let done = false;
for (var project of info.Projects) {
for (var configuration of project.Configurations) {
if (configuration.Name === "Debug" && configuration.EmitEntryPoint === true) {
if (project.Frameworks.length > 0) {
targetFramework = project.Frameworks[0].ShortName;
executableName = path.basename(configuration.CompilationOutputAssemblyFile)
}

done = true;
break;
}
}

if (done) {
break;
}
}

const launchJson = createLaunchJson(targetFramework, executableName);
Expand All @@ -256,7 +268,7 @@ export function addAssetsIfNecessary(server: OmnisharpServer) {

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) {
if ('DotNet' in info && info.DotNet.Projects.length > 0) {
return getOperations().then(operations => {
if (!hasOperations(operations)) {
return;
Expand Down
159 changes: 31 additions & 128 deletions src/features/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import {OmnisharpServer} from '../omnisharpServer';
import * as serverUtils from '../omnisharpUtils';
import findLaunchTargets from '../launchTargetFinder';
import {runInTerminal} from 'run-in-terminal';
import * as fs from 'fs-extra-promise';
import * as path from 'path';
import * as vscode from 'vscode';

Expand All @@ -18,17 +17,14 @@ const isWindows = process.platform === 'win32';
export default function registerCommands(server: OmnisharpServer, extensionPath: string) {
let d1 = vscode.commands.registerCommand('o.restart', () => server.restart());
let d2 = vscode.commands.registerCommand('o.pickProjectAndStart', () => pickProjectAndStart(server));
let d3 = vscode.commands.registerCommand('o.restore', () => dnxRestoreForAll(server));
let d4 = vscode.commands.registerCommand('o.execute', () => dnxExecuteCommand(server));
let d5 = vscode.commands.registerCommand('o.execute-last-command', () => dnxExecuteLastCommand(server));
let d6 = vscode.commands.registerCommand('o.showOutput', () => server.getChannel().show(vscode.ViewColumn.Three));
let d7 = vscode.commands.registerCommand('dotnet.restore', () => dotnetRestore(server));
let d3 = vscode.commands.registerCommand('o.showOutput', () => server.getChannel().show(vscode.ViewColumn.Three));
let d4 = vscode.commands.registerCommand('dotnet.restore', () => dotnetRestoreAllProjects(server));

// register empty handler for csharp.installDebugger
// running the command activates the extension, which is all we need for installation to kickoff
let d8 = vscode.commands.registerCommand('csharp.downloadDebugger', () => { });
let d5 = vscode.commands.registerCommand('csharp.downloadDebugger', () => { });

return vscode.Disposable.from(d1, d2, d3, d4, d5, d6, d7, d8);
return vscode.Disposable.from(d1, d2, d3, d4, d5);
}

function pickProjectAndStart(server: OmnisharpServer) {
Expand Down Expand Up @@ -61,17 +57,7 @@ interface Command {
execute(): Thenable<any>;
}

let lastCommand: Command;

function dnxExecuteLastCommand(server: OmnisharpServer) {
if (lastCommand) {
lastCommand.execute();
} else {
dnxExecuteCommand(server);
}
}

function dnxExecuteCommand(server: OmnisharpServer) {
export function dotnetRestoreAllProjects(server: OmnisharpServer) {

if (!server.isRunning()) {
return Promise.reject('OmniSharp server is not running.');
Expand All @@ -80,38 +66,20 @@ function dnxExecuteCommand(server: OmnisharpServer) {
return serverUtils.requestWorkspaceInformation(server).then(info => {

let commands: Command[] = [];

info.Dnx.Projects.forEach(project => {
Object.keys(project.Commands).forEach(key => {

commands.push({
label: `dnx ${key} - (${project.Name || path.basename(project.Path)})`,
description: path.dirname(project.Path),
execute() {
lastCommand = this;

let command = path.join(info.Dnx.RuntimePath, 'bin/dnx');
let args = [key];

// dnx-beta[1-6] needs a leading dot, like 'dnx . run'
if (/-beta[1-6]/.test(info.Dnx.RuntimePath)) {
args.unshift('.');
}

if (isWindows) {
command += '.exe';
}

return runInTerminal(command, args, {
cwd: path.dirname(project.Path),
env: {
// KRE_COMPILATION_SERVER_PORT: workspace.DesignTimeHostPort
}
});
}
});
});
});

if ('DotNet' in info && info.DotNet.Projects.length > 0) {
for (let project of info.DotNet.Projects) {
commands.push({
label: `dotnet restor - (${project.Name || path.basename(project.Path)})`,
description: path.dirname(project.Path),
execute() {
return runInTerminal('dotnet', ['restore'], {
cwd: path.dirname(project.Path)
});
}
});
}
}

return vscode.window.showQuickPick(commands).then(command => {
if (command) {
Expand All @@ -121,84 +89,19 @@ function dnxExecuteCommand(server: OmnisharpServer) {
});
}

export function dnxRestoreForAll(server: OmnisharpServer) {

if (!server.isRunning()) {
return Promise.reject('OmniSharp server is not running.');
}
export function dotnetRestoreForProject(server: OmnisharpServer, fileName: string) {

return serverUtils.requestWorkspaceInformation(server).then(info => {

let commands:Command[] = [];

info.Dnx.Projects.forEach(project => {
commands.push({
label: `dnu restore - (${project.Name || path.basename(project.Path)})`,
description: path.dirname(project.Path),
execute() {

let command = path.join(info.Dnx.RuntimePath, 'bin/dnu');
if (isWindows) {
command += '.cmd';
}

return runInTerminal(command, ['restore'], {
cwd: path.dirname(project.Path)
});
}
});
});

return vscode.window.showQuickPick(commands).then(command => {
if(command) {
return command.execute();
}
});
});
}

export function dnxRestoreForProject(server: OmnisharpServer, fileName: string) {

return serverUtils.requestWorkspaceInformation(server).then((info):Promise<any> => {
for(let project of info.Dnx.Projects) {
if (project.Path === fileName) {
let command = path.join(info.Dnx.RuntimePath, 'bin/dnu');
if (isWindows) {
command += '.cmd';
}

return runInTerminal(command, ['restore'], {
cwd: path.dirname(project.Path)
});
}
}

return Promise.reject(`Failed to execute restore, try to run 'dnu restore' manually for ${fileName}.`);
if ('DotNet' in info && info.DotNet.Projects.length > 0) {
for (let project of info.DotNet.Projects) {
if (project.Path === path.dirname(fileName)) {
return runInTerminal('dotnet', ['restore', fileName], {
cwd: path.dirname(project.Path)
});
}
}
}

return Promise.reject(`Failed to execute restore, try to run 'dotnet restore' manually for ${fileName}.`);
});
}

function dotnetRestore(server: OmnisharpServer) {

if (!server.isRunning()) {
return Promise.reject('OmniSharp server is not running.');
}

let solutionPathOrFolder = server.getSolutionPathOrFolder();
if (!solutionPathOrFolder) {
return Promise.reject('No solution or folder open.');
}

getFolderPath(solutionPathOrFolder).then(folder => {
return runInTerminal('dotnet', ['restore'], {
cwd: folder
});
});
}

function getFolderPath(fileOrFolderPath: string): Promise<string> {
return fs.lstatAsync(fileOrFolderPath).then(stats => {
return stats.isFile()
? path.dirname(fileOrFolderPath)
: fileOrFolderPath;
});
}
4 changes: 2 additions & 2 deletions src/features/omnisharpStatus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import * as vscode from 'vscode';
import {OmnisharpServer} from '../omnisharpServer';
import {dnxRestoreForProject} from './commands';
import {dotnetRestoreForProject} from './commands';
import {basename} from 'path';
import * as protocol from '../protocol';
import * as serverUtils from '../omnisharpUtils';
Expand Down Expand Up @@ -235,7 +235,7 @@ export function reportServerStatus(server: OmnisharpServer): vscode.Disposable{

return vscode.window.showInformationMessage(info, 'Restore').then(value => {
if (value) {
dnxRestoreForProject(server, message.FileName);
dotnetRestoreForProject(server, message.FileName);
}
});
});
Expand Down
19 changes: 13 additions & 6 deletions src/protocol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -263,19 +263,26 @@ export interface DnxFramework {

export interface DotNetWorkspaceInformation {
Projects: DotNetProject[];
RuntimePath: string;
}

export interface DotNetProject {
Path: string;
Name: string;
TargetFramework: DotNetFramework;
CompilationOutputPath: string;
CompilationOutputAssemblyFile: string;
CompilationOutputPdbFile: string;
EmitEntryPoint?: boolean;
Name: string;
ProjectSearchPaths: string[];
Configurations: DotNetConfiguration[];
Frameworks: DotNetFramework[];
SourceFiles: string[];
}

export interface DotNetConfiguration {
Name: string;
CompilationOutputPath: string;
CompilationOutputAssemblyFile: string;
CompilationOutputPdbFile: string;
EmitEntryPoint?: boolean;
}

export interface DotNetFramework {
Name: string;
FriendlyName: string;
Expand Down