Fix #71392 - remove autofixing commas in settings.json
This commit is contained in:
parent
fc07ea96e9
commit
8bd5e2f93d
|
@ -3,12 +3,12 @@
|
||||||
* Licensed under the MIT License. See License.txt in the project root for license information.
|
* Licensed under the MIT License. See License.txt in the project root for license information.
|
||||||
*--------------------------------------------------------------------------------------------*/
|
*--------------------------------------------------------------------------------------------*/
|
||||||
|
|
||||||
import * as nls from 'vscode-nls';
|
import { getLocation, parse, visit } from 'jsonc-parser';
|
||||||
const localize = nls.loadMessageBundle();
|
|
||||||
import * as vscode from 'vscode';
|
|
||||||
import { getLocation, visit, parse, ParseErrorCode } from 'jsonc-parser';
|
|
||||||
import * as path from 'path';
|
import * as path from 'path';
|
||||||
|
import * as vscode from 'vscode';
|
||||||
|
import * as nls from 'vscode-nls';
|
||||||
import { SettingsDocument } from './settingsDocumentHelper';
|
import { SettingsDocument } from './settingsDocumentHelper';
|
||||||
|
const localize = nls.loadMessageBundle();
|
||||||
|
|
||||||
const fadedDecoration = vscode.window.createTextEditorDecorationType({
|
const fadedDecoration = vscode.window.createTextEditorDecorationType({
|
||||||
light: {
|
light: {
|
||||||
|
@ -45,50 +45,6 @@ export function activate(context: vscode.ExtensionContext): void {
|
||||||
}
|
}
|
||||||
}, null, context.subscriptions));
|
}, null, context.subscriptions));
|
||||||
updateLaunchJsonDecorations(vscode.window.activeTextEditor);
|
updateLaunchJsonDecorations(vscode.window.activeTextEditor);
|
||||||
|
|
||||||
context.subscriptions.push(vscode.workspace.onWillSaveTextDocument(e => {
|
|
||||||
if (!e.document.fileName.endsWith('/settings.json')) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
autoFixSettingsJSON(e);
|
|
||||||
}));
|
|
||||||
}
|
|
||||||
|
|
||||||
function autoFixSettingsJSON(willSaveEvent: vscode.TextDocumentWillSaveEvent): void {
|
|
||||||
const document = willSaveEvent.document;
|
|
||||||
const text = document.getText();
|
|
||||||
const edit = new vscode.WorkspaceEdit();
|
|
||||||
|
|
||||||
let lastEndOfSomething = -1;
|
|
||||||
visit(text, {
|
|
||||||
onArrayEnd(offset: number, length: number): void {
|
|
||||||
lastEndOfSomething = offset + length;
|
|
||||||
},
|
|
||||||
|
|
||||||
onLiteralValue(_value: any, offset: number, length: number): void {
|
|
||||||
lastEndOfSomething = offset + length;
|
|
||||||
},
|
|
||||||
|
|
||||||
onObjectEnd(offset: number, length: number): void {
|
|
||||||
lastEndOfSomething = offset + length;
|
|
||||||
},
|
|
||||||
|
|
||||||
onError(error: ParseErrorCode, _offset: number, _length: number): void {
|
|
||||||
if (error === ParseErrorCode.CommaExpected && lastEndOfSomething > -1) {
|
|
||||||
const fixPosition = document.positionAt(lastEndOfSomething);
|
|
||||||
|
|
||||||
// Don't insert a comma immediately before a : or ' :'
|
|
||||||
const colonRange = document.getWordRangeAtPosition(fixPosition, / *:/);
|
|
||||||
if (!colonRange) {
|
|
||||||
edit.insert(document.uri, fixPosition, ',');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
willSaveEvent.waitUntil(
|
|
||||||
vscode.workspace.applyEdit(edit));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function registerSettingsCompletions(): vscode.Disposable {
|
function registerSettingsCompletions(): vscode.Disposable {
|
||||||
|
|
Loading…
Reference in a new issue