зеркало из https://github.com/dotnet/razor.git
Handle spaces in C# semantic requests (#3622)
Handle spaces in C# semantic requests
This commit is contained in:
Родитель
5ef5ed4e77
Коммит
8469d8a26e
|
@ -6,6 +6,7 @@ using System.Collections.Generic;
|
|||
using System.Composition;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Razor.LanguageServer.Common;
|
||||
|
@ -279,12 +280,8 @@ namespace Microsoft.VisualStudio.LanguageServerClient.Razor
|
|||
throw new ArgumentNullException(nameof(semanticTokensParams));
|
||||
}
|
||||
|
||||
if (!_documentManager.TryGetDocument(semanticTokensParams.TextDocument.Uri, out var documentSnapshot))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
if (!documentSnapshot.TryGetVirtualDocument<CSharpVirtualDocumentSnapshot>(out var csharpDoc))
|
||||
var csharpDoc = GetCSharpDocumentSnapshsot(semanticTokensParams.TextDocument.Uri);
|
||||
if (csharpDoc is null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
@ -314,12 +311,8 @@ namespace Microsoft.VisualStudio.LanguageServerClient.Razor
|
|||
throw new ArgumentNullException(nameof(semanticTokensEditsParams));
|
||||
}
|
||||
|
||||
if (!_documentManager.TryGetDocument(semanticTokensEditsParams.TextDocument.Uri, out var documentSnapshot))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
if (!documentSnapshot.TryGetVirtualDocument<CSharpVirtualDocumentSnapshot>(out var csharpDoc))
|
||||
var csharpDoc = GetCSharpDocumentSnapshsot(semanticTokensEditsParams.TextDocument.Uri);
|
||||
if (csharpDoc is null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
@ -356,6 +349,24 @@ namespace Microsoft.VisualStudio.LanguageServerClient.Razor
|
|||
}
|
||||
}
|
||||
|
||||
private CSharpVirtualDocumentSnapshot GetCSharpDocumentSnapshsot(Uri uri)
|
||||
{
|
||||
var normalizedString = uri.GetAbsoluteOrUNCPath();
|
||||
var normalizedUri = new Uri(WebUtility.UrlDecode(normalizedString));
|
||||
|
||||
if (!_documentManager.TryGetDocument(normalizedUri, out var documentSnapshot))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
if (!documentSnapshot.TryGetVirtualDocument<CSharpVirtualDocumentSnapshot>(out var csharpDoc))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
return csharpDoc;
|
||||
}
|
||||
|
||||
public override async Task RazorServerReadyAsync(CancellationToken cancellationToken)
|
||||
{
|
||||
// Doing both UIContext and BrokeredService while integrating
|
||||
|
|
|
@ -396,9 +396,9 @@ namespace Microsoft.VisualStudio.LanguageServerClient.Razor
|
|||
public async Task ProvideSemanticTokensAsync_ReturnsSemanticTokensAsync()
|
||||
{
|
||||
// Arrange
|
||||
var testDocUri = new Uri("C:/path/to/file.razor");
|
||||
var testVirtualDocUri = new Uri("C:/path/to/file2.razor.g");
|
||||
var testCSharpDocUri = new Uri("C:/path/to/file.razor.g.cs");
|
||||
var testDocUri = new Uri("C:/path/to - project/file.razor");
|
||||
var testVirtualDocUri = new Uri("C:/path/to - project/file2.razor.g");
|
||||
var testCSharpDocUri = new Uri("C:/path/to - project/file.razor.g.cs");
|
||||
|
||||
var documentVersion = 0;
|
||||
var testVirtualDocument = new TestVirtualDocumentSnapshot(testVirtualDocUri, 0);
|
||||
|
@ -406,7 +406,7 @@ namespace Microsoft.VisualStudio.LanguageServerClient.Razor
|
|||
LSPDocumentSnapshot testDocument = new TestLSPDocumentSnapshot(testDocUri, documentVersion, testVirtualDocument, csharpVirtualDocument);
|
||||
|
||||
var documentManager = new Mock<TrackingLSPDocumentManager>(MockBehavior.Strict);
|
||||
documentManager.Setup(manager => manager.TryGetDocument(It.IsAny<Uri>(), out testDocument))
|
||||
documentManager.Setup(manager => manager.TryGetDocument(testDocUri, out testDocument))
|
||||
.Returns(true);
|
||||
|
||||
var expectedcSharpResults = new OmniSharp.Extensions.LanguageServer.Protocol.Models.Proposals.SemanticTokens();
|
||||
|
@ -429,7 +429,7 @@ namespace Microsoft.VisualStudio.LanguageServerClient.Razor
|
|||
{
|
||||
TextDocument = new TextDocumentIdentifier()
|
||||
{
|
||||
Uri = testDocUri
|
||||
Uri = new Uri("C:/path/to%20-%20project/file.razor")
|
||||
}
|
||||
};
|
||||
var expectedResults = new ProvideSemanticTokensResponse(expectedcSharpResults, documentVersion);
|
||||
|
|
Загрузка…
Ссылка в новой задаче