mirror of
https://github.com/Microsoft/vscode
synced 2024-08-27 21:09:43 +00:00
Use [].flat()
This commit is contained in:
parent
739dfea8e6
commit
5c452f8973
|
@ -6,7 +6,6 @@
|
|||
import * as vscode from 'vscode';
|
||||
import type * as Proto from '../protocol';
|
||||
import { ITypeScriptServiceClient } from '../typescriptService';
|
||||
import { flatten } from '../utils/arrays';
|
||||
import { DocumentSelector } from '../utils/documentSelector';
|
||||
import * as typeConverters from '../utils/typeConverters';
|
||||
|
||||
|
@ -34,10 +33,10 @@ class TypeScriptDocumentHighlightProvider implements vscode.DocumentHighlightPro
|
|||
return [];
|
||||
}
|
||||
|
||||
return flatten(
|
||||
response.body
|
||||
return response.body
|
||||
.filter(highlight => highlight.file === file)
|
||||
.map(convertDocumentHighlight));
|
||||
.map(convertDocumentHighlight)
|
||||
.flat();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -8,7 +8,7 @@ import { basename, dirname, join, posix } from 'path';
|
|||
import * as vscode from 'vscode';
|
||||
import * as nls from 'vscode-nls';
|
||||
import { Utils } from 'vscode-uri';
|
||||
import { coalesce, flatten } from '../utils/arrays';
|
||||
import { coalesce } from '../utils/arrays';
|
||||
import { exists } from '../utils/fs';
|
||||
|
||||
function mapChildren<R>(node: jsonc.Node | undefined, f: (x: jsonc.Node) => R): R[] {
|
||||
|
@ -195,9 +195,9 @@ export function register() {
|
|||
|
||||
const languages = ['json', 'jsonc'];
|
||||
|
||||
const selector: vscode.DocumentSelector = flatten(
|
||||
languages.map(language =>
|
||||
patterns.map((pattern): vscode.DocumentFilter => ({ language, pattern }))));
|
||||
const selector: vscode.DocumentSelector =
|
||||
languages.map(language => patterns.map((pattern): vscode.DocumentFilter => ({ language, pattern })))
|
||||
.flat();
|
||||
|
||||
return vscode.Disposable.from(
|
||||
vscode.commands.registerCommand(openExtendsLinkCommandId, async ({ resourceUri, extendsValue, }: OpenExtendsLinkCommandArgs) => {
|
||||
|
|
|
@ -11,7 +11,6 @@ import { TsServerProcessFactory } from './tsServer/server';
|
|||
import { ITypeScriptVersionProvider } from './tsServer/versionProvider';
|
||||
import TypeScriptServiceClientHost from './typeScriptServiceClientHost';
|
||||
import { ActiveJsTsEditorTracker } from './utils/activeJsTsEditorTracker';
|
||||
import { flatten } from './utils/arrays';
|
||||
import { ServiceConfigurationProvider } from './utils/configuration';
|
||||
import * as fileSchemes from './utils/fileSchemes';
|
||||
import { standardLanguageDescriptions } from './utils/languageDescription';
|
||||
|
@ -55,10 +54,10 @@ export function lazilyActivateClient(
|
|||
): vscode.Disposable {
|
||||
const disposables: vscode.Disposable[] = [];
|
||||
|
||||
const supportedLanguage = flatten([
|
||||
const supportedLanguage = [
|
||||
...standardLanguageDescriptions.map(x => x.languageIds),
|
||||
...pluginManager.plugins.map(x => x.languages)
|
||||
]);
|
||||
].flat();
|
||||
|
||||
let hasActivated = false;
|
||||
const maybeActivate = (textDocument: vscode.TextDocument): boolean => {
|
||||
|
|
|
@ -9,7 +9,7 @@ import * as vscode from 'vscode';
|
|||
import * as nls from 'vscode-nls';
|
||||
import { wait } from '../test/testUtils';
|
||||
import { ITypeScriptServiceClient, ServerResponse } from '../typescriptService';
|
||||
import { coalesce, flatten } from '../utils/arrays';
|
||||
import { coalesce } from '../utils/arrays';
|
||||
import { Disposable } from '../utils/dispose';
|
||||
import { exists } from '../utils/fs';
|
||||
import { isTsConfigFileName } from '../utils/languageDescription';
|
||||
|
@ -98,10 +98,10 @@ class TscTaskProvider extends Disposable implements vscode.TaskProvider {
|
|||
}
|
||||
|
||||
private async getAllTsConfigs(token: vscode.CancellationToken): Promise<TSConfig[]> {
|
||||
const configs = flatten(await Promise.all([
|
||||
const configs = (await Promise.all([
|
||||
this.getTsConfigForActiveFile(token),
|
||||
this.getTsConfigsInWorkspace(token),
|
||||
]));
|
||||
])).flat();
|
||||
|
||||
return Promise.all(
|
||||
configs.map(async config => await exists(config.uri) ? config : undefined),
|
||||
|
|
|
@ -23,7 +23,7 @@ import TypeScriptServiceClient from './typescriptServiceClient';
|
|||
import { IntellisenseStatus } from './ui/intellisenseStatus';
|
||||
import { VersionStatus } from './ui/versionStatus';
|
||||
import { ActiveJsTsEditorTracker } from './utils/activeJsTsEditorTracker';
|
||||
import { coalesce, flatten } from './utils/arrays';
|
||||
import { coalesce } from './utils/arrays';
|
||||
import { ServiceConfigurationProvider } from './utils/configuration';
|
||||
import { Disposable } from './utils/dispose';
|
||||
import * as errorCodes from './utils/errorCodes';
|
||||
|
@ -165,11 +165,10 @@ export default class TypeScriptServiceClientHost extends Disposable {
|
|||
}
|
||||
|
||||
private getAllModeIds(descriptions: LanguageDescription[], pluginManager: PluginManager) {
|
||||
const allModeIds = flatten([
|
||||
return [
|
||||
...descriptions.map(x => x.languageIds),
|
||||
...pluginManager.plugins.map(x => x.languages)
|
||||
]);
|
||||
return allModeIds;
|
||||
].flat();
|
||||
}
|
||||
|
||||
public get serviceClient(): TypeScriptServiceClient {
|
||||
|
|
|
@ -19,10 +19,6 @@ export function equals<T>(
|
|||
return a.every((x, i) => itemEquals(x, b[i]));
|
||||
}
|
||||
|
||||
export function flatten<T>(array: ReadonlyArray<T>[]): T[] {
|
||||
return Array.prototype.concat.apply([], array);
|
||||
}
|
||||
|
||||
export function coalesce<T>(array: ReadonlyArray<T | undefined>): T[] {
|
||||
return <T[]>array.filter(e => !!e);
|
||||
}
|
||||
|
|
|
@ -37,7 +37,7 @@ export class PluginManager extends Disposable {
|
|||
return;
|
||||
}
|
||||
const newPlugins = this.readPlugins();
|
||||
if (!arrays.equals(arrays.flatten(Array.from(this._plugins.values())), arrays.flatten(Array.from(newPlugins.values())), TypeScriptServerPlugin.equals)) {
|
||||
if (!arrays.equals(Array.from(this._plugins.values()).flat(), Array.from(newPlugins.values()).flat(), TypeScriptServerPlugin.equals)) {
|
||||
this._plugins = newPlugins;
|
||||
this._onDidUpdatePlugins.fire(this);
|
||||
}
|
||||
|
@ -48,7 +48,7 @@ export class PluginManager extends Disposable {
|
|||
if (!this._plugins) {
|
||||
this._plugins = this.readPlugins();
|
||||
}
|
||||
return arrays.flatten(Array.from(this._plugins.values()));
|
||||
return Array.from(this._plugins.values()).flat();
|
||||
}
|
||||
|
||||
private readonly _onDidUpdatePlugins = this._register(new vscode.EventEmitter<this>());
|
||||
|
|
Loading…
Reference in a new issue