mirror of
https://github.com/microsoft/TypeScript.git
synced 2025-11-18 17:21:48 +00:00
Merge branch 'master' of https://github.com/Microsoft/TypeScript
This commit is contained in:
@@ -648,6 +648,10 @@ module ts {
|
||||
return SyntaxKind.FirstKeyword <= token && token <= SyntaxKind.LastKeyword;
|
||||
}
|
||||
|
||||
export function isTrivia(token: SyntaxKind) {
|
||||
return SyntaxKind.FirstTriviaToken <= token && token <= SyntaxKind.LastTriviaToken;
|
||||
}
|
||||
|
||||
export function isModifier(token: SyntaxKind): boolean {
|
||||
switch (token) {
|
||||
case SyntaxKind.PublicKeyword:
|
||||
|
||||
@@ -959,10 +959,9 @@ module FourSlash {
|
||||
var help = this.languageService.getSignatureHelpItems(this.activeFile.fileName, this.currentCaretPosition);
|
||||
|
||||
var item = help.items[help.selectedItemIndex];
|
||||
var state = this.languageService.getSignatureHelpCurrentArgumentState(this.activeFile.fileName, this.currentCaretPosition, help.applicableSpan.start());
|
||||
|
||||
|
||||
// Same logic as in getActiveSignatureHelp - this value might be -1 until a parameter value actually gets typed
|
||||
var currentParam = state === undefined ? 0 : state.argumentIndex;
|
||||
var currentParam = help.argumentIndex < 0 ? 0 : help.argumentIndex;
|
||||
return item.parameters[currentParam];
|
||||
}
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@ class UnitTestRunner extends RunnerBase {
|
||||
}
|
||||
|
||||
public initializeTests() {
|
||||
this.tests = this.enumerateFiles('tests/cases/unittests/services');
|
||||
this.tests = this.enumerateFiles('tests/cases/unittests/services', /\.ts/i);
|
||||
|
||||
var outfile = new Harness.Compiler.WriterAggregator()
|
||||
var outerr = new Harness.Compiler.WriterAggregator();
|
||||
|
||||
@@ -174,7 +174,7 @@ module ts.formatting {
|
||||
|
||||
function childStartsOnTheSameLineWithElseInIfStatement(parent: Node, child: Node, childStartLine: number, sourceFile: SourceFile): boolean {
|
||||
if (parent.kind === SyntaxKind.IfStatement && (<IfStatement>parent).elseStatement === child) {
|
||||
var elseKeyword = forEach(parent.getChildren(), c => c.kind === SyntaxKind.ElseKeyword && c);
|
||||
var elseKeyword = findChildOfKind(parent, SyntaxKind.ElseKeyword, sourceFile);
|
||||
Debug.assert(elseKeyword);
|
||||
|
||||
var elseKeywordStartLine = getStartLineAndCharacterForNode(elseKeyword, sourceFile).line;
|
||||
@@ -383,7 +383,7 @@ module ts.formatting {
|
||||
return isCompletedNode((<WhileStatement>n).statement, sourceFile);
|
||||
case SyntaxKind.DoStatement:
|
||||
// rough approximation: if DoStatement has While keyword - then if node is completed is checking the presence of ')';
|
||||
var hasWhileKeyword = forEach(n.getChildren(), c => c.kind === SyntaxKind.WhileKeyword && c);
|
||||
var hasWhileKeyword = findChildOfKind(n, SyntaxKind.WhileKeyword, sourceFile);
|
||||
if(hasWhileKeyword) {
|
||||
return nodeEndsWith(n, SyntaxKind.CloseParenToken, sourceFile);
|
||||
}
|
||||
|
||||
@@ -60,18 +60,24 @@ module ts {
|
||||
case SyntaxKind.TryBlock:
|
||||
case SyntaxKind.CatchBlock:
|
||||
case SyntaxKind.FinallyBlock:
|
||||
var openBrace = forEach(n.getChildren(), c => c.kind === SyntaxKind.OpenBraceToken && c);
|
||||
var closeBrace = forEach(n.getChildren(), c => c.kind === SyntaxKind.CloseBraceToken && c);
|
||||
var openBrace = findChildOfKind(n, SyntaxKind.OpenBraceToken, sourceFile);
|
||||
var closeBrace = findChildOfKind(n, SyntaxKind.CloseBraceToken, sourceFile);
|
||||
addOutlineRange(n.parent, openBrace, closeBrace);
|
||||
break;
|
||||
case SyntaxKind.ClassDeclaration:
|
||||
case SyntaxKind.InterfaceDeclaration:
|
||||
case SyntaxKind.EnumDeclaration:
|
||||
case SyntaxKind.ObjectLiteral:
|
||||
var openBrace = forEach(n.getChildren(), c => c.kind === SyntaxKind.OpenBraceToken && c);
|
||||
var closeBrace = forEach(n.getChildren(), c => c.kind === SyntaxKind.CloseBraceToken && c);
|
||||
case SyntaxKind.SwitchStatement:
|
||||
var openBrace = findChildOfKind(n, SyntaxKind.OpenBraceToken, sourceFile);
|
||||
var closeBrace = findChildOfKind(n, SyntaxKind.CloseBraceToken, sourceFile);
|
||||
addOutlineRange(n, openBrace, closeBrace);
|
||||
break;
|
||||
case SyntaxKind.ArrayLiteral:
|
||||
var openBracket = findChildOfKind(n, SyntaxKind.OpenBracketToken, sourceFile);
|
||||
var closeBracket = findChildOfKind(n, SyntaxKind.CloseBracketToken, sourceFile);
|
||||
addOutlineRange(n, openBracket, closeBracket);
|
||||
break;
|
||||
}
|
||||
depth++;
|
||||
forEachChild(n, walk);
|
||||
|
||||
+16
-27
@@ -651,16 +651,18 @@ module ts {
|
||||
getCompletionsAtPosition(fileName: string, position: number, isMemberCompletion: boolean): CompletionInfo;
|
||||
getCompletionEntryDetails(fileName: string, position: number, entryName: string): CompletionEntryDetails;
|
||||
|
||||
getTypeAtPosition(fileName: string, position: number): TypeInfo;
|
||||
getQuickInfoAtPosition(fileName: string, position: number): QuickInfo;
|
||||
|
||||
// Obsolete. Use getQuickInfoAtPosition instead.
|
||||
getTypeAtPosition(fileName: string, position: number): TypeInfo;
|
||||
|
||||
getNameOrDottedNameSpan(fileName: string, startPos: number, endPos: number): TypeScript.TextSpan;
|
||||
|
||||
getBreakpointStatementAtPosition(fileName: string, position: number): TypeScript.TextSpan;
|
||||
|
||||
getSignatureHelpItems(fileName: string, position: number): SignatureHelpItems;
|
||||
getSignatureHelpCurrentArgumentState(fileName: string, position: number, applicableSpanStart: number): SignatureHelpState;
|
||||
|
||||
// Obsolete. Use getSignatureHelpItems instead.
|
||||
getSignatureAtPosition(fileName: string, position: number): SignatureInfo;
|
||||
|
||||
getRenameInfo(fileName: string, position: number): RenameInfo;
|
||||
@@ -861,9 +863,6 @@ module ts {
|
||||
items: SignatureHelpItem[];
|
||||
applicableSpan: TypeScript.TextSpan;
|
||||
selectedItemIndex: number;
|
||||
}
|
||||
|
||||
export interface SignatureHelpState {
|
||||
argumentIndex: number;
|
||||
argumentCount: number;
|
||||
}
|
||||
@@ -1032,6 +1031,7 @@ module ts {
|
||||
static none = "";
|
||||
static publicMemberModifier = "public";
|
||||
static privateMemberModifier = "private";
|
||||
static protectedMemberModifier = "protected";
|
||||
static exportedModifier = "export";
|
||||
static ambientModifier = "declare";
|
||||
static staticModifier = "static";
|
||||
@@ -2354,6 +2354,7 @@ module ts {
|
||||
var result: string[] = [];
|
||||
|
||||
if (flags & NodeFlags.Private) result.push(ScriptElementKindModifier.privateMemberModifier);
|
||||
if (flags & NodeFlags.Protected) result.push(ScriptElementKindModifier.protectedMemberModifier);
|
||||
if (flags & NodeFlags.Public) result.push(ScriptElementKindModifier.publicMemberModifier);
|
||||
if (flags & NodeFlags.Static) result.push(ScriptElementKindModifier.staticModifier);
|
||||
if (flags & NodeFlags.Export) result.push(ScriptElementKindModifier.exportedModifier);
|
||||
@@ -3765,16 +3766,6 @@ module ts {
|
||||
return SignatureHelp.getSignatureHelpItems(sourceFile, position, typeInfoResolver, cancellationToken);
|
||||
}
|
||||
|
||||
/**
|
||||
* This is a syntactic operation
|
||||
*/
|
||||
function getSignatureHelpCurrentArgumentState(fileName: string, position: number, applicableSpanStart: number): SignatureHelpState {
|
||||
fileName = TypeScript.switchToForwardSlashes(fileName);
|
||||
var sourceFile = getCurrentSourceFile(fileName);
|
||||
|
||||
return SignatureHelp.getSignatureHelpCurrentArgumentState(sourceFile, position, applicableSpanStart);
|
||||
}
|
||||
|
||||
function getSignatureAtPosition(filename: string, position: number): SignatureInfo {
|
||||
var signatureHelpItems = getSignatureHelpItems(filename, position);
|
||||
|
||||
@@ -3782,7 +3773,7 @@ module ts {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
var currentArguemntState = getSignatureHelpCurrentArgumentState(filename, position, signatureHelpItems.applicableSpan.start());
|
||||
var currentArgumentState = { argumentIndex: signatureHelpItems.argumentIndex, argumentCount: signatureHelpItems.argumentCount };
|
||||
|
||||
var formalSignatures: FormalSignatureItemInfo[] = [];
|
||||
forEach(signatureHelpItems.items, signature => {
|
||||
@@ -3827,7 +3818,7 @@ module ts {
|
||||
parameterMinChar: signatureHelpItems.applicableSpan.start(),
|
||||
parameterLimChar: signatureHelpItems.applicableSpan.end(),
|
||||
currentParameterIsTypeParameter: false,
|
||||
currentParameter: currentArguemntState.argumentIndex
|
||||
currentParameter: currentArgumentState.argumentIndex
|
||||
};
|
||||
|
||||
return {
|
||||
@@ -4465,7 +4456,6 @@ module ts {
|
||||
getCompletionEntryDetails: getCompletionEntryDetails,
|
||||
getTypeAtPosition: getTypeAtPosition,
|
||||
getSignatureHelpItems: getSignatureHelpItems,
|
||||
getSignatureHelpCurrentArgumentState: getSignatureHelpCurrentArgumentState,
|
||||
getQuickInfoAtPosition: getQuickInfoAtPosition,
|
||||
getDefinitionAtPosition: getDefinitionAtPosition,
|
||||
getReferencesAtPosition: getReferencesAtPosition,
|
||||
@@ -4550,17 +4540,16 @@ module ts {
|
||||
do {
|
||||
token = scanner.scan();
|
||||
|
||||
if ((token === SyntaxKind.SlashToken || token === SyntaxKind.SlashEqualsToken) && !noRegexTable[lastNonTriviaToken]) {
|
||||
if (scanner.reScanSlashToken() === SyntaxKind.RegularExpressionLiteral) {
|
||||
token = SyntaxKind.RegularExpressionLiteral;
|
||||
if (!isTrivia(token)) {
|
||||
if ((token === SyntaxKind.SlashToken || token === SyntaxKind.SlashEqualsToken) && !noRegexTable[lastNonTriviaToken]) {
|
||||
if (scanner.reScanSlashToken() === SyntaxKind.RegularExpressionLiteral) {
|
||||
token = SyntaxKind.RegularExpressionLiteral;
|
||||
}
|
||||
}
|
||||
else if (lastNonTriviaToken === SyntaxKind.DotToken && isKeyword(token)) {
|
||||
token = SyntaxKind.Identifier;
|
||||
}
|
||||
}
|
||||
else if (lastNonTriviaToken === SyntaxKind.DotToken) {
|
||||
token = SyntaxKind.Identifier;
|
||||
}
|
||||
|
||||
// Only recall the token if it was *not* trivia.
|
||||
if (!(SyntaxKind.FirstTriviaToken <= token && token <= SyntaxKind.LastTriviaToken)) {
|
||||
lastNonTriviaToken = token;
|
||||
}
|
||||
|
||||
|
||||
+3
-10
@@ -84,14 +84,16 @@ module ts {
|
||||
getCompletionEntryDetails(fileName: string, position: number, entryName: string): string;
|
||||
|
||||
getQuickInfoAtPosition(fileName: string, position: number): string;
|
||||
|
||||
// Obsolete. Use getQuickInfoAtPosition instead.
|
||||
getTypeAtPosition(fileName: string, position: number): string;
|
||||
|
||||
getNameOrDottedNameSpan(fileName: string, startPos: number, endPos: number): string;
|
||||
getBreakpointStatementAtPosition(fileName: string, position: number): string;
|
||||
|
||||
getSignatureHelpItems(fileName: string, position: number): string;
|
||||
getSignatureHelpCurrentArgumentState(fileName: string, position: number, applicableSpanStart: number): string;
|
||||
|
||||
// Obsolete. Use getSignatureHelpItems instead.
|
||||
getSignatureAtPosition(fileName: string, position: number): string;
|
||||
|
||||
/**
|
||||
@@ -617,15 +619,6 @@ module ts {
|
||||
});
|
||||
}
|
||||
|
||||
public getSignatureHelpCurrentArgumentState(fileName: string, position: number, applicableSpanStart: number): string {
|
||||
return this.forwardJSONCall(
|
||||
"getSignatureHelpCurrentArgumentState('" + fileName + "', " + position + ", " + applicableSpanStart + ")",
|
||||
() => {
|
||||
var signatureHelpState = this.languageService.getSignatureHelpCurrentArgumentState(fileName, position, applicableSpanStart);
|
||||
return signatureHelpState;
|
||||
});
|
||||
}
|
||||
|
||||
public getSignatureAtPosition(fileName: string, position: number): string {
|
||||
return this.forwardJSONCall(
|
||||
"getSignatureAtPosition('" + fileName + "', " + position + ")",
|
||||
|
||||
@@ -337,15 +337,19 @@ module ts.SignatureHelp {
|
||||
var applicableSpanStart = argumentListOrTypeArgumentList.getFullStart();
|
||||
var applicableSpanEnd = skipTrivia(sourceFile.text, argumentListOrTypeArgumentList.end, /*stopAfterLineBreak*/ false);
|
||||
var applicableSpan = new TypeScript.TextSpan(applicableSpanStart, applicableSpanEnd - applicableSpanStart);
|
||||
|
||||
var state = getSignatureHelpCurrentArgumentState(sourceFile, position, applicableSpanStart);
|
||||
return {
|
||||
items: items,
|
||||
applicableSpan: applicableSpan,
|
||||
selectedItemIndex: selectedItemIndex
|
||||
selectedItemIndex: selectedItemIndex,
|
||||
argumentIndex: state.argumentIndex,
|
||||
argumentCount: state.argumentCount
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
export function getSignatureHelpCurrentArgumentState(sourceFile: SourceFile, position: number, applicableSpanStart: number): SignatureHelpState {
|
||||
function getSignatureHelpCurrentArgumentState(sourceFile: SourceFile, position: number, applicableSpanStart: number): { argumentIndex: number; argumentCount: number } {
|
||||
var tokenPrecedingSpanStart = findPrecedingToken(applicableSpanStart, sourceFile);
|
||||
if (!tokenPrecedingSpanStart) {
|
||||
return undefined;
|
||||
|
||||
@@ -16,6 +16,10 @@ module ts {
|
||||
};
|
||||
}
|
||||
|
||||
export function findChildOfKind(n: Node, kind: SyntaxKind, sourceFile?: SourceFile): Node {
|
||||
return forEach(n.getChildren(sourceFile), c => c.kind === kind && c);
|
||||
}
|
||||
|
||||
export function findContainingList(node: Node): Node {
|
||||
// The node might be a list element (nonsynthetic) or a comma (synthetic). Either way, it will
|
||||
// be parented by the container of the SyntaxList, not the SyntaxList itself.
|
||||
|
||||
Reference in New Issue
Block a user