mirror of
https://github.com/microsoft/vscode.git
synced 2026-05-08 17:19:48 +01:00
JSON edit deletes comments. fixes #6725
This commit is contained in:
@@ -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) {
|
||||
|
||||
@@ -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', () => {
|
||||
|
||||
Reference in New Issue
Block a user