Skip to content

Commit

Permalink
Merge pull request #139 from DustinCampbell/update-omnisharp
Browse files Browse the repository at this point in the history
Update to support new OmniSharp release
  • Loading branch information
DustinCampbell committed Apr 5, 2016
2 parents a9b09e5 + 31e37d8 commit be7147d
Show file tree
Hide file tree
Showing 7 changed files with 69 additions and 169 deletions.
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
23 changes: 0 additions & 23 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,7 @@
"onLanguage:csharp",
"onCommand:o.restart",
"onCommand:o.pickProjectAndStart",
"onCommand:o.restore",
"onCommand:o.execute",
"onCommand:o.showOutput",
"onCommand:o.execute-last-command",
"onCommand:dotnet.restore",
"onCommand:csharp.downloadDebugger",
"workspaceContains:project.json"
Expand Down Expand Up @@ -92,16 +89,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 All @@ -119,16 +106,6 @@
"key": "Ctrl+L L",
"mac": "Cmd+L L"
},
{
"command": "o.execute",
"key": "Ctrl+L Shift+R",
"mac": "Cmd+L Shift+R"
},
{
"command": "o.execute-last-command",
"key": "Ctrl+L R",
"mac": "Cmd+L R"
},
{
"key": "shift+0",
"command": "^acceptSelectedSuggestion",
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
8 changes: 4 additions & 4 deletions src/omnisharpDownload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,19 @@ const Decompress = require('decompress');
const Github = require('github-releases');

const OmnisharpRepo = 'OmniSharp/omnisharp-roslyn';
const OmnisharpVersion = 'v1.9-alpha7';
const OmnisharpVersion = 'v1.9-alpha10';
const DefaultInstallLocation = path.join(__dirname, '../.omnisharp');

tmp.setGracefulCleanup();

function getOmnisharpAssetName(): string {
switch (process.platform) {
case 'win32':
return 'omnisharp-win-x64-dnx451.zip';
return 'omnisharp-win-x64-net451.zip';
case 'darwin':
return 'omnisharp-osx-x64-dnxcore50.tar.gz';
return 'omnisharp-osx-x64-netcoreapp1.0.tar.gz';
case 'linux':
return 'omnisharp-linux-x64-dnxcore50.tar.gz';
return 'omnisharp-linux-x64-netcoreapp1.0.tar.gz';
default:
throw new Error(`Unsupported platform: ${process.platform}`);
}
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

0 comments on commit be7147d

Please sign in to comment.