From 462bdd37e5b2dd83d0710d1f4bdfc9bc1f2bb543 Mon Sep 17 00:00:00 2001 From: Martin Aeschlimann Date: Wed, 25 May 2016 14:56:01 +0200 Subject: [PATCH] JSON edit deletes comments. fixes #6725 --- src/vs/base/common/jsonEdit.ts | 2 +- src/vs/base/test/common/jsonEdit.test.ts | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/vs/base/common/jsonEdit.ts b/src/vs/base/common/jsonEdit.ts index d83795e91a3..b02004fd88d 100644 --- a/src/vs/base/common/jsonEdit.ts +++ b/src/vs/base/common/jsonEdit.ts @@ -36,7 +36,7 @@ export function setProperty(text: string, path: JSONPath, value: any, formatting if (value === void 0) { // delete throw new Error('Can not delete in empty document'); } - return withFormatting(text, { offset: root ? root.offset : 0, length: root ? root.length : text.length, content: JSON.stringify(value) }, formattingOptions); + return withFormatting(text, { offset: root ? root.offset : 0, length: root ? root.length : 0, content: JSON.stringify(value) }, formattingOptions); } else if (parent.type === 'object' && typeof lastSegment === 'string') { let existing = findNodeAtLocation(parent, [ lastSegment ]); if (existing !== void 0) { diff --git a/src/vs/base/test/common/jsonEdit.test.ts b/src/vs/base/test/common/jsonEdit.test.ts index 33d1482fa2b..6593efb4df1 100644 --- a/src/vs/base/test/common/jsonEdit.test.ts +++ b/src/vs/base/test/common/jsonEdit.test.ts @@ -83,6 +83,10 @@ suite('JSON - edits', () => { content = ''; edits = setProperty(content, ['foo', 0], 'bar', formatterOptions); assertEdit(content, edits, '{\n "foo": [\n "bar"\n ]\n}'); + + content = '//comment'; + edits = setProperty(content, ['foo', 0], 'bar', formatterOptions); + assertEdit(content, edits, '{\n "foo": [\n "bar"\n ]\n} //comment\n'); }); test('remove property', () => {