mirror of
https://github.com/ckaczor/sqltoolsservice.git
synced 2026-01-13 17:23:02 -05:00
Integrate SqlParser into the onchange diagnostics to provide error messages.
This commit is contained in:
@@ -5,6 +5,8 @@
|
|||||||
|
|
||||||
using Microsoft.SqlTools.EditorServices;
|
using Microsoft.SqlTools.EditorServices;
|
||||||
using Microsoft.SqlTools.EditorServices.Session;
|
using Microsoft.SqlTools.EditorServices.Session;
|
||||||
|
using Microsoft.SqlServer.Management.SqlParser.Parser;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
|
||||||
namespace Microsoft.SqlTools.LanguageSupport
|
namespace Microsoft.SqlTools.LanguageSupport
|
||||||
{
|
{
|
||||||
@@ -13,6 +15,11 @@ namespace Microsoft.SqlTools.LanguageSupport
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public class LanguageService
|
public class LanguageService
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// The cached parse result from previous incremental parse
|
||||||
|
/// </summary>
|
||||||
|
private ParseResult prevParseResult;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets or sets the current SQL Tools context
|
/// Gets or sets the current SQL Tools context
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -34,24 +41,38 @@ namespace Microsoft.SqlTools.LanguageSupport
|
|||||||
/// <param name="scriptFile"></param>
|
/// <param name="scriptFile"></param>
|
||||||
public ScriptFileMarker[] GetSemanticMarkers(ScriptFile scriptFile)
|
public ScriptFileMarker[] GetSemanticMarkers(ScriptFile scriptFile)
|
||||||
{
|
{
|
||||||
// the commented out snippet is an example of how to create a error marker
|
// parse current SQL file contents to retrieve a list of errors
|
||||||
// semanticMarkers = new ScriptFileMarker[1];
|
ParseOptions parseOptions = new ParseOptions();
|
||||||
// semanticMarkers[0] = new ScriptFileMarker()
|
ParseResult parseResult = Parser.IncrementalParse(
|
||||||
// {
|
scriptFile.Contents,
|
||||||
// Message = "Error message",
|
prevParseResult,
|
||||||
// Level = ScriptFileMarkerLevel.Error,
|
parseOptions);
|
||||||
// ScriptRegion = new ScriptRegion()
|
|
||||||
// {
|
// save previous result for next incremental parse
|
||||||
// File = scriptFile.FilePath,
|
this.prevParseResult = parseResult;
|
||||||
// StartLineNumber = 2,
|
|
||||||
// StartColumnNumber = 2,
|
// build a list of SQL script file markers from the errors
|
||||||
// StartOffset = 0,
|
List<ScriptFileMarker> markers = new List<ScriptFileMarker>();
|
||||||
// EndLineNumber = 4,
|
foreach (var error in parseResult.Errors)
|
||||||
// EndColumnNumber = 10,
|
{
|
||||||
// EndOffset = 0
|
markers.Add(new ScriptFileMarker()
|
||||||
// }
|
{
|
||||||
// };
|
Message = error.Message,
|
||||||
return new ScriptFileMarker[0];
|
Level = ScriptFileMarkerLevel.Error,
|
||||||
|
ScriptRegion = new ScriptRegion()
|
||||||
|
{
|
||||||
|
File = scriptFile.FilePath,
|
||||||
|
StartLineNumber = error.Start.LineNumber,
|
||||||
|
StartColumnNumber = error.Start.ColumnNumber,
|
||||||
|
StartOffset = 0,
|
||||||
|
EndLineNumber = error.End.LineNumber,
|
||||||
|
EndColumnNumber = error.End.ColumnNumber,
|
||||||
|
EndOffset = 0
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
return markers.ToArray();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -122,7 +122,7 @@ namespace Microsoft.SqlTools.EditorServices.Protocol.Server
|
|||||||
/// <param name="textChangeParams"></param>
|
/// <param name="textChangeParams"></param>
|
||||||
/// <param name="eventContext"></param>
|
/// <param name="eventContext"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
protected Task HandleDidChangeTextDocumentNotification(
|
protected async Task HandleDidChangeTextDocumentNotification(
|
||||||
DidChangeTextDocumentParams textChangeParams,
|
DidChangeTextDocumentParams textChangeParams,
|
||||||
EventContext eventContext)
|
EventContext eventContext)
|
||||||
{
|
{
|
||||||
@@ -133,7 +133,7 @@ namespace Microsoft.SqlTools.EditorServices.Protocol.Server
|
|||||||
// A text change notification can batch multiple change requests
|
// A text change notification can batch multiple change requests
|
||||||
foreach (var textChange in textChangeParams.ContentChanges)
|
foreach (var textChange in textChangeParams.ContentChanges)
|
||||||
{
|
{
|
||||||
string fileUri = textChangeParams.TextDocument.Uri;
|
string fileUri = textChangeParams.Uri ?? textChangeParams.TextDocument.Uri;
|
||||||
msg.AppendLine();
|
msg.AppendLine();
|
||||||
msg.Append(" File: ");
|
msg.Append(" File: ");
|
||||||
msg.Append(fileUri);
|
msg.Append(fileUri);
|
||||||
@@ -150,12 +150,12 @@ namespace Microsoft.SqlTools.EditorServices.Protocol.Server
|
|||||||
|
|
||||||
Logger.Write(LogLevel.Verbose, msg.ToString());
|
Logger.Write(LogLevel.Verbose, msg.ToString());
|
||||||
|
|
||||||
this.RunScriptDiagnostics(
|
await this.RunScriptDiagnostics(
|
||||||
changedFiles.ToArray(),
|
changedFiles.ToArray(),
|
||||||
editorSession,
|
editorSession,
|
||||||
eventContext);
|
eventContext);
|
||||||
|
|
||||||
return Task.FromResult(true);
|
await Task.FromResult(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected Task HandleDidOpenTextDocumentNotification(
|
protected Task HandleDidOpenTextDocumentNotification(
|
||||||
|
|||||||
@@ -5,7 +5,8 @@
|
|||||||
"emitEntryPoint": true
|
"emitEntryPoint": true
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"Newtonsoft.Json": "9.0.1"
|
"Newtonsoft.Json": "9.0.1",
|
||||||
|
"Microsoft.SqlServer.SqlParser": "140.1.3"
|
||||||
},
|
},
|
||||||
"frameworks": {
|
"frameworks": {
|
||||||
"netcoreapp1.0": {
|
"netcoreapp1.0": {
|
||||||
|
|||||||
Reference in New Issue
Block a user