Skip to content

Commit a939a71

Browse files
committed
addressed CR feedback
1 parent c298f09 commit a939a71

File tree

2 files changed

+17
-7
lines changed

2 files changed

+17
-7
lines changed

src/services/services.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2088,7 +2088,7 @@ module ts {
20882088
}
20892089

20902090
// TODO: this is a hack for now, we need a proper walking mechanism to verify that we have the correct node
2091-
var mappedNode = getTouchingToken(sourceFile, TypeScript.end(node) - 1, /*allowPositionInLeadingTrivia*/ false);
2091+
var mappedNode = getTouchingToken(sourceFile, TypeScript.end(node) - 1);
20922092
if (isPunctuation(mappedNode.kind)) {
20932093
mappedNode = mappedNode.parent;
20942094
}
@@ -4022,7 +4022,7 @@ module ts {
40224022
var sourceFile = getCurrentSourceFile(filename);
40234023
var result: TypeScript.TextSpan[] = [];
40244024

4025-
var token = getTouchingToken(sourceFile, position, /*allowPositionInLeadingTrivia*/ false);
4025+
var token = getTouchingToken(sourceFile, position);
40264026

40274027
if (token.getStart(sourceFile) === position) {
40284028
var matchKind = getMatchingTokenKind(token);
@@ -4178,7 +4178,7 @@ module ts {
41784178

41794179
// OK, we have found a match in the file. This is only an acceptable match if
41804180
// it is contained within a comment.
4181-
var token = getTouchingToken(sourceFile, matchPosition, /*allowPositionInLeadingTrivia*/ true);
4181+
var token = getTokenAtPosition(sourceFile, matchPosition);
41824182

41834183
if (token.getStart() <= matchPosition && matchPosition < token.getEnd()) {
41844184
// match was within the token itself. Not in the comment. Keep searching

src/services/utilities.ts

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,18 +50,28 @@ module ts {
5050
* position >= start and (position < end or (position === end && token is keyword or identifier))
5151
*/
5252
export function getTouchingWord(sourceFile: SourceFile, position: number): Node {
53-
return getTouchingToken(sourceFile, position, /*allowPositionInLeadingTrivia*/ false, isWord);
53+
return getTouchingToken(sourceFile, position, isWord);
5454
}
5555

5656
/* Gets the token whose text has range [start, end) and position >= start
5757
* and (position < end or (position === end && token is keyword or identifier or numeric\string litera))
5858
*/
5959
export function getTouchingPropertyName(sourceFile: SourceFile, position: number): Node {
60-
return getTouchingToken(sourceFile, position, /*allowPositionInLeadingTrivia*/ false, isPropertyName);
60+
return getTouchingToken(sourceFile, position, isPropertyName);
61+
}
62+
63+
/** Returns the token if position is in [start, end) or if position === end and includeItemAtEndPosition(token) === true */
64+
export function getTouchingToken(sourceFile: SourceFile, position: number, includeItemAtEndPosition?: (n: Node) => boolean): Node {
65+
return getTokenAtPositionWorker(sourceFile, position, /*allowPositionInLeadingTrivia*/ false, includeItemAtEndPosition);
66+
}
67+
68+
/** Returns a token if position is in [start-of-leading-trivia, end) */
69+
export function getTokenAtPosition(sourceFile: SourceFile, position: number): Node {
70+
return getTokenAtPositionWorker(sourceFile, position, /*allowPositionInLeadingTrivia*/ true, /*includeItemAtEndPosition*/ undefined);
6171
}
6272

6373
/** Get the token whose text contains the position */
64-
export function getTouchingToken(sourceFile: SourceFile, position: number, allowPositionInLeadingTrivia: boolean, includeItemAtEndPosition?: (n: Node) => boolean): Node {
74+
function getTokenAtPositionWorker(sourceFile: SourceFile, position: number, allowPositionInLeadingTrivia: boolean, includeItemAtEndPosition: (n: Node) => boolean): Node {
6575
var current: Node = sourceFile;
6676
outer: while (true) {
6777
if (isToken(current)) {
@@ -101,7 +111,7 @@ module ts {
101111
export function findTokenOnLeftOfPosition(file: SourceFile, position: number): Node {
102112
// Ideally, getTokenAtPosition should return a token. However, it is currently
103113
// broken, so we do a check to make sure the result was indeed a token.
104-
var tokenAtPosition = getTouchingToken(file, position, /*allowPositionInLeadingTrivia*/ true);
114+
var tokenAtPosition = getTokenAtPosition(file, position);
105115
if (isToken(tokenAtPosition) && position > tokenAtPosition.getStart(file) && position < tokenAtPosition.getEnd()) {
106116
return tokenAtPosition;
107117
}

0 commit comments

Comments
 (0)