提交 26c4541c 编写于 作者: M Matt Bierner

Add coalease helper function

上级 69263017
......@@ -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)
......
......@@ -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(
......
......@@ -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<R>(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));
});
......
......@@ -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];
......
......@@ -19,6 +19,10 @@ export function equals<T>(
return a.every((x, i) => itemEquals(x, b[i]));
}
export function flatten<T>(arr: ReadonlyArray<T>[]): T[] {
return Array.prototype.concat.apply([], arr);
}
\ No newline at end of file
export function flatten<T>(array: ReadonlyArray<T>[]): T[] {
return Array.prototype.concat.apply([], array);
}
export function coalease<T>(array: ReadonlyArray<T | undefined>): T[] {
return <T[]>array.filter(e => !!e);
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册