using json-parser to get existing recommendations

This commit is contained in:
Fernando Tolentino 2017-05-16 15:32:12 -03:00
parent ba578c15de
commit ebb5c05734

View file

@ -6,7 +6,7 @@
'use strict';
import * as vscode from 'vscode';
import { getLocation, visit } from 'jsonc-parser';
import { getLocation, visit, parse } from 'jsonc-parser';
import * as path from 'path';
import { SettingsDocument } from './settingsDocumentHelper';
@ -70,8 +70,9 @@ function registerExtensionsCompletions(): vscode.Disposable {
const location = getLocation(document.getText(), document.offsetAt(position));
const range = document.getWordRangeAtPosition(position) || new vscode.Range(position, position);
if (location.path[0] === 'recommendations') {
const config = vscode.workspace && vscode.workspace.getConfiguration('extensions.json');
const alreadyEnteredExtensions = config.get<string[]>('recommendations') || [];
const config = parse(document.getText());
const alreadyEnteredExtensions = config && config.recommendations || [];
if (Array.isArray(alreadyEnteredExtensions)) {
return vscode.extensions.all
.filter(e => !(
e.id.startsWith('vscode.')
@ -80,6 +81,7 @@ function registerExtensionsCompletions(): vscode.Disposable {
))
.map(e => newSimpleCompletionItem(e.id, range, undefined, '"' + e.id + '"'));
}
}
return [];
}
});