Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
4 changes: 4 additions & 0 deletions Extension/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# C/C++ for Visual Studio Code Change Log

## Version 0.22.1: March 20, 2019
* Fix `tasks.json` with single-line comments being overwritten when `Build and Debug Active File` is used. [#3327](https://github.com/Microsoft/vscode-cpptools/issues/3327)
* Fix an invalid `compilerPath` property getting added to `tasks.json` after doing `Configure Task` with a C/C++ compiler.

## Version 0.22.0: March 19, 2019
### Major Changes
* Add warning squiggles for invalid properties and paths in `c_cpp_properties.json`. [#2799](https://github.com/Microsoft/vscode-cpptools/issues/2799), [PR #3283](https://github.com/Microsoft/vscode-cpptools/pull/3283)
Expand Down
2 changes: 1 addition & 1 deletion Extension/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "cpptools",
"displayName": "C/C++",
"description": "C/C++ IntelliSense, debugging, and code browsing.",
"version": "0.22.0-master",
"version": "0.22.1-master",
"publisher": "ms-vscode",
"preview": true,
"icon": "LanguageCCPP_color_128x.png",
Expand Down
2 changes: 1 addition & 1 deletion Extension/src/Debugger/configurationProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ class CppConfigurationProvider implements vscode.DebugConfigurationProvider {
* Returns a list of initial debug configurations based on contextual information, e.g. package.json or folder.
*/
async provideDebugConfigurations(folder: vscode.WorkspaceFolder | undefined, token?: vscode.CancellationToken): Promise<vscode.DebugConfiguration[]> {
let buildTasks: vscode.Task[] = await getBuildTasks();
let buildTasks: vscode.Task[] = await getBuildTasks(true);
if (buildTasks.length === 0) {
return Promise.resolve(this.provider.getInitialConfigurations(this.type));
}
Expand Down
5 changes: 4 additions & 1 deletion Extension/src/Debugger/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,12 +91,15 @@ export function initialize(context: vscode.ExtensionContext): void {
await util.ensureBuildTaskExists(selection.configuration.preLaunchTask);
Telemetry.logDebuggerEvent("buildAndDebug", { "success": "false" });
} catch (e) {
if (e && e.message === util.failedToParseTasksJson) {
vscode.window.showErrorMessage(util.failedToParseTasksJson);
}
return Promise.resolve();
}
} else {
return Promise.resolve();
// TODO uncomment this when single file mode works correctly.
// const buildTasks: vscode.Task[] = await getBuildTasks();
// const buildTasks: vscode.Task[] = await getBuildTasks(true);
// const task: vscode.Task = buildTasks.find(task => task.name === selection.configuration.preLaunchTask);
// await vscode.tasks.executeTask(task);
// delete selection.configuration.preLaunchTask;
Expand Down
8 changes: 6 additions & 2 deletions Extension/src/LanguageServer/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ export function activate(activationEventOccurred: boolean): void {

taskProvider = vscode.tasks.registerTaskProvider(taskSourceStr, {
provideTasks: () => {
return getBuildTasks();
return getBuildTasks(false);
},
resolveTask(task: vscode.Task): vscode.Task {
// Currently cannot implement because VS Code does not call this. Can implement custom output file directory when enabled.
Expand Down Expand Up @@ -114,7 +114,7 @@ export interface BuildTaskDefinition extends vscode.TaskDefinition {
/**
* Generate tasks to build the current file based on the user's detected compilers, the user's compilerPath setting, and the current file's extension.
*/
export async function getBuildTasks(): Promise<vscode.Task[]> {
export async function getBuildTasks(returnComplerPath: boolean): Promise<vscode.Task[]> {
const editor: vscode.TextEditor = vscode.window.activeTextEditor;
if (!editor) {
return [];
Expand Down Expand Up @@ -243,6 +243,10 @@ export async function getBuildTasks(): Promise<vscode.Task[]> {
task.definition = kind; // The constructor for vscode.Task will eat the definition. Reset it by reassigning.
task.group = vscode.TaskGroup.Build;

if (!returnComplerPath) {
delete task.definition.compilerPath;
}

return task;
});
}
Expand Down
16 changes: 7 additions & 9 deletions Extension/src/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ export function setExtensionContext(context: vscode.ExtensionContext): void {
extensionContext = context;
}

export const failedToParseTasksJson: string = "Failed to parse tasks.json, possibly due to comments or trailing commas.";

// Use this package.json to read values
export const packageJson: any = vscode.extensions.getExtension("ms-vscode.cpptools").packageJSON;

Expand All @@ -47,11 +49,13 @@ export function getRawTasksJson(): Promise<any> {
if (!exists) {
return resolve({});
}
const fileContents: Buffer = fs.readFileSync(path);
let fileContents: string = fs.readFileSync(path).toString();
fileContents = fileContents.replace(/^\s*\/\/.*$/gm, ""); // Remove start of line // comments.
let rawTasks: any = {};
try {
rawTasks = JSON.parse(fileContents.toString());
rawTasks = JSON.parse(fileContents);
} catch (error) {
return reject(new Error(failedToParseTasksJson));
}
resolve(rawTasks);
});
Expand All @@ -73,16 +77,10 @@ export async function ensureBuildTaskExists(taskName: string): Promise<void> {
return;
}

const buildTasks: vscode.Task[] = await getBuildTasks();
const buildTasks: vscode.Task[] = await getBuildTasks(false);
selectedTask = buildTasks.find(task => task.name === taskName);
console.assert(selectedTask);

let definition: vscode.TaskDefinition = selectedTask.definition as vscode.TaskDefinition;
if (definition && definition.compilerPath) {
// TODO: add desired properties to empty object, don't delete.
delete definition.compilerPath;
}

rawTasksJson.version = "2.0.0";

if (!rawTasksJson.tasks.find(task => { return task.label === selectedTask.definition.label; })) {
Expand Down