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

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

Merged
merged 1 commit into from
Jul 27, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 5 additions & 1 deletion extensions/npm/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
Expand Down
7 changes: 7 additions & 0 deletions extensions/npm/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
}
}
},
Expand Down
1 change: 1 addition & 0 deletions extensions/npm/package.nls.json
Original file line number Diff line number Diff line change
Expand Up @@ -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.",
Expand Down
18 changes: 15 additions & 3 deletions extensions/npm/src/features/bowerJSONContribution.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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 {
Expand Down
2 changes: 2 additions & 0 deletions extensions/npm/src/features/jsonContributions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.' });
16 changes: 13 additions & 3 deletions extensions/npm/src/features/packageJSONContribution.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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> {
Expand Down