Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add option for LSP-based auto insert #75224

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
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 @@ -54,6 +54,7 @@ internal partial class DidChangeConfigurationNotificationHandler
SolutionCrawlerOptionsStorage.CompilerDiagnosticsScopeOption,
LspOptionsStorage.LspEnableReferencesCodeLens,
LspOptionsStorage.LspEnableTestsCodeLens,
LspOptionsStorage.LspEnableAutoInsert,
LanguageServerProjectSystemOptionsStorage.BinaryLogPath,
LanguageServerProjectSystemOptionsStorage.EnableAutomaticRestore,
MetadataAsSourceOptionsStorage.NavigateToSourceLinkAndEmbeddedSources,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ internal sealed class OnAutoInsertHandler(
if (document == null)
return SpecializedTasks.Null<LSP.VSInternalDocumentOnAutoInsertResponseItem>();

var onAutoInsertEnabled = _globalOptions.GetOption(LspOptionsStorage.LspEnableAutoInsert, document.Project.Language);
if (!onAutoInsertEnabled)
return SpecializedTasks.Null<LSP.VSInternalDocumentOnAutoInsertResponseItem>();

var servicesForDocument = _braceCompletionServices.Where(s => s.Metadata.Language == document.Project.Language).SelectAsArray(s => s.Value);
var isRazorRequest = context.ServerKind == WellKnownLspServerKinds.RazorLspServer;
var position = ProtocolConversions.PositionToLinePosition(request.Position);
Expand Down
7 changes: 7 additions & 0 deletions src/LanguageServer/Protocol/LspOptionsStorage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ internal sealed class LspOptionsStorage

private static readonly OptionGroup s_codeLensOptionGroup = new(name: "code_lens", description: "");

private static readonly OptionGroup s_autoInsertOptionGroup = new(name: "auto_insert", description: "");

/// <summary>
/// Flag indicating whether or not references should be returned in LSP codelens.
/// </summary>
Expand All @@ -41,5 +43,10 @@ internal sealed class LspOptionsStorage
/// Flag indicating whether or not test and debug code lens items should be returned.
/// </summary>
public static readonly PerLanguageOption2<bool> LspEnableTestsCodeLens = new("dotnet_enable_tests_code_lens", defaultValue: true, group: s_codeLensOptionGroup);

/// <summary>
/// Flag indicating whether or not auto-insert should be abled by default in LSP.
/// </summary>
public static readonly PerLanguageOption2<bool> LspEnableAutoInsert = new("dotnet_enable_auto_insert", defaultValue: true, group: s_autoInsertOptionGroup);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ public void VerifyLspClientOptionNames()
"background_analysis.dotnet_compiler_diagnostics_scope",
"code_lens.dotnet_enable_references_code_lens",
"code_lens.dotnet_enable_tests_code_lens",
"auto_insert.dotnet_enable_auto_insert",
"projects.dotnet_binary_log_path",
"projects.dotnet_enable_automatic_restore",
"navigation.dotnet_navigate_to_source_link_and_embedded_sources"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,7 @@ public void OptionHasStorageIfNecessary(string configName)
"dotnet_lsp_using_devkit", // VSCode internal only option. Does not need any UI.
"dotnet_enable_references_code_lens", // VSCode only option. Does not apply to VS.
"dotnet_enable_tests_code_lens", // VSCode only option. Does not apply to VS.
"dotnet_enable_auto_insert", // VSCode only option. Does not apply to VS.
"end_of_line", // persisted by the editor
"ExtensionManagerOptions_DisableCrashingExtensions", // TODO: remove? https://github.com/dotnet/roslyn/issues/66063
"FeatureOnOffOptions_RefactoringVerification", // TODO: remove? https://github.com/dotnet/roslyn/issues/66063
Expand Down
Loading