Skip to content

Control language service availability using project capabilities #8502

@drewnoakes

Description

@drewnoakes

Currently we use ILanguageServiceHostEnvironment to control whether the language service should be initialized or not.

[Export(typeof(ILanguageServiceHostEnvironment))]
internal sealed class LanguageServiceHostEnvironment : ILanguageServiceHostEnvironment
{
private readonly AsyncLazy<bool> _isEnabled;
[ImportingConstructor]
public LanguageServiceHostEnvironment(IVsUIService<SVsShell, IVsShell> vsShell, JoinableTaskContext joinableTaskContext)
{
_isEnabled = new(
async () =>
{
await joinableTaskContext.Factory.SwitchToMainThreadAsync();
// If VS is running in command line mode (e.g. "devenv.exe /build my.sln"),
// the language service host is not enabled.
return ErrorHandler.Succeeded(vsShell.Value.GetProperty((int)__VSSPROPID.VSSPROPID_IsInCommandLineMode, out object resultObj))
&& resultObj is bool result
&& !result; // negate: enabled when not in command line mode
},
joinableTaskContext.Factory);
}
public Task<bool> IsEnabledAsync(CancellationToken cancellationToken) => _isEnabled.GetValueAsync(cancellationToken);
}

Today, we use this interface to prevent the language service from doing redundant work during devenv /build.

The current design requires calling code to check this flag. It would be cleaner to control this via project capabilities.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Feature-Language-ServicePopulating the Roslyn workspace with references, source files, analyzers, etcTriage-ApprovedReviewed and prioritized

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions