Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ internal abstract class AbstractVSTypeScriptRequestHandler<TRequestType, TRespon

var textDocumentIdentifier = new VSTextDocumentIdentifier
{
Uri = typeScriptIdentifier.Value.Uri,
DocumentUri = new(typeScriptIdentifier.Value.Uri),
};

if (typeScriptIdentifier.Value.ProjectId != null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
using StreamJsonRpc;
using Xunit;
using Xunit.Abstractions;
using System.Text.Json.Serialization;

namespace Microsoft.CodeAnalysis.Editor.UnitTests.LanguageServer;

Expand Down Expand Up @@ -138,7 +139,7 @@ public static async Task<VSTypeScriptTestLspServer> CreateAsync(LspTestWorkspace
}
}

internal sealed record TSRequest(Uri Document, string Project);
internal sealed record TSRequest([property: JsonConverter(typeof(DocumentUriConverter))] DocumentUri Document, string Project);

[ExportTypeScriptLspServiceFactory(typeof(TypeScriptHandler)), PartNotDiscoverable, Shared]
internal sealed class TypeScriptHandlerFactory : AbstractVSTypeScriptRequestHandlerFactory
Expand Down Expand Up @@ -168,7 +169,7 @@ internal sealed class TypeScriptHandler : AbstractVSTypeScriptRequestHandler<TSR

protected override TypeScriptTextDocumentIdentifier? GetTypeSciptTextDocumentIdentifier(TSRequest request)
{
return new TypeScriptTextDocumentIdentifier(request.Document, request.Project);
return new TypeScriptTextDocumentIdentifier(request.Document.GetRequiredParsedUri(), request.Project);
}

protected override Task<int> HandleRequestAsync(TSRequest request, TypeScriptRequestContext context, CancellationToken cancellationToken)
Expand Down
2 changes: 1 addition & 1 deletion src/Features/Lsif/Generator/Generator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ public async Task GenerateForProjectAsync(

var contentBase64Encoded = await GetBase64EncodedContentAsync(document, cancellationToken);

var documentVertex = new Graph.LsifDocument(document.GetURI(), GetLanguageKind(semanticModel.Language), contentBase64Encoded, idFactory);
var documentVertex = new Graph.LsifDocument(document.GetURI().GetRequiredParsedUri(), GetLanguageKind(semanticModel.Language), contentBase64Encoded, idFactory);
lsifJsonWriter.Write(documentVertex);
lsifJsonWriter.Write(new Event(Event.EventKind.Begin, documentVertex.GetId(), idFactory));

Expand Down
1 change: 1 addition & 0 deletions src/Features/Lsif/Generator/Graph/LsifDocument.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// See the LICENSE file in the project root for more information.

using System;
using Roslyn.LanguageServer.Protocol;

namespace Microsoft.CodeAnalysis.LanguageServerIndexFormat.Generator.Graph;

Expand Down
1 change: 1 addition & 0 deletions src/Features/Lsif/Generator/Graph/LsifProject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// See the LICENSE file in the project root for more information.

using System;
using Roslyn.LanguageServer.Protocol;

namespace Microsoft.CodeAnalysis.LanguageServerIndexFormat.Generator.Graph;

Expand Down
2 changes: 1 addition & 1 deletion src/Features/Lsif/GeneratorTest/ProjectStructureTests.vb
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ Namespace Microsoft.CodeAnalysis.LanguageServerIndexFormat.Generator.UnitTests
Await TestLsifOutput.GenerateForWorkspaceAsync(workspace, New LineModeLsifJsonWriter(stringWriter))

Dim generatedDocument = Assert.Single(Await workspace.CurrentSolution.Projects.Single().GetSourceGeneratedDocumentsAsync())
Dim uri = SourceGeneratedDocumentUri.Create(generatedDocument.Identity)
Dim uri = SourceGeneratedDocumentUri.Create(generatedDocument.Identity).GetRequiredParsedUri()
Dim outputText = stringWriter.ToString()
Assert.Contains(uri.AbsoluteUri, outputText)
End Function
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ internal abstract class AbstractCompilerDeveloperSdkLspServiceDocumentRequestHan
bool ISolutionRequiredHandler.RequiresLSPSolution => RequiresLSPSolution;

TextDocumentIdentifier ITextDocumentIdentifierHandler<TRequest, TextDocumentIdentifier>.GetTextDocumentIdentifier(TRequest request)
=> new() { Uri = GetTextDocumentIdentifier(request) };
=> new() { DocumentUri = new(GetTextDocumentIdentifier(request)) };
Task<TResponse> IRequestHandler<TRequest, TResponse, LspRequestContext>.HandleRequestAsync(TRequest request, LspRequestContext context, CancellationToken cancellationToken)
=> HandleRequestAsync(request, new RequestContext(context), cancellationToken);
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ internal abstract class AbstractCopilotLspServiceDocumentRequestHandler<TRequest
bool ISolutionRequiredHandler.RequiresLSPSolution => true;

TextDocumentIdentifier ITextDocumentIdentifierHandler<TRequest, TextDocumentIdentifier>.GetTextDocumentIdentifier(TRequest request)
=> new() { Uri = GetTextDocumentUri(request) };
=> new() { DocumentUri = new(GetTextDocumentUri(request)) };

Task<TResponse> IRequestHandler<TRequest, TResponse, RequestContext>.HandleRequestAsync(TRequest request, RequestContext context, CancellationToken cancellationToken)
=> HandleRequestAsync(request, new CopilotRequestContext(context), cancellationToken);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public async Task<ImmutableArray<DiagnosticData>> GetDiagnosticsAsync(RequestCon
return result;
}

public TextDocumentIdentifier? GetDocumentIdentifier() => new() { Uri = textDocument.GetURI() };
public TextDocumentIdentifier? GetDocumentIdentifier() => new() { DocumentUri = textDocument.GetURI() };
public ProjectOrDocumentId GetId() => new(textDocument.Id);
public Project GetProject() => textDocument.Project;
public bool IsLiveSource() => true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public async Task CreatingDirectoryWatchRequestsDirectoryWatch()

var watcher = GetSingleFileWatcher(dynamicCapabilitiesRpcTarget);

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

// Get rid of the registration and it should be gone again
Expand Down Expand Up @@ -93,7 +93,7 @@ public async Task CreatingFileWatchRequestsFileWatch()

var watcher = GetSingleFileWatcher(dynamicCapabilitiesRpcTarget);

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

// Get rid of the registration and it should be gone again
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ public ServerInitializationTests(ITestOutputHelper testOutputHelper) : base(test
public async Task TestServerHandlesTextSyncRequestsAsync()
{
await using var server = await CreateLanguageServerAsync();
var document = new VersionedTextDocumentIdentifier { Uri = ProtocolConversions.CreateAbsoluteUri("C:\\\ue25b\ud86d\udeac.cs") };
var document = new VersionedTextDocumentIdentifier { DocumentUri = ProtocolConversions.CreateAbsoluteDocumentUri("C:\\\ue25b\ud86d\udeac.cs") };
var response = await server.ExecuteRequestAsync<DidOpenTextDocumentParams, object>(Methods.TextDocumentDidOpenName, new DidOpenTextDocumentParams
{
TextDocument = new TextDocumentItem
{
Uri = document.Uri,
DocumentUri = document.DocumentUri,
Text = "Write"
}
}, CancellationToken.None);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ private static async Task TestCodeActionAsync(

testLspClient.ApplyWorkspaceEdit(resolvedCodeAction.Edit);

var updatedCode = testLspClient.GetDocumentText(caretLocation.Uri);
var updatedCode = testLspClient.GetDocumentText(caretLocation.DocumentUri);

AssertEx.Equal(expected, updatedCode);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ internal sealed class TestLspClient : ILspClient, IAsyncDisposable
private int _disposed = 0;

private readonly Process _process;
private readonly Dictionary<Uri, SourceText> _documents;
private readonly Dictionary<DocumentUri, SourceText> _documents;
private readonly Dictionary<string, IList<LSP.Location>> _locations;
private readonly ILoggerFactory _loggerFactory;

Expand All @@ -38,7 +38,7 @@ internal static async Task<TestLspClient> CreateAsync(
bool includeDevKitComponents,
bool debugLsp,
ILoggerFactory loggerFactory,
Dictionary<Uri, SourceText>? documents = null,
Dictionary<DocumentUri, SourceText>? documents = null,
Dictionary<string, IList<LSP.Location>>? locations = null)
{
var pipeName = CreateNewPipeName();
Expand Down Expand Up @@ -124,7 +124,7 @@ static ProcessStartInfo CreateLspStartInfo(string pipeName, string extensionLogs

internal ServerCapabilities ServerCapabilities => _serverCapabilities ?? throw new InvalidOperationException("Initialize has not been called");

private TestLspClient(Process process, string pipeName, Dictionary<Uri, SourceText> documents, Dictionary<string, IList<LSP.Location>> locations, ILoggerFactory loggerFactory)
private TestLspClient(Process process, string pipeName, Dictionary<DocumentUri, SourceText> documents, Dictionary<string, IList<LSP.Location>> locations, ILoggerFactory loggerFactory)
{
_documents = documents;
_locations = locations;
Expand Down Expand Up @@ -229,7 +229,7 @@ public void ApplyWorkspaceEdit(WorkspaceEdit? workspaceEdit)

foreach (var documentEdit in textDocumentEdits)
{
var uri = documentEdit.TextDocument.Uri;
var uri = documentEdit.TextDocument.DocumentUri;
var document = _documents[uri];

var changes = documentEdit.Edits
Expand All @@ -242,7 +242,7 @@ public void ApplyWorkspaceEdit(WorkspaceEdit? workspaceEdit)
}
}

public string GetDocumentText(Uri uri) => _documents[uri].ToString();
public string GetDocumentText(DocumentUri uri) => _documents[uri].ToString();

public IList<LSP.Location> GetLocations(string locationName) => _locations[locationName];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,9 @@ await File.WriteAllTextAsync(projectPath, $"""
var codePath = Path.Combine(projectDirectory.Path, "Code.cs");
await File.WriteAllTextAsync(codePath, code);

#pragma warning disable RS0030 // Do not use banned APIs
Uri codeUri = new(codePath);
#pragma warning restore RS0030 // Do not use banned APIs
var codeUri = ProtocolConversions.CreateAbsoluteDocumentUri(codePath);
var text = SourceText.From(code);
Dictionary<Uri, SourceText> files = new() { [codeUri] = text };
Dictionary<DocumentUri, SourceText> files = new() { [codeUri] = text };
var annotatedLocations = GetAnnotatedLocations(codeUri, text, spans);

// Create server and open the project
Expand Down Expand Up @@ -93,7 +91,7 @@ await File.WriteAllTextAsync(projectPath, $"""
return lspClient;
}

private protected static Dictionary<string, IList<LSP.Location>> GetAnnotatedLocations(Uri codeUri, SourceText text, ImmutableDictionary<string, ImmutableArray<TextSpan>> spanMap)
private protected static Dictionary<string, IList<LSP.Location>> GetAnnotatedLocations(DocumentUri codeUri, SourceText text, ImmutableDictionary<string, ImmutableArray<TextSpan>> spanMap)
{
var locations = new Dictionary<string, IList<LSP.Location>>();
foreach (var (name, spans) in spanMap)
Expand All @@ -108,21 +106,21 @@ await File.WriteAllTextAsync(projectPath, $"""

return locations;

static LSP.Location ConvertTextSpanWithTextToLocation(TextSpan span, SourceText text, Uri documentUri)
static LSP.Location ConvertTextSpanWithTextToLocation(TextSpan span, SourceText text, DocumentUri documentUri)
{
var location = new LSP.Location
{
Uri = documentUri,
DocumentUri = documentUri,
Range = ProtocolConversions.TextSpanToRange(span, text),
};

return location;
}
}

private protected static TextDocumentIdentifier CreateTextDocumentIdentifier(Uri uri, ProjectId? projectContext = null)
private protected static TextDocumentIdentifier CreateTextDocumentIdentifier(DocumentUri uri, ProjectId? projectContext = null)
{
var documentIdentifier = new VSTextDocumentIdentifier { Uri = uri };
var documentIdentifier = new VSTextDocumentIdentifier { DocumentUri = uri };

if (projectContext != null)
{
Expand All @@ -140,7 +138,7 @@ private protected static TextDocumentIdentifier CreateTextDocumentIdentifier(Uri
private protected static CodeActionParams CreateCodeActionParams(LSP.Location location)
=> new()
{
TextDocument = CreateTextDocumentIdentifier(location.Uri),
TextDocument = CreateTextDocumentIdentifier(location.DocumentUri),
Range = location.Range,
Context = new CodeActionContext
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ private void WatchedFilesHandler_OnNotificationRaised(object? sender, DidChangeW
{
foreach (var changedFile in e.Changes)
{
var filePath = changedFile.Uri.LocalPath;
var filePath = changedFile.Uri.GetRequiredParsedUri().LocalPath;

// Unfortunately the LSP protocol doesn't give us any hint of which of the file watches we might have sent to the client
// was the one that registered for this change, so we have to check paths to see if this one we should respond to.
Expand Down Expand Up @@ -152,7 +152,7 @@ public IWatchedFile EnqueueWatchingFile(string filePath)
// TODO: figure out how I just can do an absolute path watch
GlobPattern = new RelativePattern
{
BaseUri = ProtocolConversions.CreateAbsoluteUri(Path.GetDirectoryName(filePath)!),
BaseUri = ProtocolConversions.CreateAbsoluteDocumentUri(Path.GetDirectoryName(filePath)!),
Pattern = Path.GetFileName(filePath)
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

using System.Composition;
using Microsoft.CodeAnalysis.Host.Mef;
using Roslyn.LanguageServer.Protocol;
using Roslyn.Utilities;

namespace Microsoft.CodeAnalysis.LanguageServer.Handler.DebugConfiguration;
Expand Down Expand Up @@ -38,9 +39,9 @@ public Task<ProjectDebugConfiguration[]> HandleRequestAsync(WorkspaceDebugConfig
return Task.FromResult(projects);
}

private static bool IsProjectInWorkspace(Uri workspacePath, Project project)
private static bool IsProjectInWorkspace(DocumentUri workspacePath, Project project)
{
return PathUtilities.IsSameDirectoryOrChildOf(project.FilePath!, workspacePath.LocalPath);
return PathUtilities.IsSameDirectoryOrChildOf(project.FilePath!, workspacePath.GetRequiredParsedUri().LocalPath);
}

private ProjectDebugConfiguration GetProjectDebugConfiguration(Project project)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@
namespace Microsoft.CodeAnalysis.LanguageServer.Handler.DebugConfiguration;

internal sealed record WorkspaceDebugConfigurationParams(
[property: JsonPropertyName("workspacePath"), JsonConverter(typeof(DocumentUriConverter))] Uri WorkspacePath);
[property: JsonPropertyName("workspacePath"), JsonConverter(typeof(DocumentUriConverter))] DocumentUri WorkspacePath);
Loading
Loading