Skip to content

Commit 1dca562

Browse files
Addressed CR feedback.
1 parent 65e23b1 commit 1dca562

File tree

1 file changed

+41
-4
lines changed

1 file changed

+41
-4
lines changed

Diff for: src/services/services.ts

+41-4
Original file line numberDiff line numberDiff line change
@@ -1171,7 +1171,26 @@ module ts {
11711171
}
11721172

11731173
export interface Classifier {
1174-
getClassificationsForLine(text: string, lexState: EndOfLineState, syntacticClassifierAbsent?: boolean): ClassificationResult;
1174+
/**
1175+
* Gives lexical classifications of tokens on a line without any syntactic context.
1176+
* For instance, a token consisting of the text 'string' can be either an identifier
1177+
* named 'string' or the keyword 'string', however, because this classifier is not aware,
1178+
* it relies on certain heuristics to give acceptable results. For classifications where
1179+
* speed trumps accuracy, this function is preferable; however, for true accuracy, the
1180+
* syntactic classifier is ideal. In fact, in certain editing scenarios, combining the
1181+
* lexical, syntactic, and semantic classifiers may issue the best user experience.
1182+
*
1183+
* @param text The text of a line to classify.
1184+
* @param lexState The state of the lexical classifier at the end of the previous line.
1185+
* @param syntacticClassifierAbsent Whether the client is *not* using a syntactic classifier.
1186+
* If there is no syntactic classifier (syntacticClassifierAbsent=true),
1187+
* certain heuristics may be used in its place; however, if there is a
1188+
* syntactic classifier (syntacticClassifierAbsent=false), certain
1189+
* classifications which may be incorrectly categorized will be given
1190+
* back as Identifiers in order to allow the syntactic classifier to
1191+
* subsume the classification.
1192+
*/
1193+
getClassificationsForLine(text: string, lexState: EndOfLineState, syntacticClassifierAbsent: boolean): ClassificationResult;
11751194
}
11761195

11771196
/**
@@ -5620,8 +5639,26 @@ module ts {
56205639
noRegexTable[SyntaxKind.TrueKeyword] = true;
56215640
noRegexTable[SyntaxKind.FalseKeyword] = true;
56225641

5623-
// Just a stack of TemplateHeads and OpenCurlyBraces, used
5624-
// to perform rudimentary classification on templates.
5642+
// Just a stack of TemplateHeads and OpenCurlyBraces, used to perform rudimentary (inexact)
5643+
// classification on template strings. Because of the context free nature of templates,
5644+
// the only precise way to classify a template portion would be by propagating the stack across
5645+
// lines, just as we do with the end-of-line state. However, this is a burden for implementers,
5646+
// and the behavior is entirely subsumed by the syntactic classifier anyway, so we instead
5647+
// flatten any nesting when the template stack is non-empty and encode it in the end-of-line state.
5648+
// Situations in which this fails are
5649+
// 1) When template strings are nested across different lines:
5650+
// `hello ${ `world
5651+
// ` }`
5652+
//
5653+
// Where on the second line, you will get the closing of a template,
5654+
// a closing curly, and a new template.
5655+
//
5656+
// 2) When substitution expressions have curly braces and the curly brace falls on the next line:
5657+
// `hello ${ () => {
5658+
// return "world" } } `
5659+
//
5660+
// Where on the second line, you will get the 'return' keyword,
5661+
// a string literal, and a template end consisting of '} } `'.
56255662
var templateStack: SyntaxKind[] = [];
56265663

56275664
function isAccessibilityModifier(kind: SyntaxKind) {
@@ -5966,7 +6003,7 @@ module ts {
59666003
case SyntaxKind.Identifier:
59676004
default:
59686005
if (isTemplateLiteralKind(token)) {
5969-
return TokenClass.StringLiteral; // maybe make a TemplateLiteral
6006+
return TokenClass.StringLiteral;
59706007
}
59716008
return TokenClass.Identifier;
59726009
}

0 commit comments

Comments
 (0)