Skip to content

Commit

Permalink
Adding ConfigurationProvider
Browse files Browse the repository at this point in the history
${workspaceRoot} is now ${workspaceFolder}

ConfigurationProvider activates on f5. This will also trigger generating
a tasks file.

tasks args are now 'build <path>', updating tests for these changes.
  • Loading branch information
WardenGnaw committed Oct 23, 2017
1 parent f14dc57 commit bf323df
Show file tree
Hide file tree
Showing 10 changed files with 174 additions and 125 deletions.
6 changes: 3 additions & 3 deletions debugger-launchjson.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ This will create a task that runs `dotnet build`. You can read more about tasks
## Program
The program field is set to the path of the application dll or .NET Core host executable to launch.

This property normally takes the form: "${workspaceRoot}/bin/Debug/\<target-framework\>/\<project-name.dll\>".
This property normally takes the form: "${workspaceFolder}/bin/Debug/\<target-framework\>/\<project-name.dll\>".

Example: `"${workspaceRoot}/bin/Debug/netcoreapp1.1/MyProject.dll"`
Example: `"${workspaceFolder}/bin/Debug/netcoreapp1.1/MyProject.dll"`

Where:

Expand Down Expand Up @@ -102,7 +102,7 @@ then add the pipeTransport field folloing this schema:
"pipeProgram": "ssh",
"pipeArgs": [ "-T", "ExampleAccount@ExampleTargetComputer" ],
"debuggerPath": "~/vsdbg/vsdbg",
"pipeCwd": "${workspaceRoot}",
"pipeCwd": "${workspaceFolder}",
"quoteArgs": true
}

Expand Down
2 changes: 1 addition & 1 deletion debugger.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ If your code has multiple projects or you would rather generate these files by h
"configurations": [
{
...
"program": "${workspaceRoot}/MyLaunchingProject/bin/Debug/netcoreapp1.0/MyLaunchingProject.dll",
"program": "${workspaceFolder}/MyLaunchingProject/bin/Debug/netcoreapp1.0/MyLaunchingProject.dll",

##### 4: Start debugging
Your project is now all set. Set a breakpoint or two where you want to stop, click the debugger play button (or press <kbd>F5</kbd>) and you are off.
Expand Down
78 changes: 39 additions & 39 deletions package.json

Large diffs are not rendered by default.

48 changes: 23 additions & 25 deletions src/assets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,10 +126,10 @@ export class AssetGenerator {
private computeProgramPath() {
if (!this.hasProject) {
// If there's no target project data, use a placeholder for the path.
return '${workspaceRoot}/bin/Debug/<insert-target-framework-here>/<insert-project-name-here>.dll';
return '${workspaceFolder}/bin/Debug/<insert-target-framework-here>/<insert-project-name-here>.dll';
}

let result = '${workspaceRoot}';
let result = '${workspaceFolder}';

if (this.projectPath) {
result = path.join(result, path.relative(this.rootPath, this.projectPath));
Expand All @@ -143,10 +143,10 @@ export class AssetGenerator {
private computeWorkingDirectory() : string {
if (!this.hasProject) {
// If there's no target project data, use a placeholder for the path.
return '${workspaceRoot}';
return '${workspaceFolder}';
}

let result = '${workspaceRoot}';
let result = '${workspaceFolder}';

if (this.projectPath) {
result = path.join(result, path.relative(this.rootPath, this.projectPath));
Expand Down Expand Up @@ -186,7 +186,7 @@ export class AssetGenerator {
"ASPNETCORE_ENVIRONMENT": "Development"
},
"sourceFileMap": {
"/Views": "\${workspaceRoot}/Views"
"/Views": "\${workspaceFolder}/Views"
}
}`;
}
Expand Down Expand Up @@ -215,11 +215,11 @@ export class AssetGenerator {
private createBuildTaskDescription(): tasks.TaskDescription {
let buildPath = '';
if (this.hasProject) {
buildPath = path.join('${workspaceRoot}', path.relative(this.rootPath, this.projectFilePath));
buildPath = path.join('${workspaceFolder}', path.relative(this.rootPath, this.projectFilePath));
}

return {
taskName: 'dotnet: build',
taskName: 'build',
command: 'dotnet',
type: 'process',
args: ['build', util.convertNativePathToPosix(buildPath)],
Expand All @@ -230,28 +230,26 @@ export class AssetGenerator {
public createTasksConfiguration(): tasks.TaskConfiguration {
return {
version: "2.0.0",
command: "dotnet",
type: "process",
tasks: [this.createBuildTaskDescription()]
};
}
}

export function createLaunchConfiguration(programPath: string, workingDirectory: string): string {
export function createLaunchConfiguration(programPath: string, workingDirectory: string): string {
return `
{
"name": ".NET Core Launch (console)",
"type": "coreclr",
"request": "launch",
"preLaunchTask": "build",
// If you have changed target frameworks, make sure to update the program path.
"program": "${util.convertNativePathToPosix(programPath)}",
"args": [],
"cwd": "${util.convertNativePathToPosix(workingDirectory)}",
// For more information about the 'console' field, see https://github.com/OmniSharp/omnisharp-vscode/blob/master/debugger-launchjson.md#console-terminal-window
"console": "internalConsole",
"stopAtEntry": false,
"internalConsoleOptions": "openOnSessionStart"
"name": ".NET Core Launch (console)",
"type": "coreclr",
"request": "launch",
"preLaunchTask": "build",
// If you have changed target frameworks, make sure to update the program path.
"program": "${util.convertNativePathToPosix(programPath)}",
"args": [],
"cwd": "${util.convertNativePathToPosix(workingDirectory)}",
// For more information about the 'console' field, see https://github.com/OmniSharp/omnisharp-vscode/blob/master/debugger-launchjson.md#console-terminal-window
"console": "internalConsole",
"stopAtEntry": false,
"internalConsoleOptions": "openOnSessionStart"
}`;
}

Expand All @@ -264,7 +262,7 @@ export function createAttachConfiguration(): string {
"request": "attach",
"processId": "\${command:pickProcess}"
}`;
}
}

function findExecutableMSBuildProjects(projects: protocol.MSBuildProject[]) {
let result: protocol.MSBuildProject[] = [];
Expand Down Expand Up @@ -294,7 +292,7 @@ function findExecutableProjectJsonProjects(projects: protocol.DotNetProject[], c
return result;
}

function containsDotNetCoreProjects(workspaceInfo: protocol.WorkspaceInformationResponse) {
export function containsDotNetCoreProjects(workspaceInfo: protocol.WorkspaceInformationResponse) {
if (workspaceInfo.DotNet && findExecutableProjectJsonProjects(workspaceInfo.DotNet.Projects, 'Debug').length > 0) {
return true;
}
Expand Down Expand Up @@ -421,7 +419,7 @@ function promptToAddAssets() {
});
}

function addTasksJsonIfNecessary(generator: AssetGenerator, operations: Operations) {
export function addTasksJsonIfNecessary(generator: AssetGenerator, operations: Operations) {
return new Promise<void>((resolve, reject) => {
if (!operations.addTasksJson) {
return resolve();
Expand Down
67 changes: 59 additions & 8 deletions src/configurationProvider.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,74 @@
import * as vscode from 'vscode';
import * as fs from 'fs-extra';
import * as path from 'path';
import { parse } from 'jsonc-parser';
import { createLaunchConfiguration, createAttachConfiguration } from './assets';
import { OmniSharpServer } from './omnisharp/server';
import * as serverUtils from './omnisharp/utils';
import { AssetGenerator, addTasksJsonIfNecessary, createLaunchConfiguration, createAttachConfiguration, containsDotNetCoreProjects} from './assets';
import { WorkspaceInformationResponse } from './omnisharp/protocol';

export class CSharpConfigurationProvider implements vscode.DebugConfigurationProvider {
private server: OmniSharpServer;

public constructor(server: OmniSharpServer) {
this.server = server;
}

/**
* TODO: Remove function.
*
* Note: serverUtils.requestWorkspaceInformation only retrieves one project. Therefore, generator will be incorrect for all folders
* except the first in a workspace.
*/
private checkWorkspaceInformationMatchesWorkspaceFolder(folder: vscode.WorkspaceFolder, info: WorkspaceInformationResponse): boolean {
return info.MsBuild.SolutionPath === folder.uri.fsPath;
}

/**
* Returns an initial debug configuration based on contextual information, e.g. package.json or folder.
* Returns a list of initial debug configurations based on contextual information, e.g. package.json or folder.
*/
provideDebugConfigurations(folder: vscode.WorkspaceFolder | undefined, token?: vscode.CancellationToken): vscode.ProviderResult<vscode.DebugConfiguration[]> {
// jsonc-parser's parse function parses a JSON string with comments into a JSON object.
return [
parse(createLaunchConfiguration("${workspaceFolder}/bin/Debug/<insert-target-framework-here>/<insert-project-name-here>.dll", '${workspaceFolder}')),
parse(createAttachConfiguration())
];
return serverUtils.requestWorkspaceInformation(this.server).then(info => {
const generator = new AssetGenerator(info);
if (this.checkWorkspaceInformationMatchesWorkspaceFolder(folder, info) && containsDotNetCoreProjects(info)){
const dotVscodeFolder: string = path.join(folder.uri.fsPath, '.vscode');
const tasksJsonPath: string = path.join(dotVscodeFolder, 'tasks.json');

// Make sure .vscode folder exists, addTasksJsonIfNecessary will fail to create tasks.json if the folder does not exist.
fs.ensureDirSync(dotVscodeFolder);

// if the file does not exist, addTasksJson
const addTasksJson: boolean = !fs.existsSync(tasksJsonPath);

return addTasksJsonIfNecessary(generator, {addTasksJson: addTasksJson}).then(() => {
const isWebProject = generator.hasWebServerDependency();
const launchJson: string = generator.createLaunchJson(isWebProject);

// jsonc-parser's parse function parses a JSON string with comments into a JSON object. However, this removes the comments.
return parse(launchJson);
});
}
else {
// Error to write default C# configurations.
throw new Error("Does not contain dotnet core projects.");
}
}).catch((err) => {
// Provider will always create an launch.json file. Providing default C# configurations.
// jsonc-parser's parse to convert to JSON object without comments.
return [
parse(createLaunchConfiguration(
"${workspaceFolder}/bin/Debug/<insert-target-framework-here>/<insert-project-name-here>.dll",
'${workspaceFolder}')),
parse(createAttachConfiguration())
];
});
}

/**
* Try to add all missing attributes to the debug configuration being launched.
*/
resolveDebugConfiguration(folder: vscode.WorkspaceFolder | undefined, config: vscode.DebugConfiguration, token?: vscode.CancellationToken): vscode.ProviderResult<vscode.DebugConfiguration> {
return null;
// vsdbg does the error checking
return config;
}
}
2 changes: 1 addition & 1 deletion src/omnisharp/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ export function activate(context: vscode.ExtensionContext, reporter: TelemetryRe
}));

// Register ConfigurationProvider
disposables.push(vscode.debug.registerDebugConfigurationProvider('coreclr', new CSharpConfigurationProvider()));
disposables.push(vscode.debug.registerDebugConfigurationProvider('coreclr', new CSharpConfigurationProvider(server)));

context.subscriptions.push(...disposables);
}
20 changes: 10 additions & 10 deletions src/tools/OptionsSchema.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@
"type": "object",
"description": "Platform-specific pipe launch configuration options",
"default": {
"pipeCwd": "${workspaceRoot}",
"pipeCwd": "${workspaceFolder}",
"pipeProgram": "enter the fully qualified path for the pipe program name, for example '/usr/bin/ssh'",
"pipeArgs": []
},
"properties": {
"pipeCwd": {
"type": "string",
"description": "The fully qualified path to the working directory for the pipe program.",
"default": "${workspaceRoot}"
"default": "${workspaceFolder}"
},
"pipeProgram": {
"type": "string",
Expand Down Expand Up @@ -61,7 +61,7 @@
"required": ["debuggerPath"],
"description": "When present, this tells the debugger to connect to a remote computer using another executable as a pipe that will relay standard input/output between VS Code and the .NET Core debugger backend executable (vsdbg).",
"default": {
"pipeCwd": "${workspaceRoot}",
"pipeCwd": "${workspaceFolder}",
"pipeProgram": "enter the fully qualified path for the pipe program name, for example '/usr/bin/ssh'",
"pipeArgs": [],
"debuggerPath" : "enter the path for the debugger on the target machine, for example ~/vsdbg/vsdbg"
Expand All @@ -70,7 +70,7 @@
"pipeCwd": {
"type": "string",
"description": "The fully qualified path to the working directory for the pipe program.",
"default": "${workspaceRoot}"
"default": "${workspaceFolder}"
},
"pipeProgram": {
"type": "string",
Expand Down Expand Up @@ -116,7 +116,7 @@
"$ref": "#/definitions/PipeConfigurations",
"description": "Windows-specific pipe launch configuration options",
"default": {
"pipeCwd": "${workspaceRoot}",
"pipeCwd": "${workspaceFolder}",
"pipeProgram": "enter the fully qualified path for the pipe program name, for example 'c:\\tools\\plink.exe'",
"pipeArgs": []
}
Expand All @@ -125,7 +125,7 @@
"$ref": "#/definitions/PipeConfigurations",
"description": "OSX-specific pipe launch configuration options",
"default": {
"pipeCwd": "${workspaceRoot}",
"pipeCwd": "${workspaceFolder}",
"pipeProgram": "enter the fully qualified path for the pipe program name, for example '/usr/bin/ssh'",
"pipeArgs": []
}
Expand All @@ -134,7 +134,7 @@
"$ref": "#/definitions/PipeConfigurations",
"description": "Linux-specific pipe launch configuration options",
"default": {
"pipeCwd": "${workspaceRoot}",
"pipeCwd": "${workspaceFolder}",
"pipeProgram": "enter the fully qualified path for the pipe program name, for example '/usr/bin/ssh'",
"pipeArgs": []
}
Expand Down Expand Up @@ -261,13 +261,13 @@
"properties": {
"program": {
"type": "string",
"description": "Path to the application dll or .NET Core host executable to launch.\nThis property normally takes the form: '${workspaceRoot}/bin/Debug/(target-framework)/(project-name.dll)'\nExample: '${workspaceRoot}/bin/Debug/netcoreapp1.1/MyProject.dll'\n\nWhere:\n(target-framework) is the framework that the debugged project is being built for. This is normally found in the project file as the 'TargetFramework' property.\n(project-name.dll) is the name of debugged project's build output dll. This is normally the same as the project file name but with a '.dll' extension.",
"default": "${workspaceRoot}/bin/Debug/<insert-target-framework-here>/<insert-project-name-here>.dll"
"description": "Path to the application dll or .NET Core host executable to launch.\nThis property normally takes the form: '${workspaceFolder}/bin/Debug/(target-framework)/(project-name.dll)'\nExample: '${workspaceFolder}/bin/Debug/netcoreapp1.1/MyProject.dll'\n\nWhere:\n(target-framework) is the framework that the debugged project is being built for. This is normally found in the project file as the 'TargetFramework' property.\n(project-name.dll) is the name of debugged project's build output dll. This is normally the same as the project file name but with a '.dll' extension.",
"default": "${workspaceFolder}/bin/Debug/<insert-target-framework-here>/<insert-project-name-here>.dll"
},
"cwd": {
"type": "string",
"description": "Path to the working directory of the program being debugged. Default is the current workspace.",
"default": "${workspaceRoot}"
"default": "${workspaceFolder}"
},
"args": {
"anyOf": [
Expand Down
Loading

0 comments on commit bf323df

Please sign in to comment.