Skip to content

Commit 44e5eaa

Browse files
committed
taskProvider threw exception when reading json file with comments - now fixed
1 parent 9dc1eba commit 44e5eaa

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

src/saxonTaskProvider.ts

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,21 @@ export class SaxonTaskProvider implements vscode.TaskProvider {
6767
let rootPath = vscode.workspace.rootPath? vscode.workspace.rootPath: '/';
6868
let tasksPath = path.join(rootPath, '.vscode', 'tasks.json');
6969
let tasksObject = undefined;
70+
7071
if (await exists(tasksPath)) {
71-
delete require.cache[tasksPath];
72-
tasksObject = require(tasksPath);
72+
const tasksText = fs.readFileSync(tasksPath).toString('utf-8');
73+
const taskLines = tasksText.split("\n");
74+
const jsonTaskLines: string[] = [];
75+
taskLines.forEach((taskLine) => {
76+
if (taskLine.trimLeft().startsWith('//')) {
77+
// don't add comment
78+
} else {
79+
jsonTaskLines.push(taskLine);
80+
}
81+
});
82+
const jsonString = jsonTaskLines.join('\n');
83+
tasksObject = JSON.parse(jsonString);
84+
7385
} else {
7486
tasksObject = {tasks: []};
7587
}

0 commit comments

Comments
 (0)