Skip to content

Commit 1b8814c

Browse files
committed
Address PR feedback
1 parent c20e4f5 commit 1b8814c

File tree

3 files changed

+22
-10
lines changed

3 files changed

+22
-10
lines changed

src/compiler/checker.ts

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -993,9 +993,11 @@ module ts {
993993
// This is for caching the result of getSymbolDisplayBuilder. Do not access directly.
994994
var _displayBuilder: SymbolDisplayBuilder;
995995
function getSymbolDisplayBuilder(): SymbolDisplayBuilder {
996-
// Enclosing declaration is optional when we don't want to get qualified name in the enclosing declaration scope
997-
// Meaning needs to be specified if the enclosing declaration is given
998-
function buildPlainSymbolName(symbol: Symbol, writer: SymbolWriter): void {
996+
/**
997+
* Writes only the name of the symbol out to the writer. Uses the original source text
998+
* for the name of the symbol if it is available to match how the user inputted the name.
999+
*/
1000+
function appendSymbolNameOnly(symbol: Symbol, writer: SymbolWriter): void {
9991001
if (symbol.declarations && symbol.declarations.length > 0) {
10001002
var declaration = symbol.declarations[0];
10011003
if (declaration.name) {
@@ -1007,9 +1009,13 @@ module ts {
10071009
writer.writeSymbol(symbol.name, symbol);
10081010
}
10091011

1012+
/**
1013+
* Enclosing declaration is optional when we don't want to get qualified name in the enclosing declaration scope
1014+
* Meaning needs to be specified if the enclosing declaration is given
1015+
*/
10101016
function buildSymbolDisplay(symbol: Symbol, writer: SymbolWriter, enclosingDeclaration?: Node, meaning?: SymbolFlags, flags?: SymbolFormatFlags): void {
10111017
var parentSymbol: Symbol;
1012-
function appendSymbolName(symbol: Symbol): void {
1018+
function appendParentTypeArgumentsAndSymbolName(symbol: Symbol): void {
10131019
if (parentSymbol) {
10141020
// Write type arguments of instantiated class/interface here
10151021
if (flags & SymbolFormatFlags.WriteTypeParametersOrArguments) {
@@ -1024,7 +1030,7 @@ module ts {
10241030
writePunctuation(writer, SyntaxKind.DotToken);
10251031
}
10261032
parentSymbol = symbol;
1027-
buildPlainSymbolName(symbol, writer);
1033+
appendSymbolNameOnly(symbol, writer);
10281034
}
10291035

10301036
// Let the writer know we just wrote out a symbol. The declaration emitter writer uses
@@ -1050,7 +1056,7 @@ module ts {
10501056

10511057
if (accessibleSymbolChain) {
10521058
for (var i = 0, n = accessibleSymbolChain.length; i < n; i++) {
1053-
appendSymbolName(accessibleSymbolChain[i]);
1059+
appendParentTypeArgumentsAndSymbolName(accessibleSymbolChain[i]);
10541060
}
10551061
}
10561062
else {
@@ -1064,7 +1070,7 @@ module ts {
10641070
return;
10651071
}
10661072

1067-
appendSymbolName(symbol);
1073+
appendParentTypeArgumentsAndSymbolName(symbol);
10681074
}
10691075
}
10701076
}
@@ -1078,7 +1084,7 @@ module ts {
10781084
return;
10791085
}
10801086

1081-
return appendSymbolName(symbol);
1087+
return appendParentTypeArgumentsAndSymbolName(symbol);
10821088
}
10831089

10841090
function buildTypeDisplay(type: Type, writer: SymbolWriter, enclosingDeclaration?: Node, flags?: TypeFormatFlags, typeStack?: Type[]) {
@@ -1314,7 +1320,7 @@ module ts {
13141320
}
13151321

13161322
function buildTypeParameterDisplay(tp: TypeParameter, writer: SymbolWriter, enclosingDeclaration?: Node, flags?: TypeFormatFlags, typeStack?: Type[]) {
1317-
buildPlainSymbolName(tp.symbol, writer);
1323+
appendSymbolNameOnly(tp.symbol, writer);
13181324
var constraint = getConstraintOfTypeParameter(tp);
13191325
if (constraint) {
13201326
writeSpace(writer);
@@ -1328,7 +1334,7 @@ module ts {
13281334
if (getDeclarationFlagsFromSymbol(p) & NodeFlags.Rest) {
13291335
writePunctuation(writer, SyntaxKind.DotDotDotToken);
13301336
}
1331-
buildPlainSymbolName(p, writer);
1337+
appendSymbolNameOnly(p, writer);
13321338
if (p.valueDeclaration.flags & NodeFlags.QuestionMark || (<VariableDeclaration>p.valueDeclaration).initializer) {
13331339
writePunctuation(writer, SyntaxKind.QuestionToken);
13341340
}

src/compiler/parser.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2344,6 +2344,11 @@ module ts {
23442344
function parseTypeArguments(): NodeArray<TypeNode> {
23452345
var typeArgumentListStart = scanner.getTokenPos();
23462346
var errorCountBeforeTypeParameterList = file.syntacticErrors.length;
2347+
// We pass parseSingleTypeArgument instead of parseType as the element parser
2348+
// because parseSingleTypeArgument knows how to parse a missing type argument.
2349+
// This is useful for signature help. parseType has the disadvantage that when
2350+
// it sees a missing type, it changes the LookAheadMode to Error, and the result
2351+
// is a broken binary expression, which breaks signature help.
23472352
var result = parseBracketedList(ParsingContext.TypeArguments, parseSingleTypeArgument, SyntaxKind.LessThanToken, SyntaxKind.GreaterThanToken);
23482353
if (!result.length && file.syntacticErrors.length === errorCountBeforeTypeParameterList) {
23492354
grammarErrorAtPos(typeArgumentListStart, scanner.getStartPos() - typeArgumentListStart, Diagnostics.Type_argument_list_cannot_be_empty);

src/services/signatureHelp.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,7 @@ module ts.SignatureHelp {
261261
function getChildListThatStartsWithOpenerToken(parent: Node, openerToken: Node, sourceFile: SourceFile): Node {
262262
var children = parent.getChildren(sourceFile);
263263
var indexOfOpenerToken = children.indexOf(openerToken);
264+
Debug.assert(indexOfOpenerToken >= 0 && children.length > indexOfOpenerToken + 1);
264265
return children[indexOfOpenerToken + 1];
265266
}
266267

0 commit comments

Comments
 (0)