Skip to content

Commit

Permalink
Re-rework LspEditorFeatureDetector
Browse files Browse the repository at this point in the history
My previous work on LspEditorFeatureDetector introduced a significant regression by removing the code that checked project capabilities. When a razor document is opened, the LspEditorFeatureDetector is queried to see if the LSP editor is enabled (i.e. the user hasn't enabled the legacy editor instead), and to see whether the project that the document belongs to supports the LSP editor. In the case of .NET Framework projects, the LSP editor can't ever be used, and my prior change broke that. (Many thanks to @alexgav for fixing my mistake!)

Giving the situation a bit more thought, I've reworked LspEditorFeatureDetector again to simplify the code and fix a different issue where we would start checking project capabilities where we hadn't before.
  • Loading branch information
DustinCampbell committed Jul 1, 2024
1 parent 47e4957 commit 6cd5bd4
Show file tree
Hide file tree
Showing 15 changed files with 223 additions and 289 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ public void SuppressDocument(ProjectKey projectKey, string documentFilePath)
throw new ArgumentNullException(nameof(documentFilePath));
}

if (_lspEditorFeatureDetector.IsLspEditorEnabledAndAvailable(documentFilePath))
if (_lspEditorFeatureDetector.IsLspEditorEnabled())
{
return;
}
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,16 @@ namespace Microsoft.VisualStudio.Razor;

internal interface ILspEditorFeatureDetector
{
bool IsLspEditorEnabledAndAvailable(string documentFilePath);
/// <summary>
/// Determines whether the LSP editor is enabled. This returns <see langword="true"/>
/// if the legacy editor has <i>not</i> been enabled via the feature flag or tools/options.
/// </summary>
bool IsLspEditorEnabled();

/// <summary>
/// Determines whether the LSP editor is supported by the given document.
/// </summary>
bool IsLspEditorSupported(string documentFilePath);

/// <summary>
/// A remote client is a LiveShare guest or a Codespaces instance
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,8 @@ namespace Microsoft.VisualStudio.Razor;

internal interface IProjectCapabilityResolver
{
bool HasCapability(string documentFilePath, object project, string capability);
/// <summary>
/// Determines whether the project associated with the specified document has the given <paramref name="capability"/>.
/// </summary>
bool ResolveCapability(string capability, string documentFilePath);
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,10 @@ namespace Microsoft.VisualStudio.Razor.LanguageClient;
[FileExtension(RazorLSPConstants.CSHTMLFileExtension)]
[Name(nameof(CSHTMLFilePathToContentTypeProvider))]
[Export(typeof(IFilePathToContentTypeProvider))]
internal class CSHTMLFilePathToContentTypeProvider : RazorFilePathToContentTypeProviderBase
[method: ImportingConstructor]
internal class CSHTMLFilePathToContentTypeProvider(
IContentTypeRegistryService contentTypeRegistryService,
ILspEditorFeatureDetector lspEditorFeatureDetector)
: RazorFilePathToContentTypeProviderBase(contentTypeRegistryService, lspEditorFeatureDetector)
{
[ImportingConstructor]
public CSHTMLFilePathToContentTypeProvider(
IContentTypeRegistryService contentTypeRegistryService,
ILspEditorFeatureDetector lspEditorFeatureDetector) : base(contentTypeRegistryService, lspEditorFeatureDetector)
{
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,10 @@ namespace Microsoft.VisualStudio.Razor.LanguageClient;
[FileExtension(RazorLSPConstants.RazorFileExtension)]
[Name(nameof(RazorFilePathToContentTypeProvider))]
[Export(typeof(IFilePathToContentTypeProvider))]
internal class RazorFilePathToContentTypeProvider : RazorFilePathToContentTypeProviderBase
[method: ImportingConstructor]
internal class RazorFilePathToContentTypeProvider(
IContentTypeRegistryService contentTypeRegistryService,
ILspEditorFeatureDetector lspEditorFeatureDetector)
: RazorFilePathToContentTypeProviderBase(contentTypeRegistryService, lspEditorFeatureDetector)
{
[ImportingConstructor]
public RazorFilePathToContentTypeProvider(
IContentTypeRegistryService contentTypeRegistryService,
ILspEditorFeatureDetector lspEditorFeatureDetector) : base(contentTypeRegistryService, lspEditorFeatureDetector)
{
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the MIT license. See License.txt in the project root for license information.

using System;
using System.Diagnostics.CodeAnalysis;
using Microsoft.VisualStudio.Utilities;

Expand All @@ -16,23 +15,14 @@ public RazorFilePathToContentTypeProviderBase(
IContentTypeRegistryService contentTypeRegistryService,
ILspEditorFeatureDetector lspEditorFeatureDetector)
{
if (contentTypeRegistryService is null)
{
throw new ArgumentNullException(nameof(contentTypeRegistryService));
}

if (lspEditorFeatureDetector is null)
{
throw new ArgumentNullException(nameof(lspEditorFeatureDetector));
}

_contentTypeRegistryService = contentTypeRegistryService;
_lspEditorFeatureDetector = lspEditorFeatureDetector;
}

public bool TryGetContentTypeForFilePath(string filePath, [NotNullWhen(true)] out IContentType? contentType)
{
if (_lspEditorFeatureDetector.IsLspEditorEnabledAndAvailable(filePath))
if (_lspEditorFeatureDetector.IsLspEditorEnabled() &&
_lspEditorFeatureDetector.IsLspEditorSupported(filePath))
{
contentType = _contentTypeRegistryService.GetContentType(RazorConstants.RazorLSPContentTypeName);
return true;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the MIT license. See License.txt in the project root for license information.

using System.Diagnostics.CodeAnalysis;
using Microsoft.VisualStudio.LiveShare;

namespace Microsoft.VisualStudio.Razor.LiveShare.Guest;

internal interface ILiveShareSessionAccessor
{
CollaborationSession? Session { get; }

[MemberNotNullWhen(true, nameof(Session))]
bool IsGuestSessionActive { get; }
}

This file was deleted.

Loading

0 comments on commit 6cd5bd4

Please sign in to comment.