Allow users to opt-out of features that send online requests in the background (#55097)
This commit is contained in:
parent
8ca017eaba
commit
f51c30d8f4
6 changed files with 43 additions and 7 deletions
|
@ -21,6 +21,10 @@ The Npm Script Explorer shows the npm scripts found in your workspace. The explo
|
|||
|
||||
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`.
|
||||
|
|
|
@ -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"]
|
||||
}
|
||||
}
|
||||
},
|
||||
|
|
|
@ -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.",
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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.' });
|
|
@ -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> {
|
||||
|
|
Loading…
Reference in a new issue