Skip to content

Commit 8b2ab62

Browse files
committed
LSP Protocol: Support Uri in SumType
1 parent 2e3dc5f commit 8b2ab62

File tree

3 files changed

+12
-4
lines changed

3 files changed

+12
-4
lines changed

src/LanguageServer/Microsoft.CodeAnalysis.LanguageServer.UnitTests/LspFileChangeWatcherTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ public async Task CreatingDirectoryWatchRequestsDirectoryWatch()
6666

6767
var watcher = GetSingleFileWatcher(dynamicCapabilitiesRpcTarget);
6868

69-
Assert.Equal(tempDirectory.Path, watcher.GlobPattern.Second.BaseUri.First.LocalPath);
69+
Assert.Equal(tempDirectory.Path, watcher.GlobPattern.Second.BaseUri.Second.LocalPath);
7070
Assert.Equal("**/*", watcher.GlobPattern.Second.Pattern);
7171

7272
// Get rid of the registration and it should be gone again
@@ -98,7 +98,7 @@ public async Task CreatingFileWatchRequestsFileWatch()
9898

9999
var watcher = GetSingleFileWatcher(dynamicCapabilitiesRpcTarget);
100100

101-
Assert.Equal("Z:\\", watcher.GlobPattern.Second.BaseUri.First.LocalPath);
101+
Assert.Equal("Z:\\", watcher.GlobPattern.Second.BaseUri.Second.LocalPath);
102102
Assert.Equal("SingleFile.txt", watcher.GlobPattern.Second.Pattern);
103103

104104
// Get rid of the registration and it should be gone again

src/LanguageServer/Protocol/Protocol/Converters/SumConverter.cs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ public override T Read(ref Utf8JsonReader reader, Type objectType, JsonSerialize
249249
}
250250
}
251251

252-
throw new JsonException(LanguageServerProtocolResources.NoSumTypeMatch);
252+
throw new JsonException($"No sum type match for {objectType}");
253253
}
254254

255255
/// <inheritdoc/>
@@ -259,6 +259,13 @@ public override void Write(Utf8JsonWriter writer, T value, JsonSerializerOptions
259259

260260
var sumValue = value.Value;
261261

262+
// behavior from DocumentUriConverter
263+
if (sumValue is Uri)
264+
{
265+
writer.WriteStringValue(sumValue.ToString());
266+
return;
267+
}
268+
262269
if (sumValue != null)
263270
{
264271
JsonSerializer.Serialize(writer, sumValue, options);
@@ -288,6 +295,7 @@ private static bool IsTokenCompatibleWithType(ref Utf8JsonReader reader, SumConv
288295
break;
289296
case JsonTokenType.String:
290297
isCompatible = unionTypeInfo.Type == typeof(string) ||
298+
unionTypeInfo.Type == typeof(Uri) ||
291299
typeof(IStringEnum).IsAssignableFrom(unionTypeInfo.Type);
292300
break;
293301
}

src/LanguageServer/Protocol/Protocol/FileOperations/RelativePattern.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ internal class RelativePattern
2121
/// </summary>
2222
[JsonPropertyName("baseUri")]
2323
[JsonRequired]
24-
public SumType<Uri, WorkspaceFolder> BaseUri { get; init; }
24+
public SumType<WorkspaceFolder, Uri> BaseUri { get; init; }
2525

2626
/// <summary>
2727
/// The actual glob pattern. See <see href="https://microsoft.github.io/language-server-protocol/specifications/specification-current/#pattern">Glob Pattern</see> for more detail.

0 commit comments

Comments
 (0)