recompute character to column when comparing indentations#12375
Merged
recompute character to column when comparing indentations#12375
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; |
Contributor
There was a problem hiding this comment.
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.
Contributor
There was a problem hiding this comment.
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;
}
Contributor
Author
There was a problem hiding this comment.
fair enough, thanks for catching this
Contributor
Author
|
failure on the CI server is not related to this PR and caused by API changes in tslint - #12376 should address it |
mhegazy
approved these changes
Nov 21, 2016
Contributor
|
@vladima can you port this to release-2.1 |
vladima
added a commit
that referenced
this pull request
Nov 21, 2016
recompute character to column when comparing indentations
Contributor
Author
|
already done |
vladima
added a commit
that referenced
this pull request
Nov 21, 2016
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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