I am using Roslyn within a source generator to find certain c# method calls in a syntax tree. When found, I want to note the line and column number.
This answer works for the line number but not the column number.
This is how I get the LineSpan for an InvocationExpression node:
syntaxTree.GetLineSpan(node.Span, cancellationToken)
In my case, the returned FileLinePositionSpan's starting Character is 5. Accounting for it being zero-based, it's character number 4. This matches Visual Studio's
Ch
value shown below.
Col
, however, is 13. VS figures that out by multiplying each tab character by 5. Two tabs and three spaces lands you on column 13. 5+5+3 = 13.
How can I accurately get the Column number with Roslyn?
p.s. There seemed to be cases where GetLineSpan returned Character values that did not coincide with Visual Studio, but I am unable to reproduce that now.