Skip to content

Commit be7147d

Browse files
Merge pull request #139 from DustinCampbell/update-omnisharp
Update to support new OmniSharp release
2 parents a9b09e5 + 31e37d8 commit be7147d

File tree

7 files changed

+69
-169
lines changed

7 files changed

+69
-169
lines changed

.vscodeignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ src/**
55
**/*.map
66

77
.vscode/**
8+
.omnisharp/**
89

910
coreclr-debug/debugAdapters/**
1011
coreclr-debug/bin/**

package.json

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,7 @@
4545
"onLanguage:csharp",
4646
"onCommand:o.restart",
4747
"onCommand:o.pickProjectAndStart",
48-
"onCommand:o.restore",
49-
"onCommand:o.execute",
5048
"onCommand:o.showOutput",
51-
"onCommand:o.execute-last-command",
5249
"onCommand:dotnet.restore",
5350
"onCommand:csharp.downloadDebugger",
5451
"workspaceContains:project.json"
@@ -92,16 +89,6 @@
9289
"title": "Select Project",
9390
"category": "OmniSharp"
9491
},
95-
{
96-
"command": "o.restore",
97-
"title": "Restore Packages",
98-
"category": "dnx"
99-
},
100-
{
101-
"command": "o.execute",
102-
"title": "Run Command",
103-
"category": "dnx"
104-
},
10592
{
10693
"command": "dotnet.restore",
10794
"title": "Restore Packages",
@@ -119,16 +106,6 @@
119106
"key": "Ctrl+L L",
120107
"mac": "Cmd+L L"
121108
},
122-
{
123-
"command": "o.execute",
124-
"key": "Ctrl+L Shift+R",
125-
"mac": "Cmd+L Shift+R"
126-
},
127-
{
128-
"command": "o.execute-last-command",
129-
"key": "Ctrl+L R",
130-
"mac": "Cmd+L R"
131-
},
132109
{
133110
"key": "shift+0",
134111
"command": "^acceptSelectedSuggestion",

src/assets.ts

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -228,12 +228,24 @@ function addLaunchJsonIfNecessary(info: protocol.DotNetWorkspaceInformation, pat
228228

229229
let targetFramework = '<target-framework>';
230230
let executableName = '<project-name.dll>';
231-
232-
let projectWithEntryPoint = info.Projects.find(project => project.EmitEntryPoint === true);
233231

234-
if (projectWithEntryPoint) {
235-
targetFramework = projectWithEntryPoint.TargetFramework.ShortName;
236-
executableName = path.basename(projectWithEntryPoint.CompilationOutputAssemblyFile);
232+
let done = false;
233+
for (var project of info.Projects) {
234+
for (var configuration of project.Configurations) {
235+
if (configuration.Name === "Debug" && configuration.EmitEntryPoint === true) {
236+
if (project.Frameworks.length > 0) {
237+
targetFramework = project.Frameworks[0].ShortName;
238+
executableName = path.basename(configuration.CompilationOutputAssemblyFile)
239+
}
240+
241+
done = true;
242+
break;
243+
}
244+
}
245+
246+
if (done) {
247+
break;
248+
}
237249
}
238250

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

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

src/features/commands.ts

Lines changed: 31 additions & 128 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import {OmnisharpServer} from '../omnisharpServer';
99
import * as serverUtils from '../omnisharpUtils';
1010
import findLaunchTargets from '../launchTargetFinder';
1111
import {runInTerminal} from 'run-in-terminal';
12-
import * as fs from 'fs-extra-promise';
1312
import * as path from 'path';
1413
import * as vscode from 'vscode';
1514

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

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

31-
return vscode.Disposable.from(d1, d2, d3, d4, d5, d6, d7, d8);
27+
return vscode.Disposable.from(d1, d2, d3, d4, d5);
3228
}
3329

3430
function pickProjectAndStart(server: OmnisharpServer) {
@@ -61,17 +57,7 @@ interface Command {
6157
execute(): Thenable<any>;
6258
}
6359

64-
let lastCommand: Command;
65-
66-
function dnxExecuteLastCommand(server: OmnisharpServer) {
67-
if (lastCommand) {
68-
lastCommand.execute();
69-
} else {
70-
dnxExecuteCommand(server);
71-
}
72-
}
73-
74-
function dnxExecuteCommand(server: OmnisharpServer) {
60+
export function dotnetRestoreAllProjects(server: OmnisharpServer) {
7561

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

8268
let commands: Command[] = [];
83-
84-
info.Dnx.Projects.forEach(project => {
85-
Object.keys(project.Commands).forEach(key => {
86-
87-
commands.push({
88-
label: `dnx ${key} - (${project.Name || path.basename(project.Path)})`,
89-
description: path.dirname(project.Path),
90-
execute() {
91-
lastCommand = this;
92-
93-
let command = path.join(info.Dnx.RuntimePath, 'bin/dnx');
94-
let args = [key];
95-
96-
// dnx-beta[1-6] needs a leading dot, like 'dnx . run'
97-
if (/-beta[1-6]/.test(info.Dnx.RuntimePath)) {
98-
args.unshift('.');
99-
}
100-
101-
if (isWindows) {
102-
command += '.exe';
103-
}
104-
105-
return runInTerminal(command, args, {
106-
cwd: path.dirname(project.Path),
107-
env: {
108-
// KRE_COMPILATION_SERVER_PORT: workspace.DesignTimeHostPort
109-
}
110-
});
111-
}
112-
});
113-
});
114-
});
69+
70+
if ('DotNet' in info && info.DotNet.Projects.length > 0) {
71+
for (let project of info.DotNet.Projects) {
72+
commands.push({
73+
label: `dotnet restor - (${project.Name || path.basename(project.Path)})`,
74+
description: path.dirname(project.Path),
75+
execute() {
76+
return runInTerminal('dotnet', ['restore'], {
77+
cwd: path.dirname(project.Path)
78+
});
79+
}
80+
});
81+
}
82+
}
11583

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

124-
export function dnxRestoreForAll(server: OmnisharpServer) {
125-
126-
if (!server.isRunning()) {
127-
return Promise.reject('OmniSharp server is not running.');
128-
}
92+
export function dotnetRestoreForProject(server: OmnisharpServer, fileName: string) {
12993

13094
return serverUtils.requestWorkspaceInformation(server).then(info => {
131-
132-
let commands:Command[] = [];
133-
134-
info.Dnx.Projects.forEach(project => {
135-
commands.push({
136-
label: `dnu restore - (${project.Name || path.basename(project.Path)})`,
137-
description: path.dirname(project.Path),
138-
execute() {
139-
140-
let command = path.join(info.Dnx.RuntimePath, 'bin/dnu');
141-
if (isWindows) {
142-
command += '.cmd';
143-
}
144-
145-
return runInTerminal(command, ['restore'], {
146-
cwd: path.dirname(project.Path)
147-
});
148-
}
149-
});
150-
});
151-
152-
return vscode.window.showQuickPick(commands).then(command => {
153-
if(command) {
154-
return command.execute();
155-
}
156-
});
157-
});
158-
}
159-
160-
export function dnxRestoreForProject(server: OmnisharpServer, fileName: string) {
161-
162-
return serverUtils.requestWorkspaceInformation(server).then((info):Promise<any> => {
163-
for(let project of info.Dnx.Projects) {
164-
if (project.Path === fileName) {
165-
let command = path.join(info.Dnx.RuntimePath, 'bin/dnu');
166-
if (isWindows) {
167-
command += '.cmd';
168-
}
169-
170-
return runInTerminal(command, ['restore'], {
171-
cwd: path.dirname(project.Path)
172-
});
173-
}
174-
}
175-
176-
return Promise.reject(`Failed to execute restore, try to run 'dnu restore' manually for ${fileName}.`);
95+
if ('DotNet' in info && info.DotNet.Projects.length > 0) {
96+
for (let project of info.DotNet.Projects) {
97+
if (project.Path === path.dirname(fileName)) {
98+
return runInTerminal('dotnet', ['restore', fileName], {
99+
cwd: path.dirname(project.Path)
100+
});
101+
}
102+
}
103+
}
104+
105+
return Promise.reject(`Failed to execute restore, try to run 'dotnet restore' manually for ${fileName}.`);
177106
});
178-
}
179-
180-
function dotnetRestore(server: OmnisharpServer) {
181-
182-
if (!server.isRunning()) {
183-
return Promise.reject('OmniSharp server is not running.');
184-
}
185-
186-
let solutionPathOrFolder = server.getSolutionPathOrFolder();
187-
if (!solutionPathOrFolder) {
188-
return Promise.reject('No solution or folder open.');
189-
}
190-
191-
getFolderPath(solutionPathOrFolder).then(folder => {
192-
return runInTerminal('dotnet', ['restore'], {
193-
cwd: folder
194-
});
195-
});
196-
}
197-
198-
function getFolderPath(fileOrFolderPath: string): Promise<string> {
199-
return fs.lstatAsync(fileOrFolderPath).then(stats => {
200-
return stats.isFile()
201-
? path.dirname(fileOrFolderPath)
202-
: fileOrFolderPath;
203-
});
204107
}

src/features/omnisharpStatus.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
import * as vscode from 'vscode';
88
import {OmnisharpServer} from '../omnisharpServer';
9-
import {dnxRestoreForProject} from './commands';
9+
import {dotnetRestoreForProject} from './commands';
1010
import {basename} from 'path';
1111
import * as protocol from '../protocol';
1212
import * as serverUtils from '../omnisharpUtils';
@@ -235,7 +235,7 @@ export function reportServerStatus(server: OmnisharpServer): vscode.Disposable{
235235

236236
return vscode.window.showInformationMessage(info, 'Restore').then(value => {
237237
if (value) {
238-
dnxRestoreForProject(server, message.FileName);
238+
dotnetRestoreForProject(server, message.FileName);
239239
}
240240
});
241241
});

src/omnisharpDownload.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,19 +13,19 @@ const Decompress = require('decompress');
1313
const Github = require('github-releases');
1414

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

1919
tmp.setGracefulCleanup();
2020

2121
function getOmnisharpAssetName(): string {
2222
switch (process.platform) {
2323
case 'win32':
24-
return 'omnisharp-win-x64-dnx451.zip';
24+
return 'omnisharp-win-x64-net451.zip';
2525
case 'darwin':
26-
return 'omnisharp-osx-x64-dnxcore50.tar.gz';
26+
return 'omnisharp-osx-x64-netcoreapp1.0.tar.gz';
2727
case 'linux':
28-
return 'omnisharp-linux-x64-dnxcore50.tar.gz';
28+
return 'omnisharp-linux-x64-netcoreapp1.0.tar.gz';
2929
default:
3030
throw new Error(`Unsupported platform: ${process.platform}`);
3131
}

src/protocol.ts

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -263,19 +263,26 @@ export interface DnxFramework {
263263

264264
export interface DotNetWorkspaceInformation {
265265
Projects: DotNetProject[];
266+
RuntimePath: string;
266267
}
267268

268269
export interface DotNetProject {
269270
Path: string;
270-
Name: string;
271-
TargetFramework: DotNetFramework;
272-
CompilationOutputPath: string;
273-
CompilationOutputAssemblyFile: string;
274-
CompilationOutputPdbFile: string;
275-
EmitEntryPoint?: boolean;
271+
Name: string;
272+
ProjectSearchPaths: string[];
273+
Configurations: DotNetConfiguration[];
274+
Frameworks: DotNetFramework[];
276275
SourceFiles: string[];
277276
}
278277

278+
export interface DotNetConfiguration {
279+
Name: string;
280+
CompilationOutputPath: string;
281+
CompilationOutputAssemblyFile: string;
282+
CompilationOutputPdbFile: string;
283+
EmitEntryPoint?: boolean;
284+
}
285+
279286
export interface DotNetFramework {
280287
Name: string;
281288
FriendlyName: string;

0 commit comments

Comments
 (0)