mirror of
https://github.com/microsoft/vscode.git
synced 2025-12-24 04:09:28 +00:00
Use flatten in a few places to improve readability
This commit is contained in:
@@ -16,6 +16,7 @@ import LogDirectoryProvider from './utils/logDirectoryProvider';
|
||||
import ManagedFileContextManager from './utils/managedFileContext';
|
||||
import { getContributedTypeScriptServerPlugins, TypeScriptServerPlugin } from './utils/plugins';
|
||||
import * as ProjectStatus from './utils/projectStatus';
|
||||
import { flatten } from './utils/arrays';
|
||||
|
||||
|
||||
export function activate(
|
||||
@@ -36,7 +37,10 @@ export function activate(
|
||||
context.subscriptions.push(module.register());
|
||||
});
|
||||
|
||||
const supportedLanguage = [].concat.apply([], standardLanguageDescriptions.map(x => x.modeIds).concat(plugins.map(x => x.languages)));
|
||||
const supportedLanguage = flatten([
|
||||
...standardLanguageDescriptions.map(x => x.modeIds),
|
||||
...plugins.map(x => x.languages)
|
||||
]);
|
||||
function didOpenTextDocument(textDocument: vscode.TextDocument): boolean {
|
||||
if (isSupportedDocument(supportedLanguage, textDocument)) {
|
||||
openListener.dispose();
|
||||
|
||||
@@ -78,7 +78,10 @@ class TscTaskProvider implements vscode.TaskProvider {
|
||||
|
||||
private async getAllTsConfigs(token: vscode.CancellationToken): Promise<TSConfig[]> {
|
||||
const out = new Set<TSConfig>();
|
||||
const configs = (await this.getTsConfigForActiveFile(token)).concat(await this.getTsConfigsInWorkspace());
|
||||
const configs = [
|
||||
...await this.getTsConfigForActiveFile(token),
|
||||
...await this.getTsConfigsInWorkspace()
|
||||
];
|
||||
for (const config of configs) {
|
||||
if (await exists(config.path)) {
|
||||
out.add(config);
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
import * as jsonc from 'jsonc-parser';
|
||||
import { dirname, join } from 'path';
|
||||
import * as vscode from 'vscode';
|
||||
import { flatten } from '../utils/arrays';
|
||||
|
||||
function mapNode<R>(node: jsonc.Node | undefined, f: (x: jsonc.Node) => R): R[] {
|
||||
return node && node.type === 'array' && node.children
|
||||
@@ -83,7 +84,9 @@ export function register() {
|
||||
|
||||
const languages = ['json', 'jsonc'];
|
||||
|
||||
const selector: vscode.DocumentSelector = ([] as any[]).concat(
|
||||
...languages.map(language => patterns.map((pattern): vscode.DocumentFilter => ({ language, pattern }))));
|
||||
const selector: vscode.DocumentSelector = flatten(
|
||||
languages.map(language =>
|
||||
patterns.map((pattern): vscode.DocumentFilter => ({ language, pattern }))));
|
||||
|
||||
return vscode.languages.registerDocumentLinkProvider(selector, new TsconfigLinkProvider());
|
||||
}
|
||||
|
||||
@@ -14,4 +14,8 @@ export function equals<T>(one: T[], other: T[], itemEquals: (a: T, b: T) => bool
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
export function flatten<T>(arr: T[][]): T[] {
|
||||
return [].concat.apply([], arr);
|
||||
}
|
||||
Reference in New Issue
Block a user