Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Intelli-sense in extensions file #26564

Merged
merged 5 commits into from
May 17, 2017
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 26 additions & 2 deletions extensions/configuration-editing/src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ export function activate(context): void {
//settings.json suggestions
context.subscriptions.push(registerSettingsCompletions());

//extensions.json suggestions
context.subscriptions.push(registerExtensionsCompletions());

// launch.json decorations
context.subscriptions.push(vscode.window.onDidChangeActiveTextEditor(editor => updateLaunchJsonDecorations(editor), null, context.subscriptions));
context.subscriptions.push(vscode.workspace.onDidChangeTextDocument(event => {
Expand Down Expand Up @@ -61,11 +64,32 @@ function registerSettingsCompletions(): vscode.Disposable {
});
}

function newSimpleCompletionItem(text: string, range: vscode.Range, description?: string): vscode.CompletionItem {
function registerExtensionsCompletions(): vscode.Disposable {
return vscode.languages.registerCompletionItemProvider({ pattern: '**/extensions.json' }, {
provideCompletionItems(document, position, token) {
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');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do not thinkvscode.workspace.getConfiguration('extensions.json') will get the extension recommendations.
You might have to read the document and parse it. You already have document with text, so you can just use parse from jsonc-parser to get the existing recommendations.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok. It's my first try to do something in vscode source. Sorry. I pushed another try.

const alreadyEnteredExtensions = config.get<string[]>('recommendations') || [];
return vscode.extensions.all
.filter(e => !(
e.id.startsWith('vscode.')
|| e.id === 'Microsoft.vscode-markdown'
|| alreadyEnteredExtensions.indexOf(e.id) > -1
))
.map(e => newSimpleCompletionItem(e.id, range, undefined, '"' + e.id + '"'));
}
return [];
}
});
}

function newSimpleCompletionItem(text: string, range: vscode.Range, description?: string, insertText?: string): vscode.CompletionItem {
const item = new vscode.CompletionItem(text);
item.kind = vscode.CompletionItemKind.Value;
item.detail = description;
item.insertText = text;
item.insertText = insertText || text;
item.range = range;

return item;
Expand Down