From d96b4e5a4ad7bc42ec1fb7717a8007fad5d18971 Mon Sep 17 00:00:00 2001 From: Leila Lali Date: Wed, 24 Aug 2016 15:16:43 -0700 Subject: [PATCH] Changing the format of the messages to be based on language server protocol 2.0 --- .../LanguageServices/AutoCompleteService.cs | 2 +- .../LanguageServices/LanguageService.cs | 2 +- .../Workspace/Contracts/TextDocument.cs | 74 +++++++++++++++---- .../Workspace/Contracts/WorkspaceSymbols.cs | 12 ++- .../Workspace/WorkspaceService.cs | 6 +- .../LanguageServer/LanguageServiceTests.cs | 9 ++- 6 files changed, 79 insertions(+), 26 deletions(-) diff --git a/src/Microsoft.SqlTools.ServiceLayer/LanguageServices/AutoCompleteService.cs b/src/Microsoft.SqlTools.ServiceLayer/LanguageServices/AutoCompleteService.cs index 9eaa411c..be778f92 100644 --- a/src/Microsoft.SqlTools.ServiceLayer/LanguageServices/AutoCompleteService.cs +++ b/src/Microsoft.SqlTools.ServiceLayer/LanguageServices/AutoCompleteService.cs @@ -155,7 +155,7 @@ namespace Microsoft.SqlTools.ServiceLayer.LanguageServices // that are not backed by a SQL connection ConnectionInfo info; IntellisenseCache cache; - if (ConnectionServiceInstance.TryFindConnection(textDocumentPosition.Uri, out info) + if (ConnectionServiceInstance.TryFindConnection(textDocumentPosition.TextDocument.Uri, out info) && caches.TryGetValue((ConnectionSummary)info.ConnectionDetails, out cache)) { return cache.GetAutoCompleteItems(textDocumentPosition).ToArray(); diff --git a/src/Microsoft.SqlTools.ServiceLayer/LanguageServices/LanguageService.cs b/src/Microsoft.SqlTools.ServiceLayer/LanguageServices/LanguageService.cs index f380f1bb..f92f81ca 100644 --- a/src/Microsoft.SqlTools.ServiceLayer/LanguageServices/LanguageService.cs +++ b/src/Microsoft.SqlTools.ServiceLayer/LanguageServices/LanguageService.cs @@ -213,7 +213,7 @@ namespace Microsoft.SqlTools.ServiceLayer.LanguageServices } private static async Task HandleDocumentSymbolRequest( - TextDocumentIdentifier textDocumentIdentifier, + DocumentSymbolParams documentSymbolParams, RequestContext requestContext) { Logger.Write(LogLevel.Verbose, "HandleDocumentSymbolRequest"); diff --git a/src/Microsoft.SqlTools.ServiceLayer/Workspace/Contracts/TextDocument.cs b/src/Microsoft.SqlTools.ServiceLayer/Workspace/Contracts/TextDocument.cs index 75b542cd..cf3f8468 100644 --- a/src/Microsoft.SqlTools.ServiceLayer/Workspace/Contracts/TextDocument.cs +++ b/src/Microsoft.SqlTools.ServiceLayer/Workspace/Contracts/TextDocument.cs @@ -19,37 +19,70 @@ namespace Microsoft.SqlTools.ServiceLayer.Workspace.Contracts /// text document. /// public string Uri { get; set; } - } + } /// /// Defines a position in a text document. /// [DebuggerDisplay("TextDocumentPosition = {Position.Line}:{Position.Character}")] - public class TextDocumentPosition : TextDocumentIdentifier + public class TextDocumentPosition { + /// + /// Gets or sets the document identifier. + /// + public TextDocumentIdentifier TextDocument { get; set; } + /// /// Gets or sets the position in the document. /// public Position Position { get; set; } } - public class DidOpenTextDocumentNotification : TextDocumentIdentifier + /// + /// Defines a text document. + /// + [DebuggerDisplay("TextDocumentItem = {Uri}")] + public class TextDocumentItem + { + /// + /// Gets or sets the URI which identifies the path of the + /// text document. + /// + public string Uri { get; set; } + + /// + /// Gets or sets the language of the document + /// + public string LanguageId { get; set; } + + /// + /// Gets or sets the version of the document + /// + public int Version { get; set; } + + /// + /// Gets or sets the full content of the document. + /// + public string Text { get; set; } + } + + public class DidOpenTextDocumentNotification { public static readonly EventType Type = EventType.Create("textDocument/didOpen"); /// - /// Gets or sets the full content of the opened document. + /// Gets or sets the opened document. /// - public string Text { get; set; } + public TextDocumentItem TextDocument { get; set; } } public class DidCloseTextDocumentNotification { public static readonly - EventType Type = - EventType.Create("textDocument/didClose"); + EventType Type = + EventType.Create("textDocument/didClose"); } public class DidChangeTextDocumentNotification @@ -59,9 +92,20 @@ namespace Microsoft.SqlTools.ServiceLayer.Workspace.Contracts EventType.Create("textDocument/didChange"); } - public class DidChangeTextDocumentParams : TextDocumentIdentifier + public class DidCloseTextDocumentParams { - public TextDocumentUriChangeEvent TextDocument { get; set; } + /// + /// Gets or sets the closed document. + /// + public TextDocumentItem TextDocument { get; set; } + } + + public class DidChangeTextDocumentParams + { + /// + /// Gets or sets the changed document. + /// + public VersionedTextDocumentIdentifier TextDocument { get; set; } /// /// 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 class TextDocumentUriChangeEvent - { - /// - /// Gets or sets the Uri of the changed text document - /// - public string Uri { get; set; } - + /// + /// Define a specific version of a text document + /// + public class VersionedTextDocumentIdentifier : TextDocumentIdentifier + { /// /// Gets or sets the Version of the changed text document /// diff --git a/src/Microsoft.SqlTools.ServiceLayer/Workspace/Contracts/WorkspaceSymbols.cs b/src/Microsoft.SqlTools.ServiceLayer/Workspace/Contracts/WorkspaceSymbols.cs index 22445c03..93140df3 100644 --- a/src/Microsoft.SqlTools.ServiceLayer/Workspace/Contracts/WorkspaceSymbols.cs +++ b/src/Microsoft.SqlTools.ServiceLayer/Workspace/Contracts/WorkspaceSymbols.cs @@ -43,8 +43,16 @@ namespace Microsoft.SqlTools.ServiceLayer.Workspace.Contracts public class DocumentSymbolRequest { public static readonly - RequestType Type = - RequestType.Create("textDocument/documentSymbol"); + RequestType Type = + RequestType.Create("textDocument/documentSymbol"); + } + + /// + /// Defines a set of parameters to send document symbol request + /// + public class DocumentSymbolParams + { + public TextDocumentIdentifier TextDocument { get; set; } } public class WorkspaceSymbolRequest diff --git a/src/Microsoft.SqlTools.ServiceLayer/Workspace/WorkspaceService.cs b/src/Microsoft.SqlTools.ServiceLayer/Workspace/WorkspaceService.cs index f47cacb9..75992645 100644 --- a/src/Microsoft.SqlTools.ServiceLayer/Workspace/WorkspaceService.cs +++ b/src/Microsoft.SqlTools.ServiceLayer/Workspace/WorkspaceService.cs @@ -181,7 +181,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Workspace // A text change notification can batch multiple change requests 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)); ScriptFile changedFile = Workspace.GetFile(fileUri); @@ -207,7 +207,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Workspace Logger.Write(LogLevel.Verbose, "HandleDidOpenTextDocumentNotification"); // 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 var textDocOpenTasks = TextDocOpenCallbacks.Select( @@ -217,7 +217,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Workspace } protected Task HandleDidCloseTextDocumentNotification( - TextDocumentIdentifier closeParams, + DidCloseTextDocumentParams closeParams, EventContext eventContext) { Logger.Write(LogLevel.Verbose, "HandleDidCloseTextDocumentNotification"); diff --git a/test/Microsoft.SqlTools.ServiceLayer.Test/LanguageServer/LanguageServiceTests.cs b/test/Microsoft.SqlTools.ServiceLayer.Test/LanguageServer/LanguageServiceTests.cs index 9462d384..6380eb91 100644 --- a/test/Microsoft.SqlTools.ServiceLayer.Test/LanguageServer/LanguageServiceTests.cs +++ b/test/Microsoft.SqlTools.ServiceLayer.Test/LanguageServer/LanguageServiceTests.cs @@ -197,7 +197,8 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.LanguageServices // Check that we get table suggestions for an autocomplete request TextDocumentPosition position = new TextDocumentPosition(); - position.Uri = connectionRequest.OwnerUri; + position.TextDocument = new TextDocumentIdentifier(); + position.TextDocument.Uri = connectionRequest.OwnerUri; position.Position = new Position(); position.Position.Line = 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 TextDocumentPosition position = new TextDocumentPosition(); - position.Uri = connectionRequest.OwnerUri; + position.TextDocument = new TextDocumentIdentifier(); + position.TextDocument.Uri = connectionRequest.OwnerUri; position.Position = new Position(); position.Position.Line = 1; position.Position.Character = 1; @@ -302,7 +304,8 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.LanguageServices Assert.Equal("model", items[1].Label); TextDocumentPosition position2 = new TextDocumentPosition(); - position2.Uri = connectionRequest2.OwnerUri; + position2.TextDocument = new TextDocumentIdentifier(); + position2.TextDocument.Uri = connectionRequest2.OwnerUri; position2.Position = new Position(); position2.Position.Line = 1; position2.Position.Character = 1;