Skip to content

Commit

Permalink
Highlight multiple errors in Azure Data Studio
Browse files Browse the repository at this point in the history
  • Loading branch information
MarkMpn committed Aug 24, 2024
1 parent 5e4e148 commit e132d96
Showing 1 changed file with 51 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -426,6 +426,8 @@ private async Task ExecuteAsync(Connection.Session session, ExecuteRequestParams

if (sql4CdsException?.Errors != null)
{
var diagnostics = new List<Diagnostic>();

foreach (var sql4CdsError in sql4CdsException.Errors)
{
var parts = new List<string>
Expand Down Expand Up @@ -468,7 +470,56 @@ private async Task ExecuteAsync(Connection.Session session, ExecuteRequestParams
IsError = true
}
});

if (sql4CdsError.Fragment != null && sql4CdsError.Fragment.FragmentLength > 0)
{
var lines = sql4CdsError.Fragment.ToSql().Split('\n');

diagnostics.Add(new Diagnostic
{
Range = new Microsoft.VisualStudio.LanguageServer.Protocol.Range
{
Start = new Position
{
Line = sql4CdsError.Fragment.StartLine - 1 + selection.StartLine,
Character = sql4CdsError.Fragment.StartColumn - 1 + (sql4CdsError.Fragment.StartLine == 1 ? selection.StartColumn : 0)
},
End = new Position
{
Line = sql4CdsError.Fragment.StartLine - 1 + selection.StartLine + lines.Length - 1,
Character = lines.Length > 1 ? lines.Last().Length - 1 : sql4CdsError.Fragment.StartColumn - 1 + (sql4CdsError.Fragment.StartLine == 1 ? selection.StartColumn : 0) + sql4CdsError.Fragment.FragmentLength
}
},
Message = sql4CdsError.Message
});
}
else
{
diagnostics.Add(new Diagnostic
{
Range = new Microsoft.VisualStudio.LanguageServer.Protocol.Range
{
Start = new Position
{
Line = Math.Max(sql4CdsError.LineNumber, 1) - 1 + selection.StartLine,
Character = 0
},
End = new Position
{
Line = Math.Max(sql4CdsError.LineNumber, 1) - 1 + selection.StartLine,
Character = qry.Split('\n')[Math.Max(sql4CdsError.LineNumber, 1) - 1].Length
}
},
Message = sql4CdsError.Message
});
}
}

await _lsp.NotifyAsync(Methods.TextDocumentPublishDiagnostics, new PublishDiagnosticParams
{
Uri = new Uri(request.OwnerUri),
Diagnostics = diagnostics.ToArray()
});
}

await _lsp.NotifyAsync(MessageEvent.Type, new MessageParams
Expand Down Expand Up @@ -517,35 +568,6 @@ private async Task ExecuteAsync(Connection.Session session, ExecuteRequestParams
}
});
}
else if (error is NotSupportedQueryFragmentException queryException)
{
var lines = queryException.Fragment.ToSql().Split('\n');

await _lsp.NotifyAsync(Methods.TextDocumentPublishDiagnostics, new PublishDiagnosticParams
{
Uri = new Uri(request.OwnerUri),
Diagnostics = new[]
{
new Diagnostic
{
Range = new Microsoft.VisualStudio.LanguageServer.Protocol.Range
{
Start = new Position
{
Line = queryException.Fragment.StartLine - 1 + selection.StartLine,
Character = queryException.Fragment.StartColumn - 1 + (queryException.Fragment.StartLine == 1 ? selection.StartColumn : 0)
},
End = new Position
{
Line = queryException.Fragment.StartLine - 1 + selection.StartLine + lines.Length - 1,
Character = lines.Length > 1 ? lines.Last().Length - 1 : queryException.Fragment.StartColumn - 1 + (queryException.Fragment.StartLine == 1 ? selection.StartColumn : 0) + queryException.Fragment.FragmentLength
}
},
Message = queryException.Message
}
}
});
}
}
finally
{
Expand Down

0 comments on commit e132d96

Please sign in to comment.