Skip to content

Commit 361a0a8

Browse files
authored
Add option for LSP-based auto insert (#75224)
* add auto insert option * fix naming * add option group * fix tests * fix name
1 parent d80afa8 commit 361a0a8

File tree

5 files changed

+14
-0
lines changed

5 files changed

+14
-0
lines changed

src/LanguageServer/Protocol/Handler/Configuration/DidChangeConfigurationNotificationHandler_OptionList.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ internal partial class DidChangeConfigurationNotificationHandler
5454
SolutionCrawlerOptionsStorage.CompilerDiagnosticsScopeOption,
5555
LspOptionsStorage.LspEnableReferencesCodeLens,
5656
LspOptionsStorage.LspEnableTestsCodeLens,
57+
LspOptionsStorage.LspEnableAutoInsert,
5758
LanguageServerProjectSystemOptionsStorage.BinaryLogPath,
5859
LanguageServerProjectSystemOptionsStorage.EnableAutomaticRestore,
5960
MetadataAsSourceOptionsStorage.NavigateToSourceLinkAndEmbeddedSources,

src/LanguageServer/Protocol/Handler/OnAutoInsert/OnAutoInsertHandler.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,10 @@ internal sealed class OnAutoInsertHandler(
5050
if (document == null)
5151
return SpecializedTasks.Null<LSP.VSInternalDocumentOnAutoInsertResponseItem>();
5252

53+
var onAutoInsertEnabled = _globalOptions.GetOption(LspOptionsStorage.LspEnableAutoInsert, document.Project.Language);
54+
if (!onAutoInsertEnabled)
55+
return SpecializedTasks.Null<LSP.VSInternalDocumentOnAutoInsertResponseItem>();
56+
5357
var servicesForDocument = _braceCompletionServices.Where(s => s.Metadata.Language == document.Project.Language).SelectAsArray(s => s.Value);
5458
var isRazorRequest = context.ServerKind == WellKnownLspServerKinds.RazorLspServer;
5559
var position = ProtocolConversions.PositionToLinePosition(request.Position);

src/LanguageServer/Protocol/LspOptionsStorage.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ internal sealed class LspOptionsStorage
3232

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

35+
private static readonly OptionGroup s_autoInsertOptionGroup = new(name: "auto_insert", description: "");
36+
3537
/// <summary>
3638
/// Flag indicating whether or not references should be returned in LSP codelens.
3739
/// </summary>
@@ -41,5 +43,10 @@ internal sealed class LspOptionsStorage
4143
/// Flag indicating whether or not test and debug code lens items should be returned.
4244
/// </summary>
4345
public static readonly PerLanguageOption2<bool> LspEnableTestsCodeLens = new("dotnet_enable_tests_code_lens", defaultValue: true, group: s_codeLensOptionGroup);
46+
47+
/// <summary>
48+
/// Flag indicating whether or not auto-insert should be abled by default in LSP.
49+
/// </summary>
50+
public static readonly PerLanguageOption2<bool> LspEnableAutoInsert = new("dotnet_enable_auto_insert", defaultValue: true, group: s_autoInsertOptionGroup);
4451
}
4552
}

src/LanguageServer/ProtocolUnitTests/Configuration/DidChangeConfigurationNotificationHandlerTest.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,7 @@ public void VerifyLspClientOptionNames()
144144
"background_analysis.dotnet_compiler_diagnostics_scope",
145145
"code_lens.dotnet_enable_references_code_lens",
146146
"code_lens.dotnet_enable_tests_code_lens",
147+
"auto_insert.dotnet_enable_auto_insert",
147148
"projects.dotnet_binary_log_path",
148149
"projects.dotnet_enable_automatic_restore",
149150
"navigation.dotnet_navigate_to_source_link_and_embedded_sources"

src/VisualStudio/Core/Test.Next/Options/VisualStudioOptionStorageTests.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,7 @@ public void OptionHasStorageIfNecessary(string configName)
230230
"dotnet_lsp_using_devkit", // VSCode internal only option. Does not need any UI.
231231
"dotnet_enable_references_code_lens", // VSCode only option. Does not apply to VS.
232232
"dotnet_enable_tests_code_lens", // VSCode only option. Does not apply to VS.
233+
"dotnet_enable_auto_insert", // VSCode only option. Does not apply to VS.
233234
"end_of_line", // persisted by the editor
234235
"ExtensionManagerOptions_DisableCrashingExtensions", // TODO: remove? https://github.com/dotnet/roslyn/issues/66063
235236
"FeatureOnOffOptions_RefactoringVerification", // TODO: remove? https://github.com/dotnet/roslyn/issues/66063

0 commit comments

Comments
 (0)