Skip to content

Commit 14e5c19

Browse files
linkdotnetegil
authored andcommitted
feat: Use the correct column
1 parent e4d8f60 commit 14e5c19

1 file changed

Lines changed: 7 additions & 4 deletions

File tree

src/bunit.generators/Web.Stubs/StubGenerator.cs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1+
using System;
12
using System.Collections.Generic;
23
using System.Collections.Immutable;
4+
using System.Diagnostics.CodeAnalysis;
35
using System.Linq;
46
using System.Text;
57
using Microsoft.CodeAnalysis;
@@ -42,17 +44,18 @@ private static StubClassInfo GetStubClassInfo(GeneratorSyntaxContext context)
4244
if (context.SemanticModel.GetSymbolInfo(typeArgument).Symbol is ITypeSymbol symbol)
4345
{
4446
var path = GetInterceptorFilePath(context.Node.SyntaxTree, context.SemanticModel.Compilation);
45-
var line = context.SemanticModel.SyntaxTree.GetLineSpan(context.Node.Span).StartLinePosition.Line + 1;
46-
// Find then column for "AddGeneratedStub" in the invocation expression
47-
var column = context.SemanticModel.SyntaxTree.GetLineSpan(context.Node.Span).StartLinePosition.Character + 1;
47+
var lineSpan = context.SemanticModel.SyntaxTree.GetLineSpan(context.Node.Span);
48+
var line = lineSpan.StartLinePosition.Line + 1;
49+
var column = lineSpan.Span.Start.Character + context.Node.ToString().IndexOf("AddGeneratedStub", StringComparison.Ordinal);
50+
4851
return new StubClassInfo
4952
{
5053
StubClassName = $"{symbol.Name}Stub",
5154
TargetTypeNamespace = symbol.ContainingNamespace.ToDisplayString(),
5255
TargetType = symbol,
5356
Path = path,
5457
Line = line,
55-
Column = column + 19, // Yeah - no - well - it works (Future Steven can take care of it)
58+
Column = column + 1,
5659
};
5760
}
5861
}

0 commit comments

Comments
 (0)