mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-11-18 20:11:14 +00:00
Merge branch 'master' into es2017-target
This commit is contained in:
commit
a500fd9211
325 files changed
+8186
-1560
No files matched your search
@@ -954,8 +954,7 @@ namespace ts {
|
||||
return;
|
||||
case SyntaxKind.Parameter:
|
||||
if ((<ParameterDeclaration>token.parent).name === token) {
|
||||
const isThis = token.kind === SyntaxKind.Identifier && (<Identifier>token).originalKeywordKind === SyntaxKind.ThisKeyword;
|
||||
return isThis ? ClassificationType.keyword : ClassificationType.parameterName;
|
||||
return isThisIdentifier(token) ? ClassificationType.keyword : ClassificationType.parameterName;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,48 @@
|
||||
/* @internal */
|
||||
namespace ts {
|
||||
export interface CodeFix {
|
||||
errorCodes: number[];
|
||||
getCodeActions(context: CodeFixContext): CodeAction[] | undefined;
|
||||
}
|
||||
|
||||
export interface CodeFixContext {
|
||||
errorCode: number;
|
||||
sourceFile: SourceFile;
|
||||
span: TextSpan;
|
||||
program: Program;
|
||||
newLineCharacter: string;
|
||||
}
|
||||
|
||||
export namespace codefix {
|
||||
const codeFixes = createMap<CodeFix[]>();
|
||||
|
||||
export function registerCodeFix(action: CodeFix) {
|
||||
forEach(action.errorCodes, error => {
|
||||
let fixes = codeFixes[error];
|
||||
if (!fixes) {
|
||||
fixes = [];
|
||||
codeFixes[error] = fixes;
|
||||
}
|
||||
fixes.push(action);
|
||||
});
|
||||
}
|
||||
|
||||
export function getSupportedErrorCodes() {
|
||||
return Object.keys(codeFixes);
|
||||
}
|
||||
|
||||
export function getFixes(context: CodeFixContext): CodeAction[] {
|
||||
const fixes = codeFixes[context.errorCode];
|
||||
let allActions: CodeAction[] = [];
|
||||
|
||||
forEach(fixes, f => {
|
||||
const actions = f.getCodeActions(context);
|
||||
if (actions && actions.length > 0) {
|
||||
allActions = allActions.concat(actions);
|
||||
}
|
||||
});
|
||||
|
||||
return allActions;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
///<reference path='superFixes.ts' />
|
||||
@@ -0,0 +1,81 @@
|
||||
/* @internal */
|
||||
namespace ts.codefix {
|
||||
function getOpenBraceEnd(constructor: ConstructorDeclaration, sourceFile: SourceFile) {
|
||||
// First token is the open curly, this is where we want to put the 'super' call.
|
||||
return constructor.body.getFirstToken(sourceFile).getEnd();
|
||||
}
|
||||
|
||||
registerCodeFix({
|
||||
errorCodes: [Diagnostics.Constructors_for_derived_classes_must_contain_a_super_call.code],
|
||||
getCodeActions: (context: CodeFixContext) => {
|
||||
const sourceFile = context.sourceFile;
|
||||
const token = getTokenAtPosition(sourceFile, context.span.start);
|
||||
|
||||
if (token.kind !== SyntaxKind.ConstructorKeyword) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
const newPosition = getOpenBraceEnd(<ConstructorDeclaration>token.parent, sourceFile);
|
||||
return [{
|
||||
description: getLocaleSpecificMessage(Diagnostics.Add_missing_super_call),
|
||||
changes: [{ fileName: sourceFile.fileName, textChanges: [{ newText: "super();", span: { start: newPosition, length: 0 } }] }]
|
||||
}];
|
||||
}
|
||||
});
|
||||
|
||||
registerCodeFix({
|
||||
errorCodes: [Diagnostics.super_must_be_called_before_accessing_this_in_the_constructor_of_a_derived_class.code],
|
||||
getCodeActions: (context: CodeFixContext) => {
|
||||
const sourceFile = context.sourceFile;
|
||||
|
||||
const token = getTokenAtPosition(sourceFile, context.span.start);
|
||||
if (token.kind !== SyntaxKind.ThisKeyword) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
const constructor = getContainingFunction(token);
|
||||
const superCall = findSuperCall((<ConstructorDeclaration>constructor).body);
|
||||
if (!superCall) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
// figure out if the this access is actuall inside the supercall
|
||||
// i.e. super(this.a), since in that case we won't suggest a fix
|
||||
if (superCall.expression && superCall.expression.kind == SyntaxKind.CallExpression) {
|
||||
const arguments = (<CallExpression>superCall.expression).arguments;
|
||||
for (let i = 0; i < arguments.length; i++) {
|
||||
if ((<PropertyAccessExpression>arguments[i]).expression === token) {
|
||||
return undefined;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const newPosition = getOpenBraceEnd(<ConstructorDeclaration>constructor, sourceFile);
|
||||
const changes = [{
|
||||
fileName: sourceFile.fileName, textChanges: [{
|
||||
newText: superCall.getText(sourceFile),
|
||||
span: { start: newPosition, length: 0 }
|
||||
},
|
||||
{
|
||||
newText: "",
|
||||
span: { start: superCall.getStart(sourceFile), length: superCall.getWidth(sourceFile) }
|
||||
}]
|
||||
}];
|
||||
|
||||
return [{
|
||||
description: getLocaleSpecificMessage(Diagnostics.Make_super_call_the_first_statement_in_the_constructor),
|
||||
changes
|
||||
}];
|
||||
|
||||
function findSuperCall(n: Node): ExpressionStatement {
|
||||
if (n.kind === SyntaxKind.ExpressionStatement && isSuperCall((<ExpressionStatement>n).expression)) {
|
||||
return <ExpressionStatement>n;
|
||||
}
|
||||
if (isFunctionLike(n)) {
|
||||
return undefined;
|
||||
}
|
||||
return forEachChild(n, findSuperCall);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
+56
-20
@@ -24,7 +24,7 @@ namespace ts.Completions {
|
||||
const entries: CompletionEntry[] = [];
|
||||
|
||||
if (isSourceFileJavaScript(sourceFile)) {
|
||||
const uniqueNames = getCompletionEntriesFromSymbols(symbols, entries, location, /*performCharacterChecks*/ false);
|
||||
const uniqueNames = getCompletionEntriesFromSymbols(symbols, entries, location, /*performCharacterChecks*/ true);
|
||||
addRange(entries, getJavaScriptCompletionEntries(sourceFile, location.pos, uniqueNames));
|
||||
}
|
||||
else {
|
||||
@@ -138,7 +138,9 @@ namespace ts.Completions {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
if (node.parent.kind === SyntaxKind.PropertyAssignment && node.parent.parent.kind === SyntaxKind.ObjectLiteralExpression) {
|
||||
if (node.parent.kind === SyntaxKind.PropertyAssignment &&
|
||||
node.parent.parent.kind === SyntaxKind.ObjectLiteralExpression &&
|
||||
(<PropertyAssignment>node.parent).name === node) {
|
||||
// Get quoted name of properties of the object literal expression
|
||||
// i.e. interface ConfigFiles {
|
||||
// 'jspm:dev': string
|
||||
@@ -323,15 +325,28 @@ namespace ts.Completions {
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Given a path ending at a directory, gets the completions for the path, and filters for those entries containing the basename.
|
||||
*/
|
||||
function getCompletionEntriesForDirectoryFragment(fragment: string, scriptPath: string, extensions: string[], includeExtensions: boolean, span: TextSpan, exclude?: string, result: CompletionEntry[] = []): CompletionEntry[] {
|
||||
if (fragment === undefined) {
|
||||
fragment = "";
|
||||
}
|
||||
|
||||
fragment = normalizeSlashes(fragment);
|
||||
|
||||
/**
|
||||
* Remove the basename from the path. Note that we don't use the basename to filter completions;
|
||||
* the client is responsible for refining completions.
|
||||
*/
|
||||
fragment = getDirectoryPath(fragment);
|
||||
if (!fragment) {
|
||||
fragment = "./";
|
||||
}
|
||||
else {
|
||||
fragment = ensureTrailingDirectorySeparator(fragment);
|
||||
|
||||
if (fragment === "") {
|
||||
fragment = "." + directorySeparator;
|
||||
}
|
||||
|
||||
fragment = ensureTrailingDirectorySeparator(fragment);
|
||||
|
||||
const absolutePath = normalizeAndPreserveTrailingSlash(isRootedDiskPath(fragment) ? fragment : combinePaths(scriptPath, fragment));
|
||||
const baseDirectory = getDirectoryPath(absolutePath);
|
||||
const ignoreCase = !(host.useCaseSensitiveFileNames && host.useCaseSensitiveFileNames());
|
||||
@@ -341,6 +356,12 @@ namespace ts.Completions {
|
||||
const files = tryReadDirectory(host, baseDirectory, extensions, /*exclude*/undefined, /*include*/["./*"]);
|
||||
|
||||
if (files) {
|
||||
/**
|
||||
* Multiple file entries might map to the same truncated name once we remove extensions
|
||||
* (happens iff includeExtensions === false)so we use a set-like data structure. Eg:
|
||||
*
|
||||
* both foo.ts and foo.tsx become foo
|
||||
*/
|
||||
const foundFiles = createMap<boolean>();
|
||||
for (let filePath of files) {
|
||||
filePath = normalizePath(filePath);
|
||||
@@ -537,36 +558,44 @@ namespace ts.Completions {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
const completionInfo: CompletionInfo = {
|
||||
/**
|
||||
* We don't want the editor to offer any other completions, such as snippets, inside a comment.
|
||||
*/
|
||||
isGlobalCompletion: false,
|
||||
isMemberCompletion: false,
|
||||
/**
|
||||
* The user may type in a path that doesn't yet exist, creating a "new identifier"
|
||||
* with respect to the collection of identifiers the server is aware of.
|
||||
*/
|
||||
isNewIdentifierLocation: true,
|
||||
|
||||
entries: []
|
||||
};
|
||||
|
||||
const text = sourceFile.text.substr(range.pos, position - range.pos);
|
||||
|
||||
const match = tripleSlashDirectiveFragmentRegex.exec(text);
|
||||
|
||||
if (match) {
|
||||
const prefix = match[1];
|
||||
const kind = match[2];
|
||||
const toComplete = match[3];
|
||||
|
||||
const scriptPath = getDirectoryPath(sourceFile.path);
|
||||
let entries: CompletionEntry[];
|
||||
if (kind === "path") {
|
||||
// Give completions for a relative path
|
||||
const span: TextSpan = getDirectoryFragmentTextSpan(toComplete, range.pos + prefix.length);
|
||||
entries = getCompletionEntriesForDirectoryFragment(toComplete, scriptPath, getSupportedExtensions(compilerOptions), /*includeExtensions*/true, span, sourceFile.path);
|
||||
completionInfo.entries = getCompletionEntriesForDirectoryFragment(toComplete, scriptPath, getSupportedExtensions(compilerOptions), /*includeExtensions*/true, span, sourceFile.path);
|
||||
}
|
||||
else {
|
||||
// Give completions based on the typings available
|
||||
const span: TextSpan = { start: range.pos + prefix.length, length: match[0].length - prefix.length };
|
||||
entries = getCompletionEntriesFromTypings(host, compilerOptions, scriptPath, span);
|
||||
completionInfo.entries = getCompletionEntriesFromTypings(host, compilerOptions, scriptPath, span);
|
||||
}
|
||||
|
||||
return {
|
||||
isGlobalCompletion: false,
|
||||
isMemberCompletion: false,
|
||||
isNewIdentifierLocation: true,
|
||||
entries
|
||||
};
|
||||
}
|
||||
|
||||
return undefined;
|
||||
return completionInfo;
|
||||
}
|
||||
|
||||
function getCompletionEntriesFromTypings(host: LanguageServiceHost, options: CompilerOptions, scriptPath: string, span: TextSpan, result: CompletionEntry[] = []): CompletionEntry[] {
|
||||
@@ -1001,6 +1030,7 @@ namespace ts.Completions {
|
||||
if ((jsxContainer.kind === SyntaxKind.JsxSelfClosingElement) || (jsxContainer.kind === SyntaxKind.JsxOpeningElement)) {
|
||||
// Cursor is inside a JSX self-closing element or opening element
|
||||
attrsType = typeChecker.getJsxElementAttributesType(<JsxOpeningLikeElement>jsxContainer);
|
||||
isGlobalCompletion = false;
|
||||
|
||||
if (attrsType) {
|
||||
symbols = filterJsxAttributes(typeChecker.getPropertiesOfType(attrsType), (<JsxOpeningLikeElement>jsxContainer).attributes);
|
||||
@@ -1671,9 +1701,15 @@ namespace ts.Completions {
|
||||
* Matches a triple slash reference directive with an incomplete string literal for its path. Used
|
||||
* to determine if the caret is currently within the string literal and capture the literal fragment
|
||||
* for completions.
|
||||
* For example, this matches /// <reference path="fragment
|
||||
* For example, this matches
|
||||
*
|
||||
* /// <reference path="fragment
|
||||
*
|
||||
* but not
|
||||
*
|
||||
* /// <reference path="fragment"
|
||||
*/
|
||||
const tripleSlashDirectiveFragmentRegex = /^(\/\/\/\s*<reference\s+(path|types)\s*=\s*(?:'|"))([^\3]*)$/;
|
||||
const tripleSlashDirectiveFragmentRegex = /^(\/\/\/\s*<reference\s+(path|types)\s*=\s*(?:'|"))([^\3"]*)$/;
|
||||
|
||||
interface VisibleModuleInfo {
|
||||
moduleName: string;
|
||||
|
||||
@@ -175,7 +175,7 @@ namespace ts.formatting {
|
||||
return rangeContainsRange((<InterfaceDeclaration>parent).members, node);
|
||||
case SyntaxKind.ModuleDeclaration:
|
||||
const body = (<ModuleDeclaration>parent).body;
|
||||
return body && body.kind === SyntaxKind.Block && rangeContainsRange((<Block>body).statements, node);
|
||||
return body && body.kind === SyntaxKind.ModuleBlock && rangeContainsRange((<ModuleBlock>body).statements, node);
|
||||
case SyntaxKind.SourceFile:
|
||||
case SyntaxKind.Block:
|
||||
case SyntaxKind.ModuleBlock:
|
||||
|
||||
@@ -332,7 +332,7 @@ namespace ts.formatting {
|
||||
(<CallExpression>node.parent).expression !== node) {
|
||||
|
||||
const fullCallOrNewExpression = (<CallExpression | NewExpression>node.parent).expression;
|
||||
const startingExpression = getStartingExpression(<PropertyAccessExpression | CallExpression | ElementAccessExpression>fullCallOrNewExpression);
|
||||
const startingExpression = getStartingExpression(fullCallOrNewExpression);
|
||||
|
||||
if (fullCallOrNewExpression === startingExpression) {
|
||||
return Value.Unknown;
|
||||
@@ -350,15 +350,14 @@ namespace ts.formatting {
|
||||
|
||||
return Value.Unknown;
|
||||
|
||||
function getStartingExpression(node: PropertyAccessExpression | CallExpression | ElementAccessExpression) {
|
||||
function getStartingExpression(node: Expression) {
|
||||
while (true) {
|
||||
switch (node.kind) {
|
||||
case SyntaxKind.CallExpression:
|
||||
case SyntaxKind.NewExpression:
|
||||
case SyntaxKind.PropertyAccessExpression:
|
||||
case SyntaxKind.ElementAccessExpression:
|
||||
|
||||
node = <PropertyAccessExpression | CallExpression | ElementAccessExpression | PropertyAccessExpression>node.expression;
|
||||
node = (<PropertyAccessExpression | CallExpression | NewExpression | ElementAccessExpression | PropertyAccessExpression>node).expression;
|
||||
break;
|
||||
default:
|
||||
return node;
|
||||
|
||||
@@ -21,6 +21,13 @@ namespace ts.NavigationBar {
|
||||
return result;
|
||||
}
|
||||
|
||||
export function getNavigationTree(sourceFile: SourceFile): NavigationTree {
|
||||
curSourceFile = sourceFile;
|
||||
const result = convertToTree(rootNavigationBarNode(sourceFile));
|
||||
curSourceFile = undefined;
|
||||
return result;
|
||||
}
|
||||
|
||||
// Keep sourceFile handy so we don't have to search for it every time we need to call `getText`.
|
||||
let curSourceFile: SourceFile;
|
||||
function nodeText(node: Node): string {
|
||||
@@ -324,7 +331,7 @@ namespace ts.NavigationBar {
|
||||
}
|
||||
|
||||
// More efficient to create a collator once and use its `compare` than to call `a.localeCompare(b)` many times.
|
||||
const collator: { compare(a: string, b: string): number } = typeof Intl === "undefined" ? undefined : new Intl.Collator();
|
||||
const collator: { compare(a: string, b: string): number } = typeof Intl === "object" && typeof Intl.Collator === "function" ? new Intl.Collator() : undefined;
|
||||
// Intl is missing in Safari, and node 0.10 treats "a" as greater than "B".
|
||||
const localeCompareIsCorrect = collator && collator.compare("a", "B") < 0;
|
||||
const localeCompareFix: (a: string, b: string) => number = localeCompareIsCorrect ? collator.compare : function(a, b) {
|
||||
@@ -502,6 +509,16 @@ namespace ts.NavigationBar {
|
||||
// NavigationBarItem requires an array, but will not mutate it, so just give it this for performance.
|
||||
const emptyChildItemArray: NavigationBarItem[] = [];
|
||||
|
||||
function convertToTree(n: NavigationBarNode): NavigationTree {
|
||||
return {
|
||||
text: getItemName(n.node),
|
||||
kind: getNodeKind(n.node),
|
||||
kindModifiers: getNodeModifiers(n.node),
|
||||
spans: getSpans(n),
|
||||
childItems: map(n.children, convertToTree)
|
||||
};
|
||||
}
|
||||
|
||||
function convertToTopLevelItem(n: NavigationBarNode): NavigationBarItem {
|
||||
return {
|
||||
text: getItemName(n.node),
|
||||
@@ -526,16 +543,16 @@ namespace ts.NavigationBar {
|
||||
grayed: false
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
function getSpans(n: NavigationBarNode): TextSpan[] {
|
||||
const spans = [getNodeSpan(n.node)];
|
||||
if (n.additionalNodes) {
|
||||
for (const node of n.additionalNodes) {
|
||||
spans.push(getNodeSpan(node));
|
||||
}
|
||||
function getSpans(n: NavigationBarNode): TextSpan[] {
|
||||
const spans = [getNodeSpan(n.node)];
|
||||
if (n.additionalNodes) {
|
||||
for (const node of n.additionalNodes) {
|
||||
spans.push(getNodeSpan(node));
|
||||
}
|
||||
return spans;
|
||||
}
|
||||
return spans;
|
||||
}
|
||||
|
||||
function getModuleName(moduleDeclaration: ModuleDeclaration): string {
|
||||
|
||||
+75
-14
@@ -24,14 +24,16 @@
|
||||
/// <reference path='transpile.ts' />
|
||||
/// <reference path='formatting\formatting.ts' />
|
||||
/// <reference path='formatting\smartIndenter.ts' />
|
||||
/// <reference path='codefixes\codeFixProvider.ts' />
|
||||
/// <reference path='codefixes\fixes.ts' />
|
||||
|
||||
namespace ts {
|
||||
/** The version of the language service API */
|
||||
export const servicesVersion = "0.5";
|
||||
|
||||
function createNode(kind: SyntaxKind, pos: number, end: number, parent?: Node): NodeObject | TokenObject | IdentifierObject {
|
||||
function createNode<TKind extends SyntaxKind>(kind: TKind, pos: number, end: number, parent?: Node): NodeObject | TokenObject<TKind> | IdentifierObject {
|
||||
const node = kind >= SyntaxKind.FirstNode ? new NodeObject(kind, pos, end) :
|
||||
kind === SyntaxKind.Identifier ? new IdentifierObject(kind, pos, end) :
|
||||
kind === SyntaxKind.Identifier ? new IdentifierObject(SyntaxKind.Identifier, pos, end) :
|
||||
new TokenObject(kind, pos, end);
|
||||
node.parent = parent;
|
||||
return node;
|
||||
@@ -210,14 +212,13 @@ namespace ts {
|
||||
}
|
||||
}
|
||||
|
||||
class TokenOrIdentifierObject implements Token {
|
||||
class TokenOrIdentifierObject implements Node {
|
||||
public kind: SyntaxKind;
|
||||
public pos: number;
|
||||
public end: number;
|
||||
public flags: NodeFlags;
|
||||
public parent: Node;
|
||||
public jsDocComments: JSDoc[];
|
||||
public __tokenTag: any;
|
||||
|
||||
constructor(pos: number, end: number) {
|
||||
// Set properties in same order as NodeObject
|
||||
@@ -319,16 +320,25 @@ namespace ts {
|
||||
}
|
||||
}
|
||||
|
||||
class TokenObject extends TokenOrIdentifierObject {
|
||||
public kind: SyntaxKind;
|
||||
constructor(kind: SyntaxKind, pos: number, end: number) {
|
||||
class TokenObject<TKind extends SyntaxKind> extends TokenOrIdentifierObject implements Token<TKind> {
|
||||
public kind: TKind;
|
||||
|
||||
constructor(kind: TKind, pos: number, end: number) {
|
||||
super(pos, end);
|
||||
this.kind = kind;
|
||||
}
|
||||
}
|
||||
|
||||
class IdentifierObject extends TokenOrIdentifierObject {
|
||||
constructor(kind: SyntaxKind, pos: number, end: number) {
|
||||
class IdentifierObject extends TokenOrIdentifierObject implements Identifier {
|
||||
public kind: SyntaxKind.Identifier;
|
||||
public text: string;
|
||||
_primaryExpressionBrand: any;
|
||||
_memberExpressionBrand: any;
|
||||
_leftHandSideExpressionBrand: any;
|
||||
_incrementExpressionBrand: any;
|
||||
_unaryExpressionBrand: any;
|
||||
_expressionBrand: any;
|
||||
constructor(kind: SyntaxKind.Identifier, pos: number, end: number) {
|
||||
super(pos, end);
|
||||
}
|
||||
}
|
||||
@@ -424,6 +434,7 @@ namespace ts {
|
||||
}
|
||||
|
||||
class SourceFileObject extends NodeObject implements SourceFile {
|
||||
public kind: SyntaxKind.SourceFile;
|
||||
public _declarationBrand: any;
|
||||
public fileName: string;
|
||||
public path: Path;
|
||||
@@ -432,7 +443,7 @@ namespace ts {
|
||||
public lineMap: number[];
|
||||
|
||||
public statements: NodeArray<Statement>;
|
||||
public endOfFileToken: Node;
|
||||
public endOfFileToken: Token<SyntaxKind.EndOfFileToken>;
|
||||
|
||||
public amdDependencies: { name: string; path: string }[];
|
||||
public moduleName: string;
|
||||
@@ -655,6 +666,7 @@ namespace ts {
|
||||
return {
|
||||
getNodeConstructor: () => NodeObject,
|
||||
getTokenConstructor: () => TokenObject,
|
||||
|
||||
getIdentifierConstructor: () => IdentifierObject,
|
||||
getSourceFileConstructor: () => SourceFileObject,
|
||||
getSymbolConstructor: () => SymbolObject,
|
||||
@@ -721,9 +733,13 @@ namespace ts {
|
||||
};
|
||||
}
|
||||
|
||||
// Cache host information about script should be refreshed
|
||||
export function getSupportedCodeFixes() {
|
||||
return codefix.getSupportedErrorCodes();
|
||||
}
|
||||
|
||||
// Cache host information about script Should be refreshed
|
||||
// at each language service public entry point, since we don't know when
|
||||
// set of scripts handled by the host changes.
|
||||
// the set of scripts handled by the host changes.
|
||||
class HostCache {
|
||||
private fileNameToEntry: FileMap<HostFileInformation>;
|
||||
private _compilationSettings: CompilerOptions;
|
||||
@@ -1507,17 +1523,32 @@ namespace ts {
|
||||
}
|
||||
|
||||
function getNavigationBarItems(fileName: string): NavigationBarItem[] {
|
||||
const sourceFile = syntaxTreeCache.getCurrentSourceFile(fileName);
|
||||
return NavigationBar.getNavigationBarItems(syntaxTreeCache.getCurrentSourceFile(fileName));
|
||||
}
|
||||
|
||||
return NavigationBar.getNavigationBarItems(sourceFile);
|
||||
function getNavigationTree(fileName: string): NavigationTree {
|
||||
return NavigationBar.getNavigationTree(syntaxTreeCache.getCurrentSourceFile(fileName));
|
||||
}
|
||||
|
||||
function isTsOrTsxFile(fileName: string): boolean {
|
||||
const kind = getScriptKind(fileName, host);
|
||||
return kind === ScriptKind.TS || kind === ScriptKind.TSX;
|
||||
}
|
||||
|
||||
function getSemanticClassifications(fileName: string, span: TextSpan): ClassifiedSpan[] {
|
||||
if (!isTsOrTsxFile(fileName)) {
|
||||
// do not run semantic classification on non-ts-or-tsx files
|
||||
return [];
|
||||
}
|
||||
synchronizeHostData();
|
||||
return ts.getSemanticClassifications(program.getTypeChecker(), cancellationToken, getValidSourceFile(fileName), program.getClassifiableNames(), span);
|
||||
}
|
||||
|
||||
function getEncodedSemanticClassifications(fileName: string, span: TextSpan): Classifications {
|
||||
if (!isTsOrTsxFile(fileName)) {
|
||||
// do not run semantic classification on non-ts-or-tsx files
|
||||
return { spans: [], endOfLineState: EndOfLineState.None };
|
||||
}
|
||||
synchronizeHostData();
|
||||
return ts.getEncodedSemanticClassifications(program.getTypeChecker(), cancellationToken, getValidSourceFile(fileName), program.getClassifiableNames(), span);
|
||||
}
|
||||
@@ -1632,6 +1663,34 @@ namespace ts {
|
||||
return [];
|
||||
}
|
||||
|
||||
function getCodeFixesAtPosition(fileName: string, start: number, end: number, errorCodes: number[]): CodeAction[] {
|
||||
synchronizeHostData();
|
||||
const sourceFile = getValidSourceFile(fileName);
|
||||
const span = { start, length: end - start };
|
||||
const newLineChar = getNewLineOrDefaultFromHost(host);
|
||||
|
||||
let allFixes: CodeAction[] = [];
|
||||
|
||||
forEach(errorCodes, error => {
|
||||
cancellationToken.throwIfCancellationRequested();
|
||||
|
||||
const context = {
|
||||
errorCode: error,
|
||||
sourceFile: sourceFile,
|
||||
span: span,
|
||||
program: program,
|
||||
newLineCharacter: newLineChar
|
||||
};
|
||||
|
||||
const fixes = codefix.getFixes(context);
|
||||
if (fixes) {
|
||||
allFixes = allFixes.concat(fixes);
|
||||
}
|
||||
});
|
||||
|
||||
return allFixes;
|
||||
}
|
||||
|
||||
function getDocCommentTemplateAtPosition(fileName: string, position: number): TextInsertion {
|
||||
return JsDoc.getDocCommentTemplateAtPosition(getNewLineOrDefaultFromHost(host), syntaxTreeCache.getCurrentSourceFile(fileName), position);
|
||||
}
|
||||
@@ -1846,6 +1905,7 @@ namespace ts {
|
||||
getRenameInfo,
|
||||
findRenameLocations,
|
||||
getNavigationBarItems,
|
||||
getNavigationTree,
|
||||
getOutliningSpans,
|
||||
getTodoComments,
|
||||
getBraceMatchingAtPosition,
|
||||
@@ -1855,6 +1915,7 @@ namespace ts {
|
||||
getFormattingEditsAfterKeystroke,
|
||||
getDocCommentTemplateAtPosition,
|
||||
isValidBraceCompletionAtPosition,
|
||||
getCodeFixesAtPosition,
|
||||
getEmitOutput,
|
||||
getNonBoundSourceFile,
|
||||
getSourceFile,
|
||||
|
||||
@@ -224,6 +224,9 @@ namespace ts {
|
||||
*/
|
||||
getNavigationBarItems(fileName: string): string;
|
||||
|
||||
/** Returns a JSON-encoded value of the type ts.NavigationTree. */
|
||||
getNavigationTree(fileName: string): string;
|
||||
|
||||
/**
|
||||
* Returns a JSON-encoded value of the type:
|
||||
* { textSpan: { start: number, length: number }; hintSpan: { start: number, length: number }; bannerText: string; autoCollapse: boolean } [] = [];
|
||||
@@ -971,6 +974,13 @@ namespace ts {
|
||||
);
|
||||
}
|
||||
|
||||
public getNavigationTree(fileName: string): string {
|
||||
return this.forwardJSONCall(
|
||||
`getNavigationTree('${fileName}')`,
|
||||
() => this.languageService.getNavigationTree(fileName)
|
||||
);
|
||||
}
|
||||
|
||||
public getOutliningSpans(fileName: string): string {
|
||||
return this.forwardJSONCall(
|
||||
`getOutliningSpans('${fileName}')`,
|
||||
|
||||
@@ -114,12 +114,12 @@ namespace ts.SymbolDisplay {
|
||||
}
|
||||
|
||||
// try get the call/construct signature from the type if it matches
|
||||
let callExpression: CallExpression;
|
||||
let callExpression: CallExpression | NewExpression;
|
||||
if (location.kind === SyntaxKind.CallExpression || location.kind === SyntaxKind.NewExpression) {
|
||||
callExpression = <CallExpression>location;
|
||||
callExpression = <CallExpression | NewExpression>location;
|
||||
}
|
||||
else if (isCallExpressionTarget(location) || isNewExpressionTarget(location)) {
|
||||
callExpression = <CallExpression>location.parent;
|
||||
callExpression = <CallExpression | NewExpression>location.parent;
|
||||
}
|
||||
|
||||
if (callExpression) {
|
||||
|
||||
@@ -79,6 +79,8 @@
|
||||
"formatting/rulesMap.ts",
|
||||
"formatting/rulesProvider.ts",
|
||||
"formatting/smartIndenter.ts",
|
||||
"formatting/tokenRange.ts"
|
||||
"formatting/tokenRange.ts",
|
||||
"codeFixes/codeFixProvider.ts",
|
||||
"codeFixes/fixes.ts"
|
||||
]
|
||||
}
|
||||
+62
-17
@@ -225,6 +225,7 @@ namespace ts {
|
||||
|
||||
getNavigateToItems(searchValue: string, maxResultCount?: number, fileName?: string, excludeDtsFiles?: boolean): NavigateToItem[];
|
||||
getNavigationBarItems(fileName: string): NavigationBarItem[];
|
||||
getNavigationTree(fileName: string): NavigationTree;
|
||||
|
||||
getOutliningSpans(fileName: string): OutliningSpan[];
|
||||
getTodoComments(fileName: string, descriptors: TodoCommentDescriptor[]): TodoComment[];
|
||||
@@ -239,6 +240,8 @@ namespace ts {
|
||||
|
||||
isValidBraceCompletionAtPosition(fileName: string, position: number, openingBrace: number): boolean;
|
||||
|
||||
getCodeFixesAtPosition(fileName: string, start: number, end: number, errorCodes: number[]): CodeAction[];
|
||||
|
||||
getEmitOutput(fileName: string, emitOnlyDtsFiles?: boolean): EmitOutput;
|
||||
|
||||
getProgram(): Program;
|
||||
@@ -264,6 +267,12 @@ namespace ts {
|
||||
classificationType: string; // ClassificationTypeNames
|
||||
}
|
||||
|
||||
/**
|
||||
* Navigation bar interface designed for visual studio's dual-column layout.
|
||||
* This does not form a proper tree.
|
||||
* The navbar is returned as a list of top-level items, each of which has a list of child items.
|
||||
* Child items always have an empty array for their `childItems`.
|
||||
*/
|
||||
export interface NavigationBarItem {
|
||||
text: string;
|
||||
kind: string;
|
||||
@@ -275,6 +284,26 @@ namespace ts {
|
||||
grayed: boolean;
|
||||
}
|
||||
|
||||
/**
|
||||
* Node in a tree of nested declarations in a file.
|
||||
* The top node is always a script or module node.
|
||||
*/
|
||||
export interface NavigationTree {
|
||||
/** Name of the declaration, or a short description, e.g. "<class>". */
|
||||
text: string;
|
||||
/** A ScriptElementKind */
|
||||
kind: string;
|
||||
/** ScriptElementKindModifier separated by commas, e.g. "public,abstract" */
|
||||
kindModifiers: string;
|
||||
/**
|
||||
* Spans of the nodes that generated this declaration.
|
||||
* There will be more than one if this is the result of merging.
|
||||
*/
|
||||
spans: TextSpan[];
|
||||
/** Present if non-empty */
|
||||
childItems?: NavigationTree[];
|
||||
}
|
||||
|
||||
export interface TodoCommentDescriptor {
|
||||
text: string;
|
||||
priority: number;
|
||||
@@ -291,6 +320,18 @@ namespace ts {
|
||||
newText: string;
|
||||
}
|
||||
|
||||
export interface FileTextChanges {
|
||||
fileName: string;
|
||||
textChanges: TextChange[];
|
||||
}
|
||||
|
||||
export interface CodeAction {
|
||||
/** Description of the code action to display in the UI of the editor */
|
||||
description: string;
|
||||
/** Text changes to apply to each file as part of the code action */
|
||||
changes: FileTextChanges[];
|
||||
}
|
||||
|
||||
export interface TextInsertion {
|
||||
newText: string;
|
||||
/** The position in newText the caret should point to after the insertion. */
|
||||
@@ -362,11 +403,11 @@ namespace ts {
|
||||
|
||||
export interface EditorSettings {
|
||||
baseIndentSize?: number;
|
||||
indentSize: number;
|
||||
tabSize: number;
|
||||
newLineCharacter: string;
|
||||
convertTabsToSpaces: boolean;
|
||||
indentStyle: IndentStyle;
|
||||
indentSize?: number;
|
||||
tabSize?: number;
|
||||
newLineCharacter?: string;
|
||||
convertTabsToSpaces?: boolean;
|
||||
indentStyle?: IndentStyle;
|
||||
}
|
||||
|
||||
/* @deprecated - consider using FormatCodeSettings instead */
|
||||
@@ -387,19 +428,19 @@ namespace ts {
|
||||
}
|
||||
|
||||
export interface FormatCodeSettings extends EditorSettings {
|
||||
insertSpaceAfterCommaDelimiter: boolean;
|
||||
insertSpaceAfterSemicolonInForStatements: boolean;
|
||||
insertSpaceBeforeAndAfterBinaryOperators: boolean;
|
||||
insertSpaceAfterKeywordsInControlFlowStatements: boolean;
|
||||
insertSpaceAfterFunctionKeywordForAnonymousFunctions: boolean;
|
||||
insertSpaceAfterOpeningAndBeforeClosingNonemptyParenthesis: boolean;
|
||||
insertSpaceAfterOpeningAndBeforeClosingNonemptyBrackets: boolean;
|
||||
insertSpaceAfterCommaDelimiter?: boolean;
|
||||
insertSpaceAfterSemicolonInForStatements?: boolean;
|
||||
insertSpaceBeforeAndAfterBinaryOperators?: boolean;
|
||||
insertSpaceAfterKeywordsInControlFlowStatements?: boolean;
|
||||
insertSpaceAfterFunctionKeywordForAnonymousFunctions?: boolean;
|
||||
insertSpaceAfterOpeningAndBeforeClosingNonemptyParenthesis?: boolean;
|
||||
insertSpaceAfterOpeningAndBeforeClosingNonemptyBrackets?: boolean;
|
||||
insertSpaceAfterOpeningAndBeforeClosingNonemptyBraces?: boolean;
|
||||
insertSpaceAfterOpeningAndBeforeClosingTemplateStringBraces: boolean;
|
||||
insertSpaceAfterOpeningAndBeforeClosingJsxExpressionBraces: boolean;
|
||||
insertSpaceAfterOpeningAndBeforeClosingTemplateStringBraces?: boolean;
|
||||
insertSpaceAfterOpeningAndBeforeClosingJsxExpressionBraces?: boolean;
|
||||
insertSpaceAfterTypeAssertion?: boolean;
|
||||
placeOpenBraceOnNewLineForFunctions: boolean;
|
||||
placeOpenBraceOnNewLineForControlBlocks: boolean;
|
||||
placeOpenBraceOnNewLineForFunctions?: boolean;
|
||||
placeOpenBraceOnNewLineForControlBlocks?: boolean;
|
||||
}
|
||||
|
||||
export interface DefinitionInfo {
|
||||
@@ -505,7 +546,11 @@ namespace ts {
|
||||
export interface CompletionInfo {
|
||||
isGlobalCompletion: boolean;
|
||||
isMemberCompletion: boolean;
|
||||
isNewIdentifierLocation: boolean; // true when the current location also allows for a new identifier
|
||||
|
||||
/**
|
||||
* true when the current location also allows for a new identifier
|
||||
*/
|
||||
isNewIdentifierLocation: boolean;
|
||||
entries: CompletionEntry[];
|
||||
}
|
||||
|
||||
|
||||
@@ -376,7 +376,7 @@ namespace ts {
|
||||
return true;
|
||||
case SyntaxKind.Identifier:
|
||||
// 'this' as a parameter
|
||||
return (node as Identifier).originalKeywordKind === SyntaxKind.ThisKeyword && node.parent.kind === SyntaxKind.Parameter;
|
||||
return identifierIsThisKeyword(node as Identifier) && node.parent.kind === SyntaxKind.Parameter;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user