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
2 changes: 1 addition & 1 deletion eng/Signing.props
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@
<ItemGroup>
<FileSignInfo Include="Newtonsoft.Json.dll" CertificateName="3PartySHA2" />
<FileSignInfo Include="MediatR.dll" CertificateName="3PartySHA2" />
<FileSignInfo Include="MediatR.Extensions.Microsoft.DependencyInjection.dll" CertificateName="3PartySHA2" />
<FileSignInfo Include="OmniSharp.Extensions.JsonRpc.dll" CertificateName="3PartySHA2" />
<FileSignInfo Include="OmniSharp.Extensions.LanguageProtocol.dll" CertificateName="3PartySHA2" />
<FileSignInfo Include="OmniSharp.Extensions.LanguageServer.dll" CertificateName="3PartySHA2" />
<FileSignInfo Include="OmniSharp.Extensions.LanguageServer.Shared.dll" CertificateName="3PartySHA2" />
</ItemGroup>

<ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion eng/Versions.props
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@
<MoqPackageVersion>4.10.0</MoqPackageVersion>
<!-- STOP!!! We need to reference the version of JSON that our HOSTS supprt. -->
<NewtonsoftJsonPackageVersion>12.0.2</NewtonsoftJsonPackageVersion>
<OmniSharpExtensionsLanguageServerPackageVersion>0.14.2</OmniSharpExtensionsLanguageServerPackageVersion>
<OmniSharpExtensionsLanguageServerPackageVersion>0.18.0-beta0081</OmniSharpExtensionsLanguageServerPackageVersion>
<OmniSharpMSBuildPackageVersion>1.33.0</OmniSharpMSBuildPackageVersion>
<SystemPrivateUriPackageVersion>4.3.2</SystemPrivateUriPackageVersion>
<SystemCompositionPackageVersion>1.0.31.0</SystemCompositionPackageVersion>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,19 @@ public static class LanguageServerConstants
{
public const string ProjectConfigurationFile = "project.razor.json";

public const string RazorSemanticTokensEndpoint = "textDocument/semanticTokens";
// Semantic "Legacy" endpoints refer to an old LSP spec version, needed for now until VS reacts.
public const string LegacyRazorSemanticTokensEndpoint = "textDocument/semanticTokens";

public const string RazorSemanticTokensEditEndpoint = "textDocument/semanticTokens/edits";
public const string LegacyRazorSemanticTokensEditEndpoint = "textDocument/semanticTokens/edits";

public const string RazorSemanticTokensRangeEndpoint = "textDocument/semanticTokens/range";
public const string LegacyRazorSemanticTokensRangeEndpoint = "textDocument/semanticTokens/range";

public const string RazorSemanticTokensLegendEndpoint = "_ms_/textDocument/semanticTokensLegend";

public const string RazorSemanticTokensEditEndpoint = "textDocument/semanticTokens/full/delta";

public const string RazorSemanticTokensEndpoint = "textDocument/semanticTokens/full";

public const string SemanticTokensProviderName = "semanticTokensProvider";

public const string RazorRangeFormattingEndpoint = "razor/rangeFormatting";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@
using Microsoft.CodeAnalysis.Razor.Workspaces;
using Microsoft.CodeAnalysis.Text;
using OmniSharp.Extensions.LanguageServer.Protocol.Client.Capabilities;
using OmniSharp.Extensions.LanguageServer.Protocol.Document;
using OmniSharp.Extensions.LanguageServer.Protocol.Models;
using OmniSharp.Extensions.LanguageServer.Protocol.Server;
using LanguageServerInstance = OmniSharp.Extensions.LanguageServer.Server.LanguageServer;

namespace Microsoft.AspNetCore.Razor.LanguageServer.CodeActions
{
Expand All @@ -25,8 +25,8 @@ internal class CodeActionEndpoint : ICodeActionHandler
private readonly IEnumerable<RazorCodeActionProvider> _providers;
private readonly ForegroundDispatcher _foregroundDispatcher;
private readonly DocumentResolver _documentResolver;
private readonly ILanguageServer _languageServer;
private readonly LanguageServerFeatureOptions _languageServerFeatureOptions;
private readonly IClientLanguageServer _languageServer;

private CodeActionCapability _capability;

Expand All @@ -36,7 +36,7 @@ public CodeActionEndpoint(
IEnumerable<RazorCodeActionProvider> providers,
ForegroundDispatcher foregroundDispatcher,
DocumentResolver documentResolver,
ILanguageServer languageServer,
IClientLanguageServer languageServer,
LanguageServerFeatureOptions languageServerFeatureOptions)
{
_providers = providers ?? throw new ArgumentNullException(nameof(providers));
Expand All @@ -63,8 +63,7 @@ public void SetCapability(CodeActionCapability capability)
{
_capability = capability;

var languageServerInstance = _languageServer as LanguageServerInstance;
var extendableClientCapabilities = languageServerInstance?.ClientSettings?.Capabilities as ExtendableClientCapabilities;
var extendableClientCapabilities = _languageServer.ClientSettings?.Capabilities as ExtendableClientCapabilities;
_supportsCodeActionResolve = extendableClientCapabilities?.SupportsCodeActionResolve ?? false;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
using Microsoft.AspNetCore.Razor.LanguageServer.Common;
using Microsoft.CodeAnalysis.Razor;
using Microsoft.VisualStudio.Editor.Razor;
using OmniSharp.Extensions.LanguageServer.Protocol;
using OmniSharp.Extensions.LanguageServer.Protocol.Models;

namespace Microsoft.AspNetCore.Razor.LanguageServer.CodeActions
Expand Down Expand Up @@ -216,7 +217,7 @@ private static WorkspaceEdit CreateRenameTagEdit(RazorCodeActionContext context,

return new WorkspaceEdit
{
Changes = new Dictionary<Uri, IEnumerable<TextEdit>> {
Changes = new Dictionary<DocumentUri, IEnumerable<TextEdit>> {
[context.Request.TextDocument.Uri] = changes,
}
};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

using System;
using OmniSharp.Extensions.LanguageServer.Protocol;

namespace Microsoft.AspNetCore.Razor.LanguageServer.CodeActions.Models
{
internal sealed class AddUsingsCodeActionParams
{
public Uri Uri { get; set; }
public DocumentUri Uri { get; set; }
public string Namespace { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

using System;
using OmniSharp.Extensions.LanguageServer.Protocol;

namespace Microsoft.AspNetCore.Razor.LanguageServer.CodeActions.Models
{
internal sealed class CreateComponentCodeActionParams
{
public Uri Uri { get; set; }
public DocumentUri Uri { get; set; }
public string Path { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

using System;
using OmniSharp.Extensions.LanguageServer.Protocol;

namespace Microsoft.AspNetCore.Razor.LanguageServer.CodeActions.Models
{
internal sealed class ExtractToCodeBehindCodeActionParams
{
public Uri Uri { get; set; }
public DocumentUri Uri { get; set; }
public int ExtractStart { get; set; }
public int ExtractEnd { get; set; }
public int RemoveStart { get; set; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
using System.Text.RegularExpressions;
using Microsoft.CodeAnalysis.Razor.Completion;
using OmniSharp.Extensions.LanguageServer.Protocol.Models;
using OmniSharp.Extensions.LanguageServer.Server;
using OmniSharp.Extensions.LanguageServer.Protocol.Server;
using RazorAttributeDescriptionInfo = Microsoft.CodeAnalysis.Razor.Completion.AttributeDescriptionInfo;

namespace Microsoft.AspNetCore.Razor.LanguageServer.Completion
Expand Down Expand Up @@ -36,17 +36,21 @@ internal class DefaultTagHelperDescriptionFactory : TagHelperDescriptionFactory
[typeof(decimal).FullName] = "decimal",
};

public DefaultTagHelperDescriptionFactory(ILanguageServer languageServer)
private readonly Lazy<ILanguageServer> _server;

// Need to have a lazy server here because if we try to resolve the server it creates types which create a DefaultTagHelperDescriptionFactory, and we end up StackOverflowing.
// This lazy can be avoided in the future by using an upcoming ILanguageServerSettings interface, but it doesn't exist/work yet.
public DefaultTagHelperDescriptionFactory(Lazy<ILanguageServer> languageServer)
{
if (languageServer is null)
{
throw new NotImplementedException(nameof(languageServer));
}

LanguageServer = languageServer;
_server = languageServer;
}

public ILanguageServer LanguageServer { get; }
public ILanguageServer LanguageServer => _server.Value;

public override bool TryCreateDescription(ElementDescriptionInfo elementDescriptionInfo, out MarkupContent tagHelperDescription)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
using Microsoft.CodeAnalysis.Text;
using Microsoft.Extensions.Logging;
using OmniSharp.Extensions.LanguageServer.Protocol.Client.Capabilities;
using OmniSharp.Extensions.LanguageServer.Protocol.Document;
using OmniSharp.Extensions.LanguageServer.Protocol.Models;
using OmniSharp.Extensions.LanguageServer.Protocol.Server;

namespace Microsoft.AspNetCore.Razor.LanguageServer.Completion
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,13 @@ public DefaultDocumentVersionCache(ForegroundDispatcher foregroundDispatcher)
_documentLookup = new Dictionary<string, List<DocumentEntry>>(FilePathComparer.Instance);
}

public override void TrackDocumentVersion(DocumentSnapshot documentSnapshot, long version)
public override void TrackDocumentVersion(DocumentSnapshot documentSnapshot, int version)
{
if (documentSnapshot == null)
{
throw new ArgumentNullException(nameof(documentSnapshot));
}

if (version < 0)
{
throw new ArgumentOutOfRangeException(nameof(version));
}

_foregroundDispatcher.AssertForegroundThread();

if (!_documentLookup.TryGetValue(documentSnapshot.FilePath, out var documentEntries))
Expand All @@ -61,7 +56,7 @@ public override void TrackDocumentVersion(DocumentSnapshot documentSnapshot, lon
documentEntries.Add(entry);
}

public override bool TryGetDocumentVersion(DocumentSnapshot documentSnapshot, out long version)
public override bool TryGetDocumentVersion(DocumentSnapshot documentSnapshot, out int? version)
{
if (documentSnapshot == null)
{
Expand All @@ -72,7 +67,7 @@ public override bool TryGetDocumentVersion(DocumentSnapshot documentSnapshot, ou

if (!_documentLookup.TryGetValue(documentSnapshot.FilePath, out var documentEntries))
{
version = -1;
version = null;
return false;
}

Expand All @@ -90,7 +85,7 @@ public override bool TryGetDocumentVersion(DocumentSnapshot documentSnapshot, ou

if (entry == null)
{
version = -1;
version = null;
return false;
}

Expand Down Expand Up @@ -146,15 +141,15 @@ internal void MarkAsLatestVersion(DocumentSnapshot document)
}

// Update our internal tracking state to track the changed document as the latest document.
TrackDocumentVersion(document, latestVersion);
TrackDocumentVersion(document, latestVersion.Value);
}

// Internal for testing
internal bool TryGetLatestVersionFromPath(string filePath, out long version)
internal bool TryGetLatestVersionFromPath(string filePath, out int? version)
{
if (!_documentLookup.TryGetValue(filePath, out var documentEntries))
{
version = -1;
version = null;
return false;
}

Expand All @@ -178,15 +173,15 @@ private void CaptureProjectDocumentsAsLatest(ProjectSnapshot projectSnapshot)

internal class DocumentEntry
{
public DocumentEntry(DocumentSnapshot document, long version)
public DocumentEntry(DocumentSnapshot document, int version)
{
Document = new WeakReference<DocumentSnapshot>(document);
Version = version;
}

public WeakReference<DocumentSnapshot> Document { get; }

public long Version { get; }
public int Version { get; }
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -103,11 +103,12 @@ private GeneratedDocumentContainer Create(string filePath)
return;
}

if (!_documentVersionCache.TryGetDocumentVersion(latestDocument, out var hostDocumentVersion))
if (!_documentVersionCache.TryGetDocumentVersion(latestDocument, out var nullableHostDocumentVersion))
{
// Cache entry doesn't exist, document most likely was evicted from the cache/too old.
return;
}
var hostDocumentVersion = nullableHostDocumentVersion.Value;

_generatedDocumentPublisher.PublishCSharp(filePath, args.NewText, hostDocumentVersion);
}, CancellationToken.None, TaskCreationOptions.None, _foregroundDispatcher.ForegroundScheduler);
Expand All @@ -127,11 +128,12 @@ private GeneratedDocumentContainer Create(string filePath)
return;
}

if (!_documentVersionCache.TryGetDocumentVersion(latestDocument, out var hostDocumentVersion))
if (!_documentVersionCache.TryGetDocumentVersion(latestDocument, out var nullableHostDocumentVersion))
{
// Cache entry doesn't exist, document most likely was evicted from the cache/too old.
return;
}
var hostDocumentVersion = nullableHostDocumentVersion.Value;

_generatedDocumentPublisher.PublishHtml(filePath, args.NewText, hostDocumentVersion);
}, CancellationToken.None, TaskCreationOptions.None, _foregroundDispatcher.ForegroundScheduler);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Threading;
using Microsoft.AspNetCore.Razor.LanguageServer.Common;
using Microsoft.CodeAnalysis.Razor;
using Microsoft.CodeAnalysis.Razor.ProjectSystem;
Expand Down Expand Up @@ -46,7 +47,7 @@ public override void Initialize(ProjectSnapshotManagerBase projectManager)
_projectSnapshotManager.Changed += ProjectSnapshotManager_Changed;
}

public override void PublishCSharp(string filePath, SourceText sourceText, long hostDocumentVersion)
public override void PublishCSharp(string filePath, SourceText sourceText, int hostDocumentVersion)
{
if (filePath is null)
{
Expand Down Expand Up @@ -81,10 +82,12 @@ public override void PublishCSharp(string filePath, SourceText sourceText, long
HostDocumentVersion = hostDocumentVersion,
};

_server.Value.Client.SendRequest(LanguageServerConstants.RazorUpdateCSharpBufferEndpoint, request);
var result = _server.Value.Client.SendRequest(LanguageServerConstants.RazorUpdateCSharpBufferEndpoint, request);
// This is the call that actually makes the request, any SendRequest without a .Returning* after it will do nothing.
result.ReturningVoid(CancellationToken.None);
}

public override void PublishHtml(string filePath, SourceText sourceText, long hostDocumentVersion)
public override void PublishHtml(string filePath, SourceText sourceText, int hostDocumentVersion)
{
if (filePath is null)
{
Expand Down Expand Up @@ -119,7 +122,8 @@ public override void PublishHtml(string filePath, SourceText sourceText, long ho
HostDocumentVersion = hostDocumentVersion,
};

_server.Value.Client.SendRequest(LanguageServerConstants.RazorUpdateHtmlBufferEndpoint, request);
var result = _server.Value.Client.SendRequest(LanguageServerConstants.RazorUpdateHtmlBufferEndpoint, request);
result.ReturningVoid(CancellationToken.None);
}

private void ProjectSnapshotManager_Changed(object sender, ProjectChangeEventArgs args)
Expand Down Expand Up @@ -149,17 +153,17 @@ private void ProjectSnapshotManager_Changed(object sender, ProjectChangeEventArg

private sealed class PublishData
{
public static readonly PublishData Default = new PublishData(SourceText.From(string.Empty), -1);
public static readonly PublishData Default = new PublishData(SourceText.From(string.Empty), null);

public PublishData(SourceText sourceText, long hostDocumentVersion)
public PublishData(SourceText sourceText, int? hostDocumentVersion)
{
SourceText = sourceText;
HostDocumentVersion = hostDocumentVersion;
}

public SourceText SourceText { get; }

public long HostDocumentVersion { get; }
public int? HostDocumentVersion { get; }
}
}
}
Loading