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
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 43 additions and 7 deletions

View file

@ -15,12 +15,16 @@ For more information about auto detection of Tasks, see the [documentation](http
### Script Explorer
The Npm Script Explorer shows the npm scripts found in your workspace. The explorer view is enabled by the setting `npm.enableScriptExplorer`. A script can be opened, run, or debug from the explorer.
The Npm Script Explorer shows the npm scripts found in your workspace. The explorer view is enabled by the setting `npm.enableScriptExplorer`. A script can be opened, run, or debug from the explorer.
### Run Scripts from the Editor
The extension provides code lense actions to run or debug a script from the editor.
### Others
The extension fetches data from https://registry.npmjs/org and https://registry.bower.io to provide auto-completion and information on hover features on npm dependencies.
## Settings
- `npm.autoDetect` - Enable detecting scripts as tasks, the default is `on`.

View file

@ -214,6 +214,13 @@
"description": "%config.npm.scriptExplorerAction%",
"scope": "window",
"default": "open"
},
"npm.fetchOnlinePackageInfo": {
"type": "boolean",
"description": "%config.npm.fetchOnlinePackageInfo%",
"default": true,
"scope": "window",
"tags": ["usesOnlineServices"]
}
}
},

View file

@ -7,6 +7,7 @@
"config.npm.exclude": "Configure glob patterns for folders that should be excluded from automatic script detection.",
"config.npm.enableScriptExplorer": "Enable an explorer view for npm scripts.",
"config.npm.scriptExplorerAction": "The default click action used in the scripts explorer: 'open' or 'run', the default is 'open'.",
"config.npm.fetchOnlinePackageInfo": "Fetch data from https://registry.npmjs/org and https://registry.bower.io to provide auto-completion and information on hover features on npm dependencies.",
"npm.parseError": "Npm task detection: failed to parse the file {0}",
"taskdef.script": "The npm script to customize.",
"taskdef.path": "The path to the folder of the package.json file that provides the script. Can be omitted.",

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';
@ -25,7 +25,19 @@ export class BowerJSONContribution implements IJSONContribution {
'hui', 'bootstrap-languages', 'async', 'gulp', 'jquery-pjax', 'coffeescript', 'hammer.js', 'ace', 'leaflet', 'jquery-mobile', 'sweetalert', 'typeahead.js', 'soup', 'typehead.js',
'sails', 'codeigniter2'];
public constructor(private xhr: XHRRequest) {
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 getDocumentSelector(): DocumentSelector {

View file

@ -164,3 +164,5 @@ export class JSONCompletionItemProvider implements CompletionItemProvider {
return nextToken === SyntaxKind.CloseBraceToken || nextToken === SyntaxKind.EOF;
}
}
export const xhrDisabled = () => Promise.reject({ responseText: 'Use of online resources is disabled.' });

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> {