chore(vscode): update to 1.56.0
This commit is contained in:
@ -29,8 +29,8 @@ export interface IJSONContribution {
|
||||
resolveSuggestion?(resourceUri: Uri | undefined, item: CompletionItem): Thenable<CompletionItem | null> | null;
|
||||
}
|
||||
|
||||
export function addJSONProviders(xhr: XHRRequest, canRunNPM: boolean): Disposable {
|
||||
const contributions = [new PackageJSONContribution(xhr, canRunNPM), new BowerJSONContribution(xhr)];
|
||||
export function addJSONProviders(xhr: XHRRequest, npmCommandPath: string | undefined): Disposable {
|
||||
const contributions = [new PackageJSONContribution(xhr, npmCommandPath), new BowerJSONContribution(xhr)];
|
||||
const subscriptions: Disposable[] = [];
|
||||
contributions.forEach(contribution => {
|
||||
const selector = contribution.getDocumentSelector();
|
||||
@ -136,7 +136,7 @@ export class JSONCompletionItemProvider implements CompletionItemProvider {
|
||||
}
|
||||
if (collectPromise) {
|
||||
return collectPromise.then(() => {
|
||||
if (items.length > 0) {
|
||||
if (items.length > 0 || isIncomplete) {
|
||||
return new CompletionList(items, isIncomplete);
|
||||
}
|
||||
return null;
|
||||
|
@ -14,7 +14,6 @@ import { dirname } from 'path';
|
||||
const localize = nls.loadMessageBundle();
|
||||
|
||||
const LIMIT = 40;
|
||||
const SCOPED_LIMIT = 250;
|
||||
|
||||
const USER_AGENT = 'Visual Studio Code';
|
||||
|
||||
@ -33,7 +32,7 @@ export class PackageJSONContribution implements IJSONContribution {
|
||||
return [{ language: 'json', scheme: '*', pattern: '**/package.json' }];
|
||||
}
|
||||
|
||||
public constructor(private xhr: XHRRequest, private canRunNPM: boolean) {
|
||||
public constructor(private xhr: XHRRequest, private npmCommandPath: string | undefined) {
|
||||
}
|
||||
|
||||
public collectDefaultSuggestions(_resource: Uri, result: ISuggestionsCollector): Thenable<any> {
|
||||
@ -53,7 +52,7 @@ export class PackageJSONContribution implements IJSONContribution {
|
||||
}
|
||||
|
||||
private isEnabled() {
|
||||
return this.canRunNPM || this.onlineEnabled();
|
||||
return this.npmCommandPath || this.onlineEnabled();
|
||||
}
|
||||
|
||||
private onlineEnabled() {
|
||||
@ -94,7 +93,7 @@ export class PackageJSONContribution implements IJSONContribution {
|
||||
collector.setAsIncomplete();
|
||||
}
|
||||
|
||||
queryUrl = `https://api.npms.io/v2/search/suggestions?size=${LIMIT}&q=${encodeURIComponent(currentWord)}`;
|
||||
queryUrl = `https://registry.npmjs.org/-/v1/search?size=${LIMIT}&text=${encodeURIComponent(currentWord)}`;
|
||||
return this.xhr({
|
||||
url: queryUrl,
|
||||
agent: USER_AGENT
|
||||
@ -102,18 +101,17 @@ export class PackageJSONContribution implements IJSONContribution {
|
||||
if (success.status === 200) {
|
||||
try {
|
||||
const obj = JSON.parse(success.responseText);
|
||||
if (obj && Array.isArray(obj)) {
|
||||
const results = <{ package: SearchPackageInfo; }[]>obj;
|
||||
if (obj && obj.objects && Array.isArray(obj.objects)) {
|
||||
const results = <{ package: SearchPackageInfo; }[]>obj.objects;
|
||||
for (const result of results) {
|
||||
this.processPackage(result.package, addValue, isLast, collector);
|
||||
}
|
||||
if (results.length === LIMIT) {
|
||||
collector.setAsIncomplete();
|
||||
}
|
||||
|
||||
}
|
||||
} catch (e) {
|
||||
// ignore
|
||||
}
|
||||
collector.setAsIncomplete();
|
||||
} else {
|
||||
collector.error(localize('json.npm.error.repoaccess', 'Request to the NPM repository failed: {0}', success.responseText));
|
||||
return 0;
|
||||
@ -155,7 +153,7 @@ export class PackageJSONContribution implements IJSONContribution {
|
||||
if (name.length < 4) {
|
||||
name = '';
|
||||
}
|
||||
let queryUrl = `https://api.npms.io/v2/search?q=scope:${scope}%20${name}&size=250`;
|
||||
let queryUrl = `https://registry.npmjs.com/-/v1/search?text=scope:${scope}%20${name}&size=250`;
|
||||
return this.xhr({
|
||||
url: queryUrl,
|
||||
agent: USER_AGENT
|
||||
@ -163,18 +161,16 @@ export class PackageJSONContribution implements IJSONContribution {
|
||||
if (success.status === 200) {
|
||||
try {
|
||||
const obj = JSON.parse(success.responseText);
|
||||
if (obj && Array.isArray(obj.results)) {
|
||||
const objects = <{ package: SearchPackageInfo }[]>obj.results;
|
||||
if (obj && Array.isArray(obj.objects)) {
|
||||
const objects = <{ package: SearchPackageInfo; }[]>obj.objects;
|
||||
for (let object of objects) {
|
||||
this.processPackage(object.package, addValue, isLast, collector);
|
||||
}
|
||||
if (objects.length === SCOPED_LIMIT) {
|
||||
collector.setAsIncomplete();
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
// ignore
|
||||
}
|
||||
collector.setAsIncomplete();
|
||||
} else {
|
||||
collector.error(localize('json.npm.error.repoaccess', 'Request to the NPM repository failed: {0}', success.responseText));
|
||||
}
|
||||
@ -272,8 +268,8 @@ export class PackageJSONContribution implements IJSONContribution {
|
||||
return undefined; // avoid unnecessary lookups
|
||||
}
|
||||
let info: ViewPackageInfo | undefined;
|
||||
if (this.canRunNPM) {
|
||||
info = await this.npmView(pack, resource);
|
||||
if (this.npmCommandPath) {
|
||||
info = await this.npmView(this.npmCommandPath, pack, resource);
|
||||
}
|
||||
if (!info && this.onlineEnabled()) {
|
||||
info = await this.npmjsView(pack);
|
||||
@ -281,11 +277,11 @@ export class PackageJSONContribution implements IJSONContribution {
|
||||
return info;
|
||||
}
|
||||
|
||||
private npmView(pack: string, resource: Uri | undefined): Promise<ViewPackageInfo | undefined> {
|
||||
private npmView(npmCommandPath: string, pack: string, resource: Uri | undefined): Promise<ViewPackageInfo | undefined> {
|
||||
return new Promise((resolve, _reject) => {
|
||||
const args = ['view', '--json', pack, 'description', 'dist-tags.latest', 'homepage', 'version'];
|
||||
let cwd = resource && resource.scheme === 'file' ? dirname(resource.fsPath) : undefined;
|
||||
cp.execFile(process.platform === 'win32' ? 'npm.cmd' : 'npm', args, { cwd }, (error, stdout) => {
|
||||
cp.execFile(npmCommandPath, args, { cwd }, (error, stdout) => {
|
||||
if (!error) {
|
||||
try {
|
||||
const content = JSON.parse(stdout);
|
||||
@ -305,21 +301,18 @@ export class PackageJSONContribution implements IJSONContribution {
|
||||
}
|
||||
|
||||
private async npmjsView(pack: string): Promise<ViewPackageInfo | undefined> {
|
||||
const queryUrl = 'https://api.npms.io/v2/package/' + encodeURIComponent(pack);
|
||||
const queryUrl = 'https://registry.npmjs.org/' + encodeURIComponent(pack);
|
||||
try {
|
||||
const success = await this.xhr({
|
||||
url: queryUrl,
|
||||
agent: USER_AGENT
|
||||
});
|
||||
const obj = JSON.parse(success.responseText);
|
||||
const metadata = obj?.collected?.metadata;
|
||||
if (metadata) {
|
||||
return {
|
||||
description: metadata.description || '',
|
||||
version: metadata.version,
|
||||
homepage: metadata.links?.homepage || ''
|
||||
};
|
||||
}
|
||||
return {
|
||||
description: obj.description || '',
|
||||
version: Object.keys(obj.versions).pop(),
|
||||
homepage: obj.homepage || ''
|
||||
};
|
||||
}
|
||||
catch (e) {
|
||||
//ignore
|
||||
|
@ -8,7 +8,7 @@ import * as vscode from 'vscode';
|
||||
import { addJSONProviders } from './features/jsonContributions';
|
||||
|
||||
export async function activate(context: vscode.ExtensionContext): Promise<void> {
|
||||
context.subscriptions.push(addJSONProviders(httpRequest.xhr, false));
|
||||
context.subscriptions.push(addJSONProviders(httpRequest.xhr, undefined));
|
||||
}
|
||||
|
||||
export function deactivate(): void {
|
||||
|
@ -11,6 +11,7 @@ import { NpmScriptsTreeDataProvider } from './npmView';
|
||||
import { getPackageManager, invalidateTasksCache, NpmTaskProvider, hasPackageJson } from './tasks';
|
||||
import { invalidateHoverScriptsCache, NpmScriptHoverProvider } from './scriptHover';
|
||||
import { NpmScriptLensProvider } from './npmScriptLens';
|
||||
import * as which from 'which';
|
||||
|
||||
let treeDataProvider: NpmScriptsTreeDataProvider | undefined;
|
||||
|
||||
@ -30,8 +31,8 @@ export async function activate(context: vscode.ExtensionContext): Promise<void>
|
||||
}
|
||||
}));
|
||||
|
||||
const canRunNPM = canRunNpmInCurrentWorkspace();
|
||||
context.subscriptions.push(addJSONProviders(httpRequest.xhr, canRunNPM));
|
||||
const npmCommandPath = await getNPMCommandPath();
|
||||
context.subscriptions.push(addJSONProviders(httpRequest.xhr, npmCommandPath));
|
||||
registerTaskProvider(context);
|
||||
|
||||
treeDataProvider = registerExplorer(context);
|
||||
@ -71,6 +72,17 @@ export async function activate(context: vscode.ExtensionContext): Promise<void>
|
||||
context.subscriptions.push(new NpmScriptLensProvider());
|
||||
}
|
||||
|
||||
async function getNPMCommandPath(): Promise<string | undefined> {
|
||||
if (canRunNpmInCurrentWorkspace()) {
|
||||
try {
|
||||
return await which(process.platform === 'win32' ? 'npm.cmd' : 'npm');
|
||||
} catch (e) {
|
||||
return undefined;
|
||||
}
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
|
||||
function canRunNpmInCurrentWorkspace() {
|
||||
if (vscode.workspace.workspaceFolders) {
|
||||
return vscode.workspace.workspaceFolders.some(f => f.uri.scheme === 'file');
|
||||
|
@ -370,7 +370,23 @@ export async function hasPackageJson(): Promise<boolean> {
|
||||
const timeout = setTimeout(() => token.cancel(), 1000);
|
||||
const files = await workspace.findFiles('**/package.json', undefined, 1, token.token);
|
||||
clearTimeout(timeout);
|
||||
return files.length > 0;
|
||||
return files.length > 0 || await hasRootPackageJson();
|
||||
}
|
||||
|
||||
async function hasRootPackageJson(): Promise<boolean> {
|
||||
let folders = workspace.workspaceFolders;
|
||||
if (!folders) {
|
||||
return false;
|
||||
}
|
||||
for (const folder of folders) {
|
||||
if (folder.uri.scheme === 'file') {
|
||||
let packageJson = path.join(folder.uri.fsPath, 'package.json');
|
||||
if (await exists(packageJson)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
async function exists(file: string): Promise<boolean> {
|
||||
|
Reference in New Issue
Block a user