diff --git a/extensions/typescript-language-features/src/features/bufferSyncSupport.ts b/extensions/typescript-language-features/src/features/bufferSyncSupport.ts index bcb4ea1b4fef1563c9d86e245acb9f20a2653afc..e47947cff2f2403d11cec99b4a77547524c5cc0f 100644 --- a/extensions/typescript-language-features/src/features/bufferSyncSupport.ts +++ b/extensions/typescript-language-features/src/features/bufferSyncSupport.ts @@ -7,6 +7,7 @@ import * as vscode from 'vscode'; import * as Proto from '../protocol'; import { ITypeScriptServiceClient } from '../typescriptService'; import API from '../utils/api'; +import { coalease } from '../utils/arrays'; import { Delayer } from '../utils/async'; import { nulToken } from '../utils/cancellation'; import { Disposable } from '../utils/dispose'; @@ -278,9 +279,7 @@ class GetErrRequest { ) { const args: Proto.GeterrRequestArgs = { delay: 0, - files: Array.from(files.entries) - .map(entry => client.normalizedPath(entry.resource)) - .filter(x => !!x) as string[] + files: coalease(Array.from(files.entries).map(entry => client.normalizedPath(entry.resource))) }; client.executeAsync('geterr', args, _token.token) diff --git a/extensions/typescript-language-features/src/features/folding.ts b/extensions/typescript-language-features/src/features/folding.ts index 963c4fbb9e061aebc3b2f3e0613ce0010e3a6f08..4d6710358162e98786ad008cc65721a0d5926bd1 100644 --- a/extensions/typescript-language-features/src/features/folding.ts +++ b/extensions/typescript-language-features/src/features/folding.ts @@ -7,6 +7,7 @@ import * as vscode from 'vscode'; import * as Proto from '../protocol'; import { ITypeScriptServiceClient } from '../typescriptService'; import API from '../utils/api'; +import { coalease } from '../utils/arrays'; import { VersionDependentRegistration } from '../utils/dependentRegistration'; import * as typeConverters from '../utils/typeConverters'; @@ -33,9 +34,7 @@ class TypeScriptFoldingProvider implements vscode.FoldingRangeProvider { return; } - return response.body - .map(span => this.convertOutliningSpan(span, document)) - .filter(foldingRange => !!foldingRange) as vscode.FoldingRange[]; + return coalease(response.body.map(span => this.convertOutliningSpan(span, document))); } private convertOutliningSpan( diff --git a/extensions/typescript-language-features/src/features/tsconfig.ts b/extensions/typescript-language-features/src/features/tsconfig.ts index 2a47c0887bd474f2eed0e7e29df03a875d7b0c05..b71a608c927eadf62a2d96bb6973a939930624ce 100644 --- a/extensions/typescript-language-features/src/features/tsconfig.ts +++ b/extensions/typescript-language-features/src/features/tsconfig.ts @@ -4,9 +4,9 @@ *--------------------------------------------------------------------------------------------*/ import * as jsonc from 'jsonc-parser'; -import { dirname, join, basename } from 'path'; +import { basename, dirname, join } from 'path'; import * as vscode from 'vscode'; -import { flatten } from '../utils/arrays'; +import { coalease, flatten } from '../utils/arrays'; function mapChildren(node: jsonc.Node | undefined, f: (x: jsonc.Node) => R): R[] { return node && node.type === 'array' && node.children @@ -25,11 +25,11 @@ class TsconfigLinkProvider implements vscode.DocumentLinkProvider { return null; } - return [ + return coalease([ this.getExtendsLink(document, root), ...this.getFilesLinks(document, root), ...this.getReferencesLinks(document, root) - ].filter(x => !!x) as vscode.DocumentLink[]; + ]); } private getExtendsLink(document: vscode.TextDocument, root: jsonc.Node): vscode.DocumentLink | undefined { @@ -68,7 +68,7 @@ class TsconfigLinkProvider implements vscode.DocumentLinkProvider { } return new vscode.DocumentLink(this.getRange(document, pathNode), - basename(pathNode.value).match('.json$') + basename(pathNode.value).endsWith('.json') ? this.getFileTarget(document, pathNode) : this.getFolderTarget(document, pathNode)); }); diff --git a/extensions/typescript-language-features/src/typeScriptServiceClientHost.ts b/extensions/typescript-language-features/src/typeScriptServiceClientHost.ts index 7e0d159132c60fcb8a3ffad6ca96378c9e1838f9..dda7adb82e641ca16b690bd3500fd7d809fc7a48 100644 --- a/extensions/typescript-language-features/src/typeScriptServiceClientHost.ts +++ b/extensions/typescript-language-features/src/typeScriptServiceClientHost.ts @@ -23,7 +23,7 @@ import { PluginManager } from './utils/plugins'; import * as typeConverters from './utils/typeConverters'; import TypingsStatus, { AtaProgressReporter } from './utils/typingsStatus'; import VersionStatus from './utils/versionStatus'; -import { flatten } from './utils/arrays'; +import { flatten, coalease } from './utils/arrays'; // Style check diagnostics that can be reported as warnings const styleCheckDiagnostics = [ @@ -245,13 +245,13 @@ export default class TypeScriptServiceClientHost extends Disposable { } const relatedInformation = diagnostic.relatedInformation; if (relatedInformation) { - converted.relatedInformation = relatedInformation.map((info: any) => { - let span = info.span; + converted.relatedInformation = coalease(relatedInformation.map((info: any) => { + const span = info.span; if (!span) { return undefined; } return new vscode.DiagnosticRelatedInformation(typeConverters.Location.fromTextSpan(this.client.toResource(span.file), span), info.message); - }).filter((x: any) => !!x) as vscode.DiagnosticRelatedInformation[]; + })); } if (diagnostic.reportsUnnecessary) { converted.tags = [vscode.DiagnosticTag.Unnecessary]; diff --git a/extensions/typescript-language-features/src/utils/arrays.ts b/extensions/typescript-language-features/src/utils/arrays.ts index f9435fe9b200291edb4fe920f88fd0c41ac25555..7c8f2d56ff6b9e286f046f987f6955b8e29b7d83 100644 --- a/extensions/typescript-language-features/src/utils/arrays.ts +++ b/extensions/typescript-language-features/src/utils/arrays.ts @@ -19,6 +19,10 @@ export function equals( return a.every((x, i) => itemEquals(x, b[i])); } -export function flatten(arr: ReadonlyArray[]): T[] { - return Array.prototype.concat.apply([], arr); -} \ No newline at end of file +export function flatten(array: ReadonlyArray[]): T[] { + return Array.prototype.concat.apply([], array); +} + +export function coalease(array: ReadonlyArray): T[] { + return array.filter(e => !!e); +}