Changing the format of the messages to be based on language server protocol 2.0

This commit is contained in:
Leila Lali
2016-08-24 15:16:43 -07:00
parent 5425e70f1f
commit d96b4e5a4a
6 changed files with 79 additions and 26 deletions

View File

@@ -155,7 +155,7 @@ namespace Microsoft.SqlTools.ServiceLayer.LanguageServices
// that are not backed by a SQL connection // that are not backed by a SQL connection
ConnectionInfo info; ConnectionInfo info;
IntellisenseCache cache; IntellisenseCache cache;
if (ConnectionServiceInstance.TryFindConnection(textDocumentPosition.Uri, out info) if (ConnectionServiceInstance.TryFindConnection(textDocumentPosition.TextDocument.Uri, out info)
&& caches.TryGetValue((ConnectionSummary)info.ConnectionDetails, out cache)) && caches.TryGetValue((ConnectionSummary)info.ConnectionDetails, out cache))
{ {
return cache.GetAutoCompleteItems(textDocumentPosition).ToArray(); return cache.GetAutoCompleteItems(textDocumentPosition).ToArray();

View File

@@ -213,7 +213,7 @@ namespace Microsoft.SqlTools.ServiceLayer.LanguageServices
} }
private static async Task HandleDocumentSymbolRequest( private static async Task HandleDocumentSymbolRequest(
TextDocumentIdentifier textDocumentIdentifier, DocumentSymbolParams documentSymbolParams,
RequestContext<SymbolInformation[]> requestContext) RequestContext<SymbolInformation[]> requestContext)
{ {
Logger.Write(LogLevel.Verbose, "HandleDocumentSymbolRequest"); Logger.Write(LogLevel.Verbose, "HandleDocumentSymbolRequest");

View File

@@ -19,37 +19,70 @@ namespace Microsoft.SqlTools.ServiceLayer.Workspace.Contracts
/// text document. /// text document.
/// </summary> /// </summary>
public string Uri { get; set; } public string Uri { get; set; }
} }
/// <summary> /// <summary>
/// Defines a position in a text document. /// Defines a position in a text document.
/// </summary> /// </summary>
[DebuggerDisplay("TextDocumentPosition = {Position.Line}:{Position.Character}")] [DebuggerDisplay("TextDocumentPosition = {Position.Line}:{Position.Character}")]
public class TextDocumentPosition : TextDocumentIdentifier public class TextDocumentPosition
{ {
/// <summary>
/// Gets or sets the document identifier.
/// </summary>
public TextDocumentIdentifier TextDocument { get; set; }
/// <summary> /// <summary>
/// Gets or sets the position in the document. /// Gets or sets the position in the document.
/// </summary> /// </summary>
public Position Position { get; set; } public Position Position { get; set; }
} }
public class DidOpenTextDocumentNotification : TextDocumentIdentifier /// <summary>
/// Defines a text document.
/// </summary>
[DebuggerDisplay("TextDocumentItem = {Uri}")]
public class TextDocumentItem
{
/// <summary>
/// Gets or sets the URI which identifies the path of the
/// text document.
/// </summary>
public string Uri { get; set; }
/// <summary>
/// Gets or sets the language of the document
/// </summary>
public string LanguageId { get; set; }
/// <summary>
/// Gets or sets the version of the document
/// </summary>
public int Version { get; set; }
/// <summary>
/// Gets or sets the full content of the document.
/// </summary>
public string Text { get; set; }
}
public class DidOpenTextDocumentNotification
{ {
public static readonly public static readonly
EventType<DidOpenTextDocumentNotification> Type = EventType<DidOpenTextDocumentNotification> Type =
EventType<DidOpenTextDocumentNotification>.Create("textDocument/didOpen"); EventType<DidOpenTextDocumentNotification>.Create("textDocument/didOpen");
/// <summary> /// <summary>
/// Gets or sets the full content of the opened document. /// Gets or sets the opened document.
/// </summary> /// </summary>
public string Text { get; set; } public TextDocumentItem TextDocument { get; set; }
} }
public class DidCloseTextDocumentNotification public class DidCloseTextDocumentNotification
{ {
public static readonly public static readonly
EventType<TextDocumentIdentifier> Type = EventType<DidCloseTextDocumentParams> Type =
EventType<TextDocumentIdentifier>.Create("textDocument/didClose"); EventType<DidCloseTextDocumentParams>.Create("textDocument/didClose");
} }
public class DidChangeTextDocumentNotification public class DidChangeTextDocumentNotification
@@ -59,9 +92,20 @@ namespace Microsoft.SqlTools.ServiceLayer.Workspace.Contracts
EventType<DidChangeTextDocumentParams>.Create("textDocument/didChange"); EventType<DidChangeTextDocumentParams>.Create("textDocument/didChange");
} }
public class DidChangeTextDocumentParams : TextDocumentIdentifier public class DidCloseTextDocumentParams
{ {
public TextDocumentUriChangeEvent TextDocument { get; set; } /// <summary>
/// Gets or sets the closed document.
/// </summary>
public TextDocumentItem TextDocument { get; set; }
}
public class DidChangeTextDocumentParams
{
/// <summary>
/// Gets or sets the changed document.
/// </summary>
public VersionedTextDocumentIdentifier TextDocument { get; set; }
/// <summary> /// <summary>
/// Gets or sets the list of changes to the document content. /// Gets or sets the list of changes to the document content.
@@ -69,13 +113,11 @@ namespace Microsoft.SqlTools.ServiceLayer.Workspace.Contracts
public TextDocumentChangeEvent[] ContentChanges { get; set; } public TextDocumentChangeEvent[] ContentChanges { get; set; }
} }
public class TextDocumentUriChangeEvent /// <summary>
{ /// Define a specific version of a text document
/// <summary> /// </summary>
/// Gets or sets the Uri of the changed text document public class VersionedTextDocumentIdentifier : TextDocumentIdentifier
/// </summary> {
public string Uri { get; set; }
/// <summary> /// <summary>
/// Gets or sets the Version of the changed text document /// Gets or sets the Version of the changed text document
/// </summary> /// </summary>

View File

@@ -43,8 +43,16 @@ namespace Microsoft.SqlTools.ServiceLayer.Workspace.Contracts
public class DocumentSymbolRequest public class DocumentSymbolRequest
{ {
public static readonly public static readonly
RequestType<TextDocumentIdentifier, SymbolInformation[]> Type = RequestType<DocumentSymbolParams, SymbolInformation[]> Type =
RequestType<TextDocumentIdentifier, SymbolInformation[]>.Create("textDocument/documentSymbol"); RequestType<DocumentSymbolParams, SymbolInformation[]>.Create("textDocument/documentSymbol");
}
/// <summary>
/// Defines a set of parameters to send document symbol request
/// </summary>
public class DocumentSymbolParams
{
public TextDocumentIdentifier TextDocument { get; set; }
} }
public class WorkspaceSymbolRequest public class WorkspaceSymbolRequest

View File

@@ -181,7 +181,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Workspace
// 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.Uri ?? textChangeParams.TextDocument.Uri; string fileUri = textChangeParams.TextDocument.Uri ?? textChangeParams.TextDocument.Uri;
msg.AppendLine(string.Format(" File: {0}", fileUri)); msg.AppendLine(string.Format(" File: {0}", fileUri));
ScriptFile changedFile = Workspace.GetFile(fileUri); ScriptFile changedFile = Workspace.GetFile(fileUri);
@@ -207,7 +207,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Workspace
Logger.Write(LogLevel.Verbose, "HandleDidOpenTextDocumentNotification"); Logger.Write(LogLevel.Verbose, "HandleDidOpenTextDocumentNotification");
// read the SQL file contents into the ScriptFile // read the SQL file contents into the ScriptFile
ScriptFile openedFile = Workspace.GetFileBuffer(openParams.Uri, openParams.Text); ScriptFile openedFile = Workspace.GetFileBuffer(openParams.TextDocument.Uri, openParams.TextDocument.Text);
// Propagate the changes to the event handlers // Propagate the changes to the event handlers
var textDocOpenTasks = TextDocOpenCallbacks.Select( var textDocOpenTasks = TextDocOpenCallbacks.Select(
@@ -217,7 +217,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Workspace
} }
protected Task HandleDidCloseTextDocumentNotification( protected Task HandleDidCloseTextDocumentNotification(
TextDocumentIdentifier closeParams, DidCloseTextDocumentParams closeParams,
EventContext eventContext) EventContext eventContext)
{ {
Logger.Write(LogLevel.Verbose, "HandleDidCloseTextDocumentNotification"); Logger.Write(LogLevel.Verbose, "HandleDidCloseTextDocumentNotification");

View File

@@ -197,7 +197,8 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.LanguageServices
// Check that we get table suggestions for an autocomplete request // Check that we get table suggestions for an autocomplete request
TextDocumentPosition position = new TextDocumentPosition(); TextDocumentPosition position = new TextDocumentPosition();
position.Uri = connectionRequest.OwnerUri; position.TextDocument = new TextDocumentIdentifier();
position.TextDocument.Uri = connectionRequest.OwnerUri;
position.Position = new Position(); position.Position = new Position();
position.Position.Line = 1; position.Position.Line = 1;
position.Position.Character = 1; position.Position.Character = 1;
@@ -291,7 +292,8 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.LanguageServices
// Check that we get 2 different table suggestions for autocomplete requests // Check that we get 2 different table suggestions for autocomplete requests
TextDocumentPosition position = new TextDocumentPosition(); TextDocumentPosition position = new TextDocumentPosition();
position.Uri = connectionRequest.OwnerUri; position.TextDocument = new TextDocumentIdentifier();
position.TextDocument.Uri = connectionRequest.OwnerUri;
position.Position = new Position(); position.Position = new Position();
position.Position.Line = 1; position.Position.Line = 1;
position.Position.Character = 1; position.Position.Character = 1;
@@ -302,7 +304,8 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.LanguageServices
Assert.Equal("model", items[1].Label); Assert.Equal("model", items[1].Label);
TextDocumentPosition position2 = new TextDocumentPosition(); TextDocumentPosition position2 = new TextDocumentPosition();
position2.Uri = connectionRequest2.OwnerUri; position2.TextDocument = new TextDocumentIdentifier();
position2.TextDocument.Uri = connectionRequest2.OwnerUri;
position2.Position = new Position(); position2.Position = new Position();
position2.Position.Line = 1; position2.Position.Line = 1;
position2.Position.Character = 1; position2.Position.Character = 1;