From e1b76523b3da721da04869c33b0e546ff5764956 Mon Sep 17 00:00:00 2001 From: Sheetal Nandi Date: Wed, 8 Oct 2014 12:19:11 -0700 Subject: [PATCH] Code review feedback - Show the type as any even inside the with block --- src/compiler/checker.ts | 25 ++++++++++++++----- src/compiler/parser.ts | 13 ---------- src/services/services.ts | 22 ++++++++-------- tests/cases/fourslash/quickInfoInWithBlock.ts | 6 ++--- 4 files changed, 32 insertions(+), 34 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index c861558451e..953c97e8ead 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -967,22 +967,22 @@ module ts { // Enclosing declaration is optional when we don't want to get qualified name in the enclosing declaration scope // Meaning needs to be specified if the enclosing declaration is given function writeSymbol(symbol: Symbol, writer: SymbolWriter, enclosingDeclaration?: Node, meaning?: SymbolFlags, flags?: SymbolFormatFlags): void { - var previouslyWrittenSymbol: Symbol; + var parentSymbol: Symbol; function writeSymbolName(symbol: Symbol): void { - if (previouslyWrittenSymbol) { + if (parentSymbol) { // Write type arguments of instantiated class/interface here if (flags & SymbolFormatFlags.WriteTypeParametersOrArguments) { if (symbol.flags & SymbolFlags.Instantiated) { - writeTypeArguments(getTypeParametersOfClassOrInterface(previouslyWrittenSymbol), + writeTypeArguments(getTypeParametersOfClassOrInterface(parentSymbol), (symbol).mapper, writer, enclosingDeclaration); } else { - writeTypeParametersOfSymbol(previouslyWrittenSymbol, writer, enclosingDeclaration); + writeTypeParametersOfSymbol(parentSymbol, writer, enclosingDeclaration); } } writePunctuation(writer, SyntaxKind.DotToken); } - previouslyWrittenSymbol = symbol; + parentSymbol = symbol; if (symbol.declarations && symbol.declarations.length > 0) { var declaration = symbol.declarations[0]; if (declaration.name) { @@ -1022,7 +1022,7 @@ module ts { } else { // If we didn't find accessible symbol chain for this symbol, break if this is external module - if (!previouslyWrittenSymbol && ts.forEach(symbol.declarations, declaration => hasExternalModuleSymbol(declaration))) { + if (!parentSymbol && ts.forEach(symbol.declarations, declaration => hasExternalModuleSymbol(declaration))) { return; } @@ -6996,6 +6996,19 @@ module ts { return findChildAtPosition(sourceFile); } + function isInsideWithStatementBody(node: Node): boolean { + if (node) { + while (node.parent) { + if (node.parent.kind === SyntaxKind.WithStatement && (node.parent).statement === node) { + return true; + } + node = node.parent; + } + } + + return false; + } + function getSymbolsInScope(location: Node, meaning: SymbolFlags): Symbol[]{ var symbols: SymbolTable = {}; var memberFlags: NodeFlags = 0; diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index a35e3a11c85..b06326f6925 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -166,19 +166,6 @@ module ts { } } - export function isInsideWithStatementBody(node: Node): boolean { - if (node) { - while (node.parent) { - if (node.parent.kind === SyntaxKind.WithStatement && (node.parent).statement === node) { - return true; - } - node = node.parent; - } - } - - return false; - } - export var fullTripleSlashReferencePathRegEx = /^(\/\/\/\s*/ // Invokes a callback for each child of the given node. The 'cbNode' callback is invoked for all child nodes diff --git a/src/services/services.ts b/src/services/services.ts index 806e08f194e..46dd05a1698 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -2970,18 +2970,16 @@ module ts { case SyntaxKind.QualifiedName: case SyntaxKind.ThisKeyword: case SyntaxKind.SuperKeyword: - // For the identifiers/this/usper etc get the type at position if not inside if statement - if (!isInsideWithStatementBody(node)) { - var type = typeInfoResolver.getTypeOfNode(node); - if (type) { - return { - kind: ScriptElementKind.unknown, - kindModifiers: ScriptElementKindModifier.none, - textSpan: new TypeScript.TextSpan(node.getStart(), node.getWidth()), - displayParts: typeToDisplayParts(typeInfoResolver, type, getContainerNode(node)), - documentation: type.symbol ? type.symbol.getDocumentationComment() : undefined - }; - } + // For the identifiers/this/usper etc get the type at position + var type = typeInfoResolver.getTypeOfNode(node); + if (type) { + return { + kind: ScriptElementKind.unknown, + kindModifiers: ScriptElementKindModifier.none, + textSpan: new TypeScript.TextSpan(node.getStart(), node.getWidth()), + displayParts: typeToDisplayParts(typeInfoResolver, type, getContainerNode(node)), + documentation: type.symbol ? type.symbol.getDocumentationComment() : undefined + }; } } diff --git a/tests/cases/fourslash/quickInfoInWithBlock.ts b/tests/cases/fourslash/quickInfoInWithBlock.ts index 7da483172f6..c58ffa56560 100644 --- a/tests/cases/fourslash/quickInfoInWithBlock.ts +++ b/tests/cases/fourslash/quickInfoInWithBlock.ts @@ -7,10 +7,10 @@ goTo.marker('1'); -verify.not.quickInfoExists(); +verify.quickInfoIs("any"); goTo.marker('2'); -verify.not.quickInfoExists(); +verify.quickInfoIs("any"); goTo.marker('3'); -verify.not.quickInfoExists(); +verify.quickInfoIs("any"); \ No newline at end of file