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