Skip to content

Commit 878897c

Browse files
DocumentUri Version 2! (#245)
* Document UI v2 porting in the uri from vscode with a patch to handle the windows paths Co-authored-by: Tyler James Leonhardt <[email protected]>
1 parent 83272f7 commit 878897c

11 files changed

+1794
-573
lines changed

src/Protocol/CharCode.cs

Lines changed: 414 additions & 0 deletions
Large diffs are not rendered by default.

src/Protocol/DocumentUri.Internal.cs

Lines changed: 433 additions & 0 deletions
Large diffs are not rendered by default.

src/Protocol/DocumentUri.cs

Lines changed: 204 additions & 149 deletions
Large diffs are not rendered by default.

src/Protocol/DocumentUriComponents.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
namespace OmniSharp.Extensions.LanguageServer.Protocol
2+
{
3+
public struct DocumentUriComponents
4+
{
5+
public string Scheme { get; set; }
6+
public string Authority { get; set; }
7+
public string Path { get; set; }
8+
public string Query { get; set; }
9+
public string Fragment { get; set; }
10+
}
11+
}

test/Client.Tests/ClientTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public ClientTests(ITestOutputHelper testOutput)
3838
/// <summary>
3939
/// Get an absolute document path for use in tests.
4040
/// </summary>
41-
string AbsoluteDocumentPath => IsWindows ? @"C:\Foo.txt" : "/Foo.txt";
41+
string AbsoluteDocumentPath => IsWindows ? @"c:\Foo.txt" : "/Foo.txt";
4242

4343
/// <summary>
4444
/// The <see cref="LanguageClient"/> under test.

test/Lsp.Tests/AbsoluteUriConverterTests.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,29 +21,29 @@ public AbsoluteUriConverterTests(ITestOutputHelper testOutputHelper)
2121
[ClassData(typeof(DocumentUriTests.WindowsPathAltStringUris))]
2222
[ClassData(typeof(DocumentUriTests.UncPathStringUris))]
2323
[ClassData(typeof(DocumentUriTests.UnixPathStringUris))]
24-
public void Should_Deserialize_VSCode_Style_Uris(string uri, DocumentUri expected)
24+
public void Should_Deserialize_VSCode_Style_Uris(string uri, string expected)
2525
{
2626
_testOutputHelper.WriteLine($"Given: {uri}");
2727
_testOutputHelper.WriteLine($"Expected: {expected}");
2828
var serializer = new JsonSerializerSettings() {
2929
Converters = {new DocumentUriConverter()}
3030
};
31-
JsonConvert.DeserializeObject<DocumentUri>($"\"{uri}\"", serializer).Should().Be(expected);
31+
JsonConvert.DeserializeObject<DocumentUri>($"\"{uri}\"", serializer).ToString().Should().Be(expected);
3232
}
3333

3434
[Theory]
3535
[ClassData(typeof(DocumentUriTests.WindowsPathStringUris))]
3636
[ClassData(typeof(DocumentUriTests.WindowsPathAltStringUris))]
3737
[ClassData(typeof(DocumentUriTests.UncPathStringUris))]
3838
[ClassData(typeof(DocumentUriTests.UnixPathStringUris))]
39-
public void Should_Serialize_VSCode_Style_Uris(string uri, DocumentUri expected)
39+
public void Should_Serialize_VSCode_Style_Uris(string uri, string expected)
4040
{
4141
_testOutputHelper.WriteLine($"Given: {uri}");
4242
_testOutputHelper.WriteLine($"Expected: {expected}");
4343
var serializer = new JsonSerializerSettings() {
4444
Converters = {new DocumentUriConverter()}
4545
};
46-
JsonConvert.SerializeObject(new DocumentUri(uri), serializer).Trim('"').Should().Be(expected.ToString());
46+
JsonConvert.SerializeObject(DocumentUri.Parse(uri), serializer).Trim('"').Should().Be(expected);
4747
}
4848
}
4949
}

test/Lsp.Tests/DocumentUriTests.cs

Lines changed: 159 additions & 416 deletions
Large diffs are not rendered by default.

test/Lsp.Tests/Models/DidChangeTextDocumentParamsTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public void NonStandardCharactersTest(string expected)
4747
}
4848
},
4949
TextDocument = new VersionedTextDocumentIdentifier() {
50-
Uri = DocumentUri.FromFileSystemPath("C:\\abc\\Mörkö.cs")
50+
Uri = DocumentUri.FromFileSystemPath("c:\\abc\\Mörkö.cs")
5151
}
5252
};
5353
var result = Fixture.SerializeObject(model);

test/Lsp.Tests/Models/DidChangeTextDocumentParamsTests_$NonStandardCharactersTest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"textDocument": {
33
"version": 0,
4-
"uri": "file:///C:/abc/M%C3%B6rk%C3%B6.cs"
4+
"uri": "file:///c:/abc/M%C3%B6rk%C3%B6.cs"
55
},
66
"contentChanges": [
77
{

test/Lsp.Tests/Models/TextDocumentIdentifierTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public void Should_Deserialize_For_Example_Value()
3131
""uri"":""file:///Users/tyler/Code/PowerShell/vscode/PowerShellEditorServices/test/PowerShellEditorServices.Test.E2E/bin/Debug/netcoreapp3.1/0b0jnxg2.kgh.ps1""
3232
}");
3333

34-
result.Uri.Should().Be(new DocumentUri("file:///Users/tyler/Code/PowerShell/vscode/PowerShellEditorServices/test/PowerShellEditorServices.Test.E2E/bin/Debug/netcoreapp3.1/0b0jnxg2.kgh.ps1"));
34+
result.Uri.Should().Be(DocumentUri.Parse("file:///Users/tyler/Code/PowerShell/vscode/PowerShellEditorServices/test/PowerShellEditorServices.Test.E2E/bin/Debug/netcoreapp3.1/0b0jnxg2.kgh.ps1"));
3535
}
3636
}
3737
}

0 commit comments

Comments
 (0)