mirror of
https://github.com/ckaczor/sqltoolsservice.git
synced 2026-01-14 01:25:40 -05:00
Fix-up the autocomplete support to better handle binding timeouts. Also provide a default keyword suggestion list.
99 lines
3.7 KiB
C#
99 lines
3.7 KiB
C#
//
|
|
// Copyright (c) Microsoft. All rights reserved.
|
|
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
|
//
|
|
|
|
using System.Linq;
|
|
using System.Threading.Tasks;
|
|
using Microsoft.SqlTools.ServiceLayer.Hosting.Protocol;
|
|
using Microsoft.SqlTools.ServiceLayer.LanguageServices.Contracts;
|
|
using Microsoft.SqlTools.ServiceLayer.Workspace.Contracts;
|
|
|
|
namespace Microsoft.SqlTools.ServiceLayer.LanguageServices
|
|
{
|
|
/// <summary>
|
|
/// Main class for Language Service functionality including anything that reqires knowledge of
|
|
/// the language to perfom, such as definitions, intellisense, etc.
|
|
/// </summary>
|
|
public static class DiagnosticsHelper
|
|
{
|
|
/// <summary>
|
|
/// Send the diagnostic results back to the host application
|
|
/// </summary>
|
|
/// <param name="scriptFile"></param>
|
|
/// <param name="semanticMarkers"></param>
|
|
/// <param name="eventContext"></param>
|
|
internal static async Task PublishScriptDiagnostics(
|
|
ScriptFile scriptFile,
|
|
ScriptFileMarker[] semanticMarkers,
|
|
EventContext eventContext)
|
|
{
|
|
var allMarkers = scriptFile.SyntaxMarkers != null
|
|
? scriptFile.SyntaxMarkers.Concat(semanticMarkers)
|
|
: semanticMarkers;
|
|
|
|
// Always send syntax and semantic errors. We want to
|
|
// make sure no out-of-date markers are being displayed.
|
|
await eventContext.SendEvent(
|
|
PublishDiagnosticsNotification.Type,
|
|
new PublishDiagnosticsNotification
|
|
{
|
|
Uri = scriptFile.ClientFilePath,
|
|
Diagnostics =
|
|
allMarkers
|
|
.Select(GetDiagnosticFromMarker)
|
|
.ToArray()
|
|
});
|
|
}
|
|
|
|
/// <summary>
|
|
/// Convert a ScriptFileMarker to a Diagnostic that is Language Service compatible
|
|
/// </summary>
|
|
/// <param name="scriptFileMarker"></param>
|
|
/// <returns></returns>
|
|
internal static Diagnostic GetDiagnosticFromMarker(ScriptFileMarker scriptFileMarker)
|
|
{
|
|
return new Diagnostic
|
|
{
|
|
Severity = MapDiagnosticSeverity(scriptFileMarker.Level),
|
|
Message = scriptFileMarker.Message,
|
|
Range = new Range
|
|
{
|
|
Start = new Position
|
|
{
|
|
Line = scriptFileMarker.ScriptRegion.StartLineNumber - 1,
|
|
Character = scriptFileMarker.ScriptRegion.StartColumnNumber - 1
|
|
},
|
|
End = new Position
|
|
{
|
|
Line = scriptFileMarker.ScriptRegion.EndLineNumber - 1,
|
|
Character = scriptFileMarker.ScriptRegion.EndColumnNumber - 1
|
|
}
|
|
}
|
|
};
|
|
}
|
|
|
|
/// <summary>
|
|
/// Map ScriptFileMarker severity to Diagnostic severity
|
|
/// </summary>
|
|
/// <param name="markerLevel"></param>
|
|
internal static DiagnosticSeverity MapDiagnosticSeverity(ScriptFileMarkerLevel markerLevel)
|
|
{
|
|
switch (markerLevel)
|
|
{
|
|
case ScriptFileMarkerLevel.Error:
|
|
return DiagnosticSeverity.Error;
|
|
|
|
case ScriptFileMarkerLevel.Warning:
|
|
return DiagnosticSeverity.Warning;
|
|
|
|
case ScriptFileMarkerLevel.Information:
|
|
return DiagnosticSeverity.Information;
|
|
|
|
default:
|
|
return DiagnosticSeverity.Error;
|
|
}
|
|
}
|
|
}
|
|
}
|