mirror of
https://github.com/ckaczor/sqltoolsservice.git
synced 2026-02-16 18:47:57 -05:00
Adding correct line numbers for errors
This commit is contained in:
@@ -64,9 +64,14 @@ namespace Microsoft.SqlTools.ServiceLayer.QueryExecution
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The 0-indexed line number that this batch started on
|
||||||
|
/// </summary>
|
||||||
|
private int StartLine { get; set; }
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
public Batch(string batchText)
|
public Batch(string batchText, int startLine)
|
||||||
{
|
{
|
||||||
// Sanity check for input
|
// Sanity check for input
|
||||||
if (string.IsNullOrEmpty(batchText))
|
if (string.IsNullOrEmpty(batchText))
|
||||||
@@ -76,6 +81,7 @@ namespace Microsoft.SqlTools.ServiceLayer.QueryExecution
|
|||||||
|
|
||||||
// Initialize the internal state
|
// Initialize the internal state
|
||||||
BatchText = batchText;
|
BatchText = batchText;
|
||||||
|
StartLine = startLine - 1;
|
||||||
HasExecuted = false;
|
HasExecuted = false;
|
||||||
ResultSets = new List<ResultSet>();
|
ResultSets = new List<ResultSet>();
|
||||||
ResultMessages = new List<string>();
|
ResultMessages = new List<string>();
|
||||||
@@ -222,8 +228,9 @@ namespace Microsoft.SqlTools.ServiceLayer.QueryExecution
|
|||||||
SqlError sqlError = error as SqlError;
|
SqlError sqlError = error as SqlError;
|
||||||
if (sqlError != null)
|
if (sqlError != null)
|
||||||
{
|
{
|
||||||
|
int lineNumber = sqlError.LineNumber + StartLine;
|
||||||
string message = String.Format("Msg {0}, Level {1}, State {2}, Line {3}{4}{5}",
|
string message = String.Format("Msg {0}, Level {1}, State {2}, Line {3}{4}{5}",
|
||||||
sqlError.Number, sqlError.Class, sqlError.State, sqlError.LineNumber,
|
sqlError.Number, sqlError.Class, sqlError.State, lineNumber,
|
||||||
Environment.NewLine, sqlError.Message);
|
Environment.NewLine, sqlError.Message);
|
||||||
ResultMessages.Add(message);
|
ResultMessages.Add(message);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -117,7 +117,7 @@ namespace Microsoft.SqlTools.ServiceLayer.QueryExecution
|
|||||||
{
|
{
|
||||||
BatchSeparator = settings.BatchSeparator
|
BatchSeparator = settings.BatchSeparator
|
||||||
});
|
});
|
||||||
Batches = parseResult.Script.Batches.Select(b => new Batch(b.Sql)).ToArray();
|
Batches = parseResult.Script.Batches.Select(b => new Batch(b.Sql, b.StartLocation.LineNumber)).ToArray();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
Reference in New Issue
Block a user