Allow users to opt-out of features that send online requests in the background (#55097)

This commit is contained in:
Ramya Rao
2018-07-27 15:42:17 -07:00
committed by GitHub
parent 8ca017eaba
commit f51c30d8f4
6 changed files with 43 additions and 7 deletions

View File

@@ -4,8 +4,8 @@
*--------------------------------------------------------------------------------------------*/
'use strict';
import { MarkedString, CompletionItemKind, CompletionItem, DocumentSelector, SnippetString } from 'vscode';
import { IJSONContribution, ISuggestionsCollector } from './jsonContributions';
import { MarkedString, CompletionItemKind, CompletionItem, DocumentSelector, SnippetString, workspace } from 'vscode';
import { IJSONContribution, ISuggestionsCollector, xhrDisabled } from './jsonContributions';
import { XHRRequest } from 'request-light';
import { Location } from 'jsonc-parser';
import { textToMarkedString } from './markedTextUtil';
@@ -28,12 +28,22 @@ export class PackageJSONContribution implements IJSONContribution {
'jsdom', 'stylus', 'when', 'readable-stream', 'aws-sdk', 'concat-stream', 'chai', 'Thenable', 'wrench'];
private knownScopes = ['@types', '@angular'];
private xhr: XHRRequest;
public getDocumentSelector(): DocumentSelector {
return [{ language: 'json', scheme: '*', pattern: '**/package.json' }];
}
public constructor(private xhr: XHRRequest) {
public constructor(httprequestxhr: XHRRequest) {
const getxhr = () => {
return workspace.getConfiguration('npm').get('fetchOnlinePackageInfo') === false ? xhrDisabled : httprequestxhr;
};
this.xhr = getxhr();
workspace.onDidChangeConfiguration((e) => {
if (e.affectsConfiguration('npm.fetchOnlinePackageInfo')) {
this.xhr = getxhr();
}
});
}
public collectDefaultSuggestions(_fileName: string, result: ISuggestionsCollector): Thenable<any> {