mirror of
https://github.com/ckaczor/sqltoolsservice.git
synced 2026-01-14 17:23:27 -05:00
Initial commit of SqlTools Service API
This commit is contained in:
118
ServiceHost/Workspace/ScriptFileMarker.cs
Normal file
118
ServiceHost/Workspace/ScriptFileMarker.cs
Normal file
@@ -0,0 +1,118 @@
|
||||
//
|
||||
// Copyright (c) Microsoft. All rights reserved.
|
||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||
//
|
||||
|
||||
using Microsoft.PowerShell.EditorServices.Utility;
|
||||
using System;
|
||||
//using System.Management.Automation.Language;
|
||||
|
||||
#if ScriptAnalyzer
|
||||
using Microsoft.Windows.PowerShell.ScriptAnalyzer.Generic;
|
||||
#endif
|
||||
|
||||
namespace Microsoft.PowerShell.EditorServices
|
||||
{
|
||||
/// <summary>
|
||||
/// Defines the message level of a script file marker.
|
||||
/// </summary>
|
||||
public enum ScriptFileMarkerLevel
|
||||
{
|
||||
/// <summary>
|
||||
/// The marker represents an informational message.
|
||||
/// </summary>
|
||||
Information = 0,
|
||||
|
||||
/// <summary>
|
||||
/// The marker represents a warning message.
|
||||
/// </summary>
|
||||
Warning,
|
||||
|
||||
/// <summary>
|
||||
/// The marker represents an error message.
|
||||
/// </summary>
|
||||
Error
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
/// Contains details about a marker that should be displayed
|
||||
/// for the a script file. The marker information could come
|
||||
/// from syntax parsing or semantic analysis of the script.
|
||||
/// </summary>
|
||||
public class ScriptFileMarker
|
||||
{
|
||||
#region Properties
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the marker's message string.
|
||||
/// </summary>
|
||||
public string Message { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the marker's message level.
|
||||
/// </summary>
|
||||
public ScriptFileMarkerLevel Level { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the ScriptRegion where the marker should appear.
|
||||
/// </summary>
|
||||
public ScriptRegion ScriptRegion { get; set; }
|
||||
|
||||
#endregion
|
||||
|
||||
#region Public Methods
|
||||
|
||||
#if false
|
||||
internal static ScriptFileMarker FromParseError(
|
||||
ParseError parseError)
|
||||
{
|
||||
Validate.IsNotNull("parseError", parseError);
|
||||
|
||||
return new ScriptFileMarker
|
||||
{
|
||||
Message = parseError.Message,
|
||||
Level = ScriptFileMarkerLevel.Error,
|
||||
ScriptRegion = ScriptRegion.Create(parseError.Extent)
|
||||
};
|
||||
}
|
||||
#endif
|
||||
|
||||
#if ScriptAnalyzer
|
||||
internal static ScriptFileMarker FromDiagnosticRecord(
|
||||
DiagnosticRecord diagnosticRecord)
|
||||
{
|
||||
Validate.IsNotNull("diagnosticRecord", diagnosticRecord);
|
||||
|
||||
return new ScriptFileMarker
|
||||
{
|
||||
Message = diagnosticRecord.Message,
|
||||
Level = GetMarkerLevelFromDiagnosticSeverity(diagnosticRecord.Severity),
|
||||
ScriptRegion = ScriptRegion.Create(diagnosticRecord.Extent)
|
||||
};
|
||||
}
|
||||
|
||||
private static ScriptFileMarkerLevel GetMarkerLevelFromDiagnosticSeverity(
|
||||
DiagnosticSeverity diagnosticSeverity)
|
||||
{
|
||||
switch (diagnosticSeverity)
|
||||
{
|
||||
case DiagnosticSeverity.Information:
|
||||
return ScriptFileMarkerLevel.Information;
|
||||
case DiagnosticSeverity.Warning:
|
||||
return ScriptFileMarkerLevel.Warning;
|
||||
case DiagnosticSeverity.Error:
|
||||
return ScriptFileMarkerLevel.Error;
|
||||
default:
|
||||
throw new ArgumentException(
|
||||
string.Format(
|
||||
"The provided DiagnosticSeverity value '{0}' is unknown.",
|
||||
diagnosticSeverity),
|
||||
"diagnosticSeverity");
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user