Closed KreativJos closed 1 year ago
This error depends on some magic number which is used to define loop limit. Unfortunately it exceeds the file's lines and raises this error. Let's say that it can be easily fixed, but it would be interesting to understand the nature of the number.
private findConstructorBodyStart(document: TextDocument, position: Position): Position | null {
for (let lineNo = position.line; lineNo < position.line + 5; lineNo++) {
const line = document.lineAt(lineNo);
...
it seems to me that 5 (the magic number) it has been used with some strong assumptions: the class gets generated from csharextension template, it does not use file scoped namespace and it does not expect body expression constructor.
Below a working example:
namespace MyTest.Workspace
{
public class NewClass
{
public NewClass(int field)
{
this.Field = field;
}
public int Field { get; }
}
}
Here one which throws the above error:
namespace MyTest.Workspace;
public class NewClass
{
public NewClass(int field)
{
this.Field = field;
}
public int Field { get; }
}
things get even worse using expression body constructor.
namespace MyTest.Workspace;
public class NewClass
{
public NewClass(int field)
=> this.Field = field;
public int Field { get; }
}
The solution will be to replace 5 with the following instruction:
const limit = min((position.line + (document.lineCount /2)), document.linesCount);
This also means that the code action needs to support body expression constructor.
Log output:
Caused somewhere in codeActionProvider (a
new Position
call)