Skip to content

Commit 1c2b569

Browse files
Generate correct values into launch.json
1 parent a46b54a commit 1c2b569

File tree

4 files changed

+63
-53
lines changed

4 files changed

+63
-53
lines changed

src/assets.ts

Lines changed: 49 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ import * as fs from 'fs-extra-promise';
99
import * as path from 'path';
1010
import * as vscode from 'vscode';
1111
import * as tasks from 'vscode-tasks';
12+
import {OmnisharpServer} from './omnisharpServer';
13+
import * as serverUtils from './omnisharpUtils';
14+
import * as protocol from './protocol.ts'
1215

1316
interface DebugConfiguration {
1417
name: string,
@@ -125,26 +128,26 @@ function promptToAddAssets() {
125128
});
126129
}
127130

128-
function createLaunchConfiguration(): ConsoleLaunchConfiguration {
131+
function createLaunchConfiguration(targetFramework: string, executableName: string): ConsoleLaunchConfiguration {
129132
return {
130133
name: '.NET Core Launch (console)',
131134
type: 'coreclr',
132135
request: 'launch',
133136
preLaunchTask: 'build',
134-
program: '${workspaceRoot}/bin/Debug/<target-framework>/<project-name.dll>',
137+
program: '${workspaceRoot}/bin/Debug/' + targetFramework + '/'+ executableName,
135138
args: [],
136139
cwd: '${workspaceRoot}',
137140
stopAtEntry: false
138141
}
139142
}
140143

141-
function createWebLaunchConfiguration(): WebLaunchConfiguration {
144+
function createWebLaunchConfiguration(targetFramework: string, executableName: string): WebLaunchConfiguration {
142145
return {
143146
name: '.NET Core Launch (web)',
144147
type: 'coreclr',
145148
request: 'launch',
146149
preLaunchTask: 'build',
147-
program: '${workspaceRoot}/bin/Debug/<target-framework>/<project-name.dll>',
150+
program: '${workspaceRoot}/bin/Debug/' + targetFramework + '/'+ executableName,
148151
args: [],
149152
cwd: '${workspaceRoot}',
150153
stopAtEntry: false,
@@ -167,19 +170,19 @@ function createWebLaunchConfiguration(): WebLaunchConfiguration {
167170

168171
function createAttachConfiguration(): AttachConfiguration {
169172
return {
170-
name: '.NET Core Attack',
173+
name: '.NET Core Attach',
171174
type: 'coreclr',
172175
request: 'attach',
173176
processName: '<example>'
174177
}
175178
}
176179

177-
function createLaunchJson(): any {
180+
function createLaunchJson(targetFramework: string, executableName: string): any {
178181
return {
179182
version: '0.2.0',
180183
configurations: [
181-
createLaunchConfiguration(),
182-
createWebLaunchConfiguration(),
184+
createLaunchConfiguration(targetFramework, executableName),
185+
createWebLaunchConfiguration(targetFramework, executableName),
183186
createAttachConfiguration()
184187
]
185188
}
@@ -204,7 +207,7 @@ function createTasksConfiguration(): tasks.TaskConfiguration {
204207
};
205208
}
206209

207-
function addTasksJsonIfNecessary(paths: Paths, operations: Operations) {
210+
function addTasksJsonIfNecessary(info: protocol.DotNetWorkspaceInformation, paths: Paths, operations: Operations) {
208211
return new Promise<void>((resolve, reject) => {
209212
if (!operations.addTasksJson) {
210213
return resolve();
@@ -217,66 +220,63 @@ function addTasksJsonIfNecessary(paths: Paths, operations: Operations) {
217220
});
218221
}
219222

220-
function updateTasksJsonIfNecesssary(paths: Paths, operations: Operations) {
223+
function addLaunchJsonIfNecessary(info: protocol.DotNetWorkspaceInformation, paths: Paths, operations: Operations) {
221224
return new Promise<void>((resolve, reject) => {
222-
if (!operations.updateTasksJson) {
225+
if (!operations.addLaunchJson) {
223226
return resolve();
224227
}
225228

226-
return fs.readFileAsync(paths.tasksJsonPath).then(buffer => {
227-
const bufferText = buffer.toString();
228-
const tasksJson: tasks.TaskConfiguration = JSON.parse(bufferText);
229-
tasksJson.tasks.push(createBuildTaskDescription());
230-
const tasksJsonText = JSON.stringify(tasksJson, null, ' ');
231-
232-
return fs.writeFileAsync(paths.tasksJsonPath, tasksJsonText);
233-
});
234-
});
235-
}
229+
let targetFramework = '<target-framework>';
230+
let executableName = '<project-name.dll>';
231+
232+
let projectWithEntryPoint = info.Projects.find(project => project.EmitEntryPoint === true);
236233

237-
function addLaunchJsonIfNecessary(paths: Paths, operations: Operations) {
238-
return new Promise<void>((resolve, reject) => {
239-
if (!operations.addLaunchJson) {
240-
return resolve();
234+
if (projectWithEntryPoint) {
235+
targetFramework = projectWithEntryPoint.TargetFramework.ShortName;
236+
executableName = path.basename(projectWithEntryPoint.CompilationOutputAssemblyFile);
241237
}
242238

243-
const launchJson = createLaunchJson();
239+
const launchJson = createLaunchJson(targetFramework, executableName);
244240
const launchJsonText = JSON.stringify(launchJson, null, ' ');
245241

246242
return fs.writeFileAsync(paths.launchJsonPath, launchJsonText);
247243
});
248244
}
249245

250-
export function addAssetsIfNecessary() {
246+
export function addAssetsIfNecessary(server: OmnisharpServer) {
251247
if (!vscode.workspace.rootPath) {
252248
return;
253249
}
254250

255-
// If there is no project.json, we won't bother to prompt the user for tasks.json.
256-
const projectJsonPath = path.join(vscode.workspace.rootPath, 'project.json');
251+
// If there is no project.json, we won't bother to prompt the user for tasks.json.
252+
const projectJsonPath = path.join(vscode.workspace.rootPath, 'project.json');
257253
if (!fs.existsSync(projectJsonPath)) {
258254
return;
259255
}
260-
261-
return getOperations().then(operations => {
262-
if (!hasOperations(operations)) {
263-
return;
264-
}
265-
266-
promptToAddAssets().then(addAssets => {
267-
if (!addAssets) {
268-
return;
269-
}
270-
271-
const paths = getPaths();
272-
273-
return fs.ensureDirAsync(paths.vscodeFolder).then(() => {
274-
return Promise.all([
275-
addTasksJsonIfNecessary(paths, operations),
276-
updateTasksJsonIfNecesssary(paths, operations),
277-
addLaunchJsonIfNecessary(paths, operations)
278-
]);
256+
257+
return serverUtils.requestWorkspaceInformation(server).then(info => {
258+
// 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) {
260+
return getOperations().then(operations => {
261+
if (!hasOperations(operations)) {
262+
return;
263+
}
264+
265+
promptToAddAssets().then(addAssets => {
266+
if (!addAssets) {
267+
return;
268+
}
269+
270+
const paths = getPaths();
271+
272+
return fs.ensureDirAsync(paths.vscodeFolder).then(() => {
273+
return Promise.all([
274+
addTasksJsonIfNecessary(info.DotNet, paths, operations),
275+
addLaunchJsonIfNecessary(info.DotNet, paths, operations)
276+
]);
277+
});
278+
});
279279
});
280-
});
280+
}
281281
});
282282
}

src/omnisharpMain.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,11 @@ export function activate(context: vscode.ExtensionContext): any {
7474

7575
disposables.push(registerCommands(server, context.extensionPath));
7676
disposables.push(reportStatus(server));
77+
78+
disposables.push(server.onServerStart(() => {
79+
// Update or add tasks.json and launch.json
80+
addAssetsIfNecessary(server);
81+
}));
7782

7883
// read and store last solution or folder path
7984
disposables.push(server.onBeforeServerStart(path => context.workspaceState.update('lastSolutionPathOrFolder', path)));
@@ -86,9 +91,6 @@ export function activate(context: vscode.ExtensionContext): any {
8691
server.stop();
8792
}));
8893

89-
// Update or add tasks.json and launch.json
90-
addAssetsIfNecessary();
91-
9294
// install coreclr-debug
9395
installCoreClrDebug(context, reporter);
9496

src/omnisharpServer.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -268,8 +268,8 @@ export abstract class OmnisharpServer {
268268
this._serverProcess = value.process;
269269
this._requestDelays = {};
270270
this._fireEvent(Events.StdOut, `[INFO] Started OmniSharp from '${value.command}' with process id ${value.process.pid}...\n`);
271-
this._fireEvent(Events.ServerStart, solutionPath);
272271
this._setState(ServerState.Started);
272+
this._fireEvent(Events.ServerStart, solutionPath);
273273
return this._doConnect();
274274
}).then(_ => {
275275
this._processQueue();

src/protocol.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,12 +268,20 @@ export interface DotNetWorkspaceInformation {
268268
export interface DotNetProject {
269269
Path: string;
270270
Name: string;
271+
TargetFramework: DotNetFramework;
271272
CompilationOutputPath: string;
272273
CompilationOutputAssemblyFile: string;
273274
CompilationOutputPdbFile: string;
275+
EmitEntryPoint?: boolean;
274276
SourceFiles: string[];
275277
}
276278

279+
export interface DotNetFramework {
280+
Name: string;
281+
FriendlyName: string;
282+
ShortName: string;
283+
}
284+
277285
export interface RenameRequest extends Request {
278286
RenameTo: string;
279287
WantsTextChanges?: boolean;

0 commit comments

Comments
 (0)