-
Notifications
You must be signed in to change notification settings - Fork 12.8k
recompute character to column when comparing indentations #12375
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
function characterToColumn(startLinePosition: number, characterInLine: number): number { | ||
let column = 0; | ||
for (let i = 0; i < characterInLine; i++) { | ||
column += sourceFile.text.charCodeAt(startLinePosition + i) === CharacterCodes.tab ? options.tabSize : 1; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This doesn't seem quite right. If i have <space><tab>
then this math tells me i'm at (tabSize + 1)
when i should be at tabSize
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Roslyn's algorithm:
public static int ConvertTabToSpace(this string textSnippet, int tabSize, int initialColumn, int endPosition)
{
Contract.Requires(tabSize > 0);
Contract.Requires(endPosition >= 0 && endPosition <= textSnippet.Length);
int column = initialColumn;
// now this will calculate indentation regardless of actual content on the buffer except TAB
for (int i = 0; i < endPosition; i++)
{
if (textSnippet[i] == '\t')
{
column += tabSize - column % tabSize;
}
else
{
column++;
}
}
return column - initialColumn;
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fair enough, thanks for catching this
failure on the CI server is not related to this PR and caused by API changes in tslint - #12376 should address it |
@vladima can you port this to release-2.1 |
recompute character to column when comparing indentations
already done |
we always compute indentation as column so in order to compare it with character position in line - character position must be converted to column as well.
fixes #12175