From f979694e3d54b1a14a508dc7a4c6361c5ac5f700 Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Mon, 9 Feb 2015 22:55:32 -0800 Subject: [PATCH] Classify newlines as whitespace in the classifier. --- src/services/services.ts | 40 +++++++++++++++++++++------------------- 1 file changed, 21 insertions(+), 19 deletions(-) diff --git a/src/services/services.ts b/src/services/services.ts index eda3a4aeff6..ca6b26fec12 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -5715,36 +5715,36 @@ module ts { } } else if (lastNonTriviaToken === SyntaxKind.DotToken && isKeyword(token)) { - token = SyntaxKind.Identifier; + token = SyntaxKind.Identifier; } else if (isKeyword(lastNonTriviaToken) && isKeyword(token) && !canFollow(lastNonTriviaToken, token)) { - // We have two keywords in a row. Only treat the second as a keyword if - // it's a sequence that could legally occur in the language. Otherwise - // treat it as an identifier. This way, if someone writes "private var" - // we recognize that 'var' is actually an identifier here. - token = SyntaxKind.Identifier; + // We have two keywords in a row. Only treat the second as a keyword if + // it's a sequence that could legally occur in the language. Otherwise + // treat it as an identifier. This way, if someone writes "private var" + // we recognize that 'var' is actually an identifier here. + token = SyntaxKind.Identifier; } else if (lastNonTriviaToken === SyntaxKind.Identifier && token === SyntaxKind.LessThanToken) { - // Could be the start of something generic. Keep track of that by bumping - // up the current count of generic contexts we may be in. - angleBracketStack++; + // Could be the start of something generic. Keep track of that by bumping + // up the current count of generic contexts we may be in. + angleBracketStack++; } else if (token === SyntaxKind.GreaterThanToken && angleBracketStack > 0) { - // If we think we're currently in something generic, then mark that that - // generic entity is complete. - angleBracketStack--; + // If we think we're currently in something generic, then mark that that + // generic entity is complete. + angleBracketStack--; } else if (token === SyntaxKind.AnyKeyword || token === SyntaxKind.StringKeyword || token === SyntaxKind.NumberKeyword || token === SyntaxKind.BooleanKeyword) { - if (angleBracketStack > 0 && !classifyKeywordsInGenerics) { - // If it looks like we're could be in something generic, don't classify this - // as a keyword. We may just get overwritten by the syntactic classifier, - // causing a noisy experience for the user. - token = SyntaxKind.Identifier; - } + if (angleBracketStack > 0 && !classifyKeywordsInGenerics) { + // If it looks like we're could be in something generic, don't classify this + // as a keyword. We may just get overwritten by the syntactic classifier, + // causing a noisy experience for the user. + token = SyntaxKind.Identifier; + } } lastNonTriviaToken = token; @@ -5844,7 +5844,8 @@ module ts { case SyntaxKind.EqualsToken: case SyntaxKind.CommaToken: return true; - default: return false; + default: + return false; } } @@ -5889,6 +5890,7 @@ module ts { case SyntaxKind.SingleLineCommentTrivia: return TokenClass.Comment; case SyntaxKind.WhitespaceTrivia: + case SyntaxKind.NewLineTrivia: return TokenClass.Whitespace; case SyntaxKind.Identifier: default: