Skip to content

Commit

Permalink
Merge pull request #73911 from mhutch/lsp-protocol-types
Browse files Browse the repository at this point in the history
Update LSP Protocol Types
  • Loading branch information
dibarbet authored Aug 20, 2024
2 parents d1ddbc8 + 3320e83 commit 2543698
Show file tree
Hide file tree
Showing 441 changed files with 10,093 additions and 2,145 deletions.
9 changes: 8 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,12 @@
"dotnet.defaultSolution": "Roslyn.sln",
"dotnet.completion.showCompletionItemsFromUnimportedNamespaces": true,
"dotnet.testWindow.disableAutoDiscovery": true,
"dotnet.testWindow.disableBuildOnRefresh": true
"dotnet.testWindow.disableBuildOnRefresh": true,
"cSpell.words": [
"Nerdbank",
"NETCOREAPP",
"Unregistration",
"Unregistrations",
"Xunit"
]
}
2 changes: 1 addition & 1 deletion .vscode/tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@
"build",
"-c",
"Debug",
"src/Features/LanguageServer/Microsoft.CodeAnalysis.LanguageServer/Microsoft.CodeAnalysis.LanguageServer.csproj"
"src/LanguageServer/Microsoft.CodeAnalysis.LanguageServer/Microsoft.CodeAnalysis.LanguageServer.csproj"
],
"problemMatcher": "$msCompile",
"group": "build"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ public override ServerCapabilities GetCapabilities(ClientCapabilities clientCapa

serverCapabilities.SupportsDiagnosticRequests = true;

serverCapabilities.DiagnosticOptions ??= new();
serverCapabilities.DiagnosticOptions.WorkspaceDiagnostics = true;
var diagnosticOptions = (serverCapabilities.DiagnosticOptions ??= new DiagnosticOptions());
diagnosticOptions.Unify().WorkspaceDiagnostics = true;

serverCapabilities.DiagnosticProvider ??= new();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ public EditorLspSymbolInformationCreationService()
public SymbolInformation Create(string name, string? containerName, LSP.SymbolKind kind, LSP.Location location, Glyph glyph)
{
var imageId = glyph.GetImageId();
#pragma warning disable CS0618 // SymbolInformation is obsolete, need to switch to DocumentSymbol/WorkspaceSymbol
return new VSSymbolInformation
{
Name = name,
Expand All @@ -32,5 +33,6 @@ public SymbolInformation Create(string name, string? containerName, LSP.SymbolKi
Location = location,
Icon = new VSImageId { Guid = imageId.Guid, Id = imageId.Id },
};
#pragma warning restore CS0618
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ internal static LSP.SymbolInformation CreateSymbolInformation(LSP.SymbolKind kin
{
var imageId = glyph.GetImageId();

#pragma warning disable CS0618 // SymbolInformation is obsolete, need to switch to DocumentSymbol/WorkspaceSymbol
var info = new LSP.VSSymbolInformation()
{
Kind = kind,
Expand All @@ -191,6 +192,7 @@ internal static LSP.SymbolInformation CreateSymbolInformation(LSP.SymbolKind kin

if (containerName != null)
info.ContainerName = containerName;
#pragma warning restore CS0618

return info;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

using Microsoft.CodeAnalysis.LanguageServerIndexFormat.Generator.Graph;
using Roslyn.LanguageServer.Protocol;
using Moniker = Microsoft.CodeAnalysis.LanguageServerIndexFormat.Generator.Graph.Moniker;

namespace Microsoft.CodeAnalysis.LanguageServerIndexFormat.Generator.ResultSetTracking
{
Expand Down
6 changes: 3 additions & 3 deletions src/Features/Lsif/GeneratorTest/HoverTests.vb
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class C
Dim rangeVertex = Await lsif.GetSelectedRangeAsync()
Dim resultSetVertex = lsif.GetLinkedVertices(Of Graph.ResultSet)(rangeVertex, "next").Single()
Dim hoverVertex = lsif.GetLinkedVertices(Of Graph.HoverResult)(resultSetVertex, Methods.TextDocumentHoverName).SingleOrDefault()
Dim hoverMarkupContent = DirectCast(hoverVertex.Result.Contents.Value.Fourth, MarkupContent)
Dim hoverMarkupContent = DirectCast(hoverVertex.Result.Contents.Fourth, MarkupContent)

Dim expectedHoverContents As String
Select Case code
Expand Down Expand Up @@ -110,7 +110,7 @@ class C
Dim rangeVertex = Await lsif.GetSelectedRangeAsync()
Dim resultSetVertex = lsif.GetLinkedVertices(Of Graph.ResultSet)(rangeVertex, "next").Single()
Dim hoverVertex = lsif.GetLinkedVertices(Of Graph.HoverResult)(resultSetVertex, Methods.TextDocumentHoverName).SingleOrDefault()
Dim hoverMarkupContent = DirectCast(hoverVertex.Result.Contents.Value.Fourth, MarkupContent)
Dim hoverMarkupContent = DirectCast(hoverVertex.Result.Contents.Fourth, MarkupContent)

Dim expectedHoverContents As String
Select Case code
Expand Down Expand Up @@ -196,7 +196,7 @@ void C.M()
End If
Next

Dim hoverMarkupContent = DirectCast(hoverVertex.Result.Contents.Value.Fourth, MarkupContent)
Dim hoverMarkupContent = DirectCast(hoverVertex.Result.Contents.Fourth, MarkupContent)
Assert.Equal(MarkupKind.Markdown, hoverMarkupContent.Kind)
Assert.Equal("```csharp
class System.String
Expand Down
3 changes: 2 additions & 1 deletion src/Features/Lsif/GeneratorTest/OutputFormatTests.vb
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ Namespace Microsoft.CodeAnalysis.LanguageServerIndexFormat.Generator.UnitTests
</Workspace>, openDocuments:=False, composition:=TestLsifOutput.TestComposition), jsonWriter)

AssertEx.EqualOrDiff(
"{""hoverProvider"":true,""declarationProvider"":false,""definitionProvider"":true,""referencesProvider"":true,""typeDefinitionProvider"":false,""documentSymbolProvider"":true,""foldingRangeProvider"":true,""diagnosticProvider"":false,""semanticTokensProvider"":{""tokenTypes"":[""namespace"",""type"",""class"",""enum"",""interface"",""struct"",""typeParameter"",""parameter"",""variable"",""property"",""enumMember"",""event"",""function"",""method"",""macro"",""keyword"",""modifier"",""comment"",""string"",""number"",""regexp"",""operator"",""class name"",""constant name"",""delegate name"",""enum member name"",""enum name"",""event name"",""excluded code"",""extension method name"",""field name"",""interface name"",""json - array"",""json - comment"",""json - constructor name"",""json - keyword"",""json - number"",""json - object"",""json - operator"",""json - property name"",""json - punctuation"",""json - string"",""json - text"",""keyword - control"",""label name"",""local name"",""method name"",""module name"",""namespace name"",""operator - overloaded"",""parameter name"",""preprocessor keyword"",""preprocessor text"",""property name"",""punctuation"",""record class name"",""record struct name"",""regex - alternation"",""regex - anchor"",""regex - character class"",""regex - comment"",""regex - grouping"",""regex - other escape"",""regex - quantifier"",""regex - self escaped character"",""regex - text"",""roslyn test code markdown"",""string - escape character"",""string - verbatim"",""struct name"",""text"",""type parameter name"",""whitespace"",""xml doc comment - attribute name"",""xml doc comment - attribute quotes"",""xml doc comment - attribute value"",""xml doc comment - cdata section"",""xml doc comment - comment"",""xml doc comment - delimiter"",""xml doc comment - entity reference"",""xml doc comment - name"",""xml doc comment - processing instruction"",""xml doc comment - text"",""xml literal - attribute name"",""xml literal - attribute quotes"",""xml literal - attribute value"",""xml literal - cdata section"",""xml literal - comment"",""xml literal - delimiter"",""xml literal - embedded expression"",""xml literal - entity reference"",""xml literal - name"",""xml literal - processing instruction"",""xml literal - text""],""tokenModifiers"":[""static"",""deprecated""]},""id"":1,""type"":""vertex"",""label"":""capabilities""}
"{""hoverProvider"":true,""declarationProvider"":false,""definitionProvider"":true,""referencesProvider"":true,""typeDefinitionProvider"":false,""documentSymbolProvider"":true,""foldingRangeProvider"":true,""diagnosticProvider"":false,""semanticTokensProvider"":{""tokenTypes"":[""namespace"",""type"",""class"",""enum"",""interface"",""struct"",""typeParameter"",""parameter"",""variable"",""property"",""enumMember"",""event"",""function"",""method"",""macro"",""keyword"",""modifier"",""comment"",""string"",""number"",""regexp"",""operator"",""decorator"",""class name"",""constant name"",""delegate name"",""enum member name"",""enum name"",""event name"",""excluded code"",""extension method name"",""field name"",""interface name"",""json - array"",""json - comment"",""json - constructor name"",""json - keyword"",""json - number"",""json - object"",""json - operator"",""json - property name"",""json - punctuation"",""json - string"",""json - text"",""keyword - control"",""label name"",""local name"",""method name"",""module name"",""namespace name"",""operator - overloaded"",""parameter name"",""preprocessor keyword"",""preprocessor text"",""property name"",""punctuation"",""record class name"",""record struct name"",""regex - alternation"",""regex - anchor"",""regex - character class"",""regex - comment"",""regex - grouping"",""regex - other escape"",""regex - quantifier"",""regex - self escaped character"",""regex - text"",""roslyn test code markdown"",""string - escape character"",""string - verbatim"",""struct name"",""text"",""type parameter name"",""whitespace"",""xml doc comment - attribute name"",""xml doc comment - attribute quotes"",""xml doc comment - attribute value"",""xml doc comment - cdata section"",""xml doc comment - comment"",""xml doc comment - delimiter"",""xml doc comment - entity reference"",""xml doc comment - name"",""xml doc comment - processing instruction"",""xml doc comment - text"",""xml literal - attribute name"",""xml literal - attribute quotes"",""xml literal - attribute value"",""xml literal - cdata section"",""xml literal - comment"",""xml literal - delimiter"",""xml literal - embedded expression"",""xml literal - entity reference"",""xml literal - name"",""xml literal - processing instruction"",""xml literal - text""],""tokenModifiers"":[""static"",""deprecated""]},""id"":1,""type"":""vertex"",""label"":""capabilities""}
{""kind"":""csharp"",""resource"":""file:///Z:/%EE%89%9B/TestProject.csproj"",""name"":""TestProject"",""id"":2,""type"":""vertex"",""label"":""project""}
{""kind"":""begin"",""scope"":""project"",""data"":2,""id"":3,""type"":""vertex"",""label"":""$event""}
{""uri"":""file:///Z:/%EE%89%9B/a.cs"",""languageId"":""csharp"",""id"":4,""type"":""vertex"",""label"":""document""}
Expand Down Expand Up @@ -94,6 +94,7 @@ Namespace Microsoft.CodeAnalysis.LanguageServerIndexFormat.Generator.UnitTests
""number"",
""regexp"",
""operator"",
""decorator"",
""class name"",
""constant name"",
""delegate name"",
Expand Down
6 changes: 3 additions & 3 deletions src/Features/Lsif/GeneratorTest/SemanticTokensTests.vb
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ Namespace Microsoft.CodeAnalysis.LanguageServerIndexFormat.Generator.UnitTests

<Theory>
<InlineData("", "{""data"":[]}")>
<InlineData("namespace Foo;", "{""data"":[0,0,9,15,0,0,10,3,48,0,0,3,1,54,0]}")>
<InlineData("namespace " & vbCrLf & " Foo {}", "{""data"":[0,0,9,15,0,2,1,3,48,0,0,4,1,54,0,0,1,1,54,0]}")>
<InlineData("public class Foo { System.Collections.IList FooList { get; set; } int FooMethod() { int x = 0; return x; } }", "{""data"":[0,0,6,15,0,0,7,5,15,0,0,6,3,22,0,0,4,1,54,0,0,2,6,48,0,0,6,1,21,0,0,1,11,48,0,0,11,1,21,0,0,1,5,31,0,0,6,7,53,0,0,8,1,54,0,0,2,3,15,0,0,3,1,54,0,0,2,3,15,0,0,3,1,54,0,0,2,1,54,0,0,2,3,15,0,0,4,9,46,0,0,9,1,54,0,0,1,1,54,0,0,2,1,54,0,0,2,3,15,0,0,4,1,45,0,0,2,1,21,0,0,2,1,19,0,0,1,1,54,0,0,2,6,43,0,0,7,1,45,0,0,1,1,54,0,0,2,1,54,0,0,2,1,54,0]}")>
<InlineData("namespace Foo;", "{""data"":[0,0,9,15,0,0,10,3,49,0,0,3,1,55,0]}")>
<InlineData("namespace " & vbCrLf & " Foo {}", "{""data"":[0,0,9,15,0,2,1,3,49,0,0,4,1,55,0,0,1,1,55,0]}")>
<InlineData("public class Foo { System.Collections.IList FooList { get; set; } int FooMethod() { int x = 0; return x; } }", "{""data"":[0,0,6,15,0,0,7,5,15,0,0,6,3,23,0,0,4,1,55,0,0,2,6,49,0,0,6,1,21,0,0,1,11,49,0,0,11,1,21,0,0,1,5,32,0,0,6,7,54,0,0,8,1,55,0,0,2,3,15,0,0,3,1,55,0,0,2,3,15,0,0,3,1,55,0,0,2,1,55,0,0,2,3,15,0,0,4,9,47,0,0,9,1,55,0,0,1,1,55,0,0,2,1,55,0,0,2,3,15,0,0,4,1,46,0,0,2,1,21,0,0,2,1,19,0,0,1,1,55,0,0,2,6,44,0,0,7,1,46,0,0,1,1,55,0,0,2,1,55,0,0,2,1,55,0]}")>
Public Async Function TestSemanticTokensData(code As String, expectedTokens As String) As Task
' This test performs LSIF specific validation of the semantic tokens output. As of this writing
' this feature is based on the same code path used to generate semantic tokens information in LSP
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public class LspFileChangeWatcherTests : AbstractLanguageServerHostTests
{
Workspace = new WorkspaceClientCapabilities
{
DidChangeWatchedFiles = new DynamicRegistrationSetting { DynamicRegistration = true }
DidChangeWatchedFiles = new DidChangeWatchedFilesClientCapabilities { DynamicRegistration = true }
}
};

Expand Down Expand Up @@ -66,8 +66,8 @@ public async Task CreatingDirectoryWatchRequestsDirectoryWatch()

var watcher = GetSingleFileWatcher(dynamicCapabilitiesRpcTarget);

Assert.Equal(tempDirectory.Path, watcher.GlobPattern.BaseUri.LocalPath);
Assert.Equal("**/*", watcher.GlobPattern.Pattern);
Assert.Equal(tempDirectory.Path, watcher.GlobPattern.Second.BaseUri.Second.LocalPath);
Assert.Equal("**/*", watcher.GlobPattern.Second.Pattern);

// Get rid of the registration and it should be gone again
context.Dispose();
Expand Down Expand Up @@ -98,8 +98,8 @@ public async Task CreatingFileWatchRequestsFileWatch()

var watcher = GetSingleFileWatcher(dynamicCapabilitiesRpcTarget);

Assert.Equal("Z:\\", watcher.GlobPattern.BaseUri.LocalPath);
Assert.Equal("SingleFile.txt", watcher.GlobPattern.Pattern);
Assert.Equal("Z:\\", watcher.GlobPattern.Second.BaseUri.Second.LocalPath);
Assert.Equal("SingleFile.txt", watcher.GlobPattern.Second.Pattern);

// Get rid of the registration and it should be gone again
watchedFile.Dispose();
Expand Down Expand Up @@ -134,7 +134,7 @@ public Task RegisterCapabilityAsync(RegistrationParams registrationParams, Cance
}

[JsonRpcMethod("client/unregisterCapability", UseSingleObjectParameterDeserialization = true)]
public Task UnregisterCapabilityAsync(UnregistrationParamsWithMisspelling unregistrationParams, CancellationToken _)
public Task UnregisterCapabilityAsync(UnregistrationParams unregistrationParams, CancellationToken _)
{
foreach (var unregistration in unregistrationParams.Unregistrations)
Assert.True(Registrations.TryRemove(unregistration.Id, out var _));
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ public void Dispose()

_registrationTask.ContinueWith(async _ =>
{
var unregistrationParams = new UnregistrationParamsWithMisspelling()
var unregistrationParams = new UnregistrationParams()
{
Unregistrations =
[
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public async Task InitializeServer_SerializesCorrectly()
var server = TestExampleLanguageServer.CreateLanguageServer(logger);

var result = await server.InitializeServerAsync();
Assert.True(result.Capabilities.SemanticTokensOptions!.Range!.Value.First);
Assert.True(result.Capabilities.SemanticTokensOptions!.Value.Unify().Range!.Value.First);
}

[Fact]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -453,7 +453,7 @@ public static LSP.Range TextSpanToRange(TextSpan textSpan, SourceText text)
}
}

var documentEdits = uriToTextEdits.GroupBy(uriAndEdit => uriAndEdit.Uri, uriAndEdit => uriAndEdit.TextEdit, (uri, edits) => new LSP.TextDocumentEdit
var documentEdits = uriToTextEdits.GroupBy(uriAndEdit => uriAndEdit.Uri, uriAndEdit => new LSP.SumType<LSP.TextEdit, LSP.AnnotatedTextEdit>(uriAndEdit.TextEdit), (uri, edits) => new LSP.TextDocumentEdit
{
TextDocument = new LSP.OptionalVersionedTextDocumentIdentifier { Uri = uri },
Edits = edits.ToArray(),
Expand Down
12 changes: 12 additions & 0 deletions src/LanguageServer/Protocol/Handler/BufferedProgress.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System;
using System.Linq;
using Microsoft.CodeAnalysis.PooledObjects;
using Roslyn.LanguageServer.Protocol;
using Roslyn.Utilities;

namespace Microsoft.CodeAnalysis.LanguageServer.Handler
Expand Down Expand Up @@ -69,6 +70,12 @@ internal static class BufferedProgress
public static BufferedProgress<T> Create<T>(IProgress<T>? progress)
=> new BufferedProgress<T>(progress);

public static BufferedProgress<TIn> Create<TIn, TOut>(IProgress<TOut>? progress, Func<TIn, TOut> transform)
=> Create(progress?.Transform(transform));

static IProgress<TIn> Transform<TIn, TOut>(this IProgress<TOut> progress, Func<TIn, TOut> transform)
=> new ProgressTransformer<TIn, TOut>(progress, transform);

public static void Report<T>(this BufferedProgress<T[]> progress, T item)
{
progress.Report([item]);
Expand All @@ -78,5 +85,10 @@ public static void Report<T>(this BufferedProgress<T[]> progress, T item)
{
return progress.GetValues()?.Flatten().ToArray();
}

class ProgressTransformer<TIn, TOut>(IProgress<TOut> inner, Func<TIn, TOut> transform) : IProgress<TIn>
{
public void Report(TIn value) => inner.Report(transform(value));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ async Task AddTextDocumentEditsAsync<TTextDocument>(
textChanges = newText.GetTextChanges(oldText);
}

var edits = textChanges.Select(tc => ProtocolConversions.TextChangeToTextEdit(tc, oldText)).ToArray();
var edits = textChanges.Select(tc => new LSP.SumType<LSP.TextEdit, LSP.AnnotatedTextEdit>(ProtocolConversions.TextChangeToTextEdit(tc, oldText))).ToArray();

if (edits.Length > 0)
{
Expand Down
Loading

0 comments on commit 2543698

Please sign in to comment.