mirror of
https://github.com/Microsoft/vscode
synced 2024-08-27 21:09:43 +00:00
improve npm.fetchOnlinePackageInfo handling
This commit is contained in:
parent
585c22af98
commit
9a03a86c0a
|
@ -27,23 +27,18 @@ export class BowerJSONContribution implements IJSONContribution {
|
|||
|
||||
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 constructor(xhr: XHRRequest) {
|
||||
this.xhr = xhr;
|
||||
}
|
||||
|
||||
public getDocumentSelector(): DocumentSelector {
|
||||
return [{ language: 'json', scheme: '*', pattern: '**/bower.json' }, { language: 'json', scheme: '*', pattern: '**/.bower.json' }];
|
||||
}
|
||||
|
||||
private onlineEnabled() {
|
||||
return !!workspace.getConfiguration('npm').get('fetchOnlinePackageInfo');
|
||||
}
|
||||
|
||||
public collectDefaultSuggestions(_resource: string, collector: ISuggestionsCollector): Thenable<any> {
|
||||
const defaultValue = {
|
||||
'name': '${1:name}',
|
||||
|
@ -62,7 +57,7 @@ export class BowerJSONContribution implements IJSONContribution {
|
|||
|
||||
public collectPropertySuggestions(_resource: string, location: Location, currentWord: string, addValue: boolean, isLast: boolean, collector: ISuggestionsCollector): Thenable<any> | null {
|
||||
if ((location.matches(['dependencies']) || location.matches(['devDependencies']))) {
|
||||
if (currentWord.length > 0) {
|
||||
if (currentWord.length > 0 && this.onlineEnabled()) {
|
||||
const queryUrl = 'https://registry.bower.io/packages/search/' + encodeURIComponent(currentWord);
|
||||
|
||||
return this.xhr({
|
||||
|
@ -156,6 +151,10 @@ export class BowerJSONContribution implements IJSONContribution {
|
|||
}
|
||||
|
||||
private getInfo(pack: string): Thenable<string | undefined> {
|
||||
if (!this.onlineEnabled()) {
|
||||
return Promise.resolve(undefined);
|
||||
}
|
||||
|
||||
const queryUrl = 'https://registry.bower.io/packages/' + encodeURIComponent(pack);
|
||||
|
||||
return this.xhr({
|
||||
|
|
|
@ -34,16 +34,8 @@ export class PackageJSONContribution implements IJSONContribution {
|
|||
return [{ language: 'json', scheme: '*', pattern: '**/package.json' }];
|
||||
}
|
||||
|
||||
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 constructor(xhr: XHRRequest) {
|
||||
this.xhr = xhr;
|
||||
}
|
||||
|
||||
public collectDefaultSuggestions(_fileName: string, result: ISuggestionsCollector): Thenable<any> {
|
||||
|
@ -62,6 +54,10 @@ export class PackageJSONContribution implements IJSONContribution {
|
|||
return Promise.resolve(null);
|
||||
}
|
||||
|
||||
private onlineEnabled() {
|
||||
return !!workspace.getConfiguration('npm').get('fetchOnlinePackageInfo');
|
||||
}
|
||||
|
||||
public collectPropertySuggestions(
|
||||
_resource: string,
|
||||
location: Location,
|
||||
|
@ -70,6 +66,10 @@ export class PackageJSONContribution implements IJSONContribution {
|
|||
isLast: boolean,
|
||||
collector: ISuggestionsCollector
|
||||
): Thenable<any> | null {
|
||||
if (!this.onlineEnabled()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if ((location.matches(['dependencies']) || location.matches(['devDependencies']) || location.matches(['optionalDependencies']) || location.matches(['peerDependencies']))) {
|
||||
let queryUrl: string;
|
||||
if (currentWord.length > 0) {
|
||||
|
@ -219,6 +219,10 @@ export class PackageJSONContribution implements IJSONContribution {
|
|||
location: Location,
|
||||
result: ISuggestionsCollector
|
||||
): Thenable<any> | null {
|
||||
if (!this.onlineEnabled()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if ((location.matches(['dependencies', '*']) || location.matches(['devDependencies', '*']) || location.matches(['optionalDependencies', '*']) || location.matches(['peerDependencies', '*']))) {
|
||||
const currentKey = location.path[location.path.length - 1];
|
||||
if (typeof currentKey === 'string') {
|
||||
|
|
Loading…
Reference in a new issue