Skip to content

Commit

Permalink
Merge pull request #71395 from jasonmalinowski/fix-uri-creation-error…
Browse files Browse the repository at this point in the history
…s-for-generated-documents

Call GetURI when getting a URI for a document
  • Loading branch information
jasonmalinowski authored Dec 22, 2023
2 parents 944f84f + 837cfcc commit 182e829
Show file tree
Hide file tree
Showing 6 changed files with 6 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -453,7 +453,7 @@ protected static void AddMappedDocument(Workspace workspace, string markup)
Contract.ThrowIfNull(document.FilePath);

var locationsForName = locations.GetValueOrDefault(name, new List<LSP.Location>());
locationsForName.AddRange(spans.Select(span => ConvertTextSpanWithTextToLocation(span, text, ProtocolConversions.CreateAbsoluteUri(document.FilePath))));
locationsForName.AddRange(spans.Select(span => ConvertTextSpanWithTextToLocation(span, text, document.GetURI())));

// Linked files will return duplicate annotated Locations for each document that links to the same file.
// Since the test output only cares about the actual file, make sure we de-dupe before returning.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -476,7 +476,7 @@ public static LSP.Range TextSpanToRange(TextSpan textSpan, SourceText text)
CancellationToken cancellationToken)
{
Debug.Assert(document.FilePath != null);
var uri = CreateAbsoluteUri(document.FilePath);
var uri = document.GetURI();

var text = await document.GetValueTextAsync(cancellationToken).ConfigureAwait(false);
if (isStale)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public async Task TestGetFoldingRangeAsync_Regions(bool mutatingLspWorkspace)
var document = testLspServer.GetCurrentSolution().Projects.First().Documents.First();
var request = new LSP.FoldingRangeParams()
{
TextDocument = CreateTextDocumentIdentifier(ProtocolConversions.CreateAbsoluteUri(document.FilePath))
TextDocument = CreateTextDocumentIdentifier(document.GetURI())
};

return await testLspServer.ExecuteRequestAsync<LSP.FoldingRangeParams, LSP.FoldingRange[]>(LSP.Methods.TextDocumentFoldingRangeName,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ void M()
Assert.Null(GetMiscellaneousDocument(testLspServer));

// Open a file that is part of a registered workspace and verify it is not present in the misc workspace.
var fileInWorkspaceUri = ProtocolConversions.CreateAbsoluteUri(testLspServer.GetCurrentSolution().Projects.Single().Documents.Single().FilePath!);
var fileInWorkspaceUri = testLspServer.GetCurrentSolution().Projects.Single().Documents.Single().GetURI();
await testLspServer.OpenDocumentAsync(fileInWorkspaceUri).ConfigureAwait(false);
Assert.Null(GetMiscellaneousDocument(testLspServer));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ private static async Task<TReturn> RunGetDocumentSymbolsAsync<TReturn>(TestLspSe
var document = testLspServer.GetCurrentSolution().Projects.First().Documents.First();
var request = new LSP.DocumentSymbolParams
{
TextDocument = CreateTextDocumentIdentifier(ProtocolConversions.CreateAbsoluteUri(document.FilePath))
TextDocument = CreateTextDocumentIdentifier(document.GetURI())
};

return await testLspServer.ExecuteRequestAsync<LSP.DocumentSymbolParams, TReturn>(LSP.Methods.TextDocumentDocumentSymbolName,
Expand Down
5 changes: 1 addition & 4 deletions src/Tools/ExternalAccess/Razor/RazorUri.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,6 @@ public static Uri CreateAbsoluteUri(string absolutePath)

public static Uri CreateUri(this TextDocument document)
{
Contract.ThrowIfNull(document.FilePath);
return document is SourceGeneratedDocument
? ProtocolConversions.CreateUriFromSourceGeneratedFilePath(document.FilePath)
: ProtocolConversions.CreateAbsoluteUri(document.FilePath);
return document.GetURI();
}
}

0 comments on commit 182e829

Please sign in to comment.