From 3f1e2cea77d68354e98ca69d1e32ef3c188cd3ef Mon Sep 17 00:00:00 2001 From: Hendrik Mennen Date: Tue, 30 Jul 2024 14:47:00 +0200 Subject: [PATCH] fix completionlist filtering add setting to turn of snippets for vhdl + verilog --- build/props/AvaloniaEdit.TextMate.props | 2 +- build/props/AvaloniaEdit.props | 2 +- src/OneWare.Core/Styles/Editor.axaml | 2 +- .../EditorExtensions/CompletionData.cs | 14 +++++++------- .../TypeAssistanceLanguageService.cs | 18 ++++++++++++++---- src/OneWare.Verilog/LanguageServiceVerilog.cs | 2 +- src/OneWare.Verilog/TypeAssistanceVerilog.cs | 10 ++++++++-- src/OneWare.Verilog/VerilogModule.cs | 4 ++++ src/OneWare.Vhdl/LanguageServiceVhdl.cs | 2 +- src/OneWare.Vhdl/TypeAssistanceVhdl.cs | 15 ++++++++++++--- src/OneWare.Vhdl/VhdlModule.cs | 4 ++++ 11 files changed, 54 insertions(+), 21 deletions(-) diff --git a/build/props/AvaloniaEdit.TextMate.props b/build/props/AvaloniaEdit.TextMate.props index 3ff10f0d..f2e18e6d 100644 --- a/build/props/AvaloniaEdit.TextMate.props +++ b/build/props/AvaloniaEdit.TextMate.props @@ -1,6 +1,6 @@  - + diff --git a/build/props/AvaloniaEdit.props b/build/props/AvaloniaEdit.props index 0ea4a719..8c206208 100644 --- a/build/props/AvaloniaEdit.props +++ b/build/props/AvaloniaEdit.props @@ -1,6 +1,6 @@  - + diff --git a/src/OneWare.Core/Styles/Editor.axaml b/src/OneWare.Core/Styles/Editor.axaml index d4af0436..d006951d 100644 --- a/src/OneWare.Core/Styles/Editor.axaml +++ b/src/OneWare.Core/Styles/Editor.axaml @@ -47,7 +47,7 @@ Width="{Binding #CompletionName.Bounds.Height}" Height="{Binding #CompletionName.Bounds.Height}" /> 0) + { + var compare = string.Compare(Completion.CompletionList.CompletionData[c].Label, customItem.Label, + StringComparison.Ordinal); + + if (compare > 0) { Completion.CompletionList.CompletionData.Insert(c, customItem); insert = true; break; } - + if (compare == 0) + { + //Do not insert duplicates + insert = true; + break; + } + } + if (!insert) Completion.CompletionList.CompletionData.Add(customItem); } @@ -565,7 +575,7 @@ protected virtual async Task ShowCompletionAsync(CompletionTriggerKind triggerKi var length = 0; foreach (var data in Completion.CompletionList.CompletionData) { - var contentLength = (data.Content as string)?.Length ?? 0; + var contentLength = data.Label.Length; var detailLength = (data as CompletionData)?.Detail?.Length ?? 0; var visibleChars = contentLength + detailLength + 5; diff --git a/src/OneWare.Verilog/LanguageServiceVerilog.cs b/src/OneWare.Verilog/LanguageServiceVerilog.cs index 33e18761..ab7de2ba 100644 --- a/src/OneWare.Verilog/LanguageServiceVerilog.cs +++ b/src/OneWare.Verilog/LanguageServiceVerilog.cs @@ -15,7 +15,7 @@ public class LanguageServiceVerilog(string workspace, ISettingsService settingsS { public override ITypeAssistance GetTypeAssistance(IEditor editor) { - return new TypeAssistanceVerilog(editor, this); + return new TypeAssistanceVerilog(editor, this, settingsService); } protected override IEnumerable ConvertErrors(PublishDiagnosticsParams pdp, IFile file) diff --git a/src/OneWare.Verilog/TypeAssistanceVerilog.cs b/src/OneWare.Verilog/TypeAssistanceVerilog.cs index c343630c..a19e3a3b 100644 --- a/src/OneWare.Verilog/TypeAssistanceVerilog.cs +++ b/src/OneWare.Verilog/TypeAssistanceVerilog.cs @@ -3,6 +3,7 @@ using OneWare.Essentials.EditorExtensions; using OneWare.Essentials.Helpers; using OneWare.Essentials.LanguageService; +using OneWare.Essentials.Services; using OneWare.Essentials.ViewModels; using OneWare.Verilog.Folding; @@ -10,10 +11,13 @@ namespace OneWare.Verilog; internal class TypeAssistanceVerilog : TypeAssistanceLanguageService { + private readonly ISettingsService _settingsService; private static List? _snippets; - public TypeAssistanceVerilog(IEditor editor, LanguageServiceVerilog ls) : base(editor, ls) + public TypeAssistanceVerilog(IEditor editor, LanguageServiceVerilog ls, ISettingsService settingsService) : base(editor, ls) { + _settingsService = settingsService; + CodeBox.TextArea.IndentationStrategy = IndentationStrategy = new LspIndentationStrategy(CodeBox.Options, ls, CurrentFile); FoldingStrategy = new RegexFoldingStrategy(FoldingRegexVerilog.FoldingStart, FoldingRegexVerilog.FoldingEnd); @@ -29,10 +33,12 @@ protected override Task> GetCustomCompletionItemsAsync() if (IsInComment(CodeBox.CaretOffset)) return Task.FromResult(items); - if (_snippets != null) + if (_settingsService.GetSettingValue(VerilogModule.EnableSnippetsSetting) && _snippets != null) + { items.AddRange(_snippets.Select(snippet => new CompletionData(snippet.Content, snippet.Label, null, snippet.Description, TypeAssistanceIconStore.Instance.Icons[CompletionItemKind.Snippet], 0, CodeBox.CaretOffset))); + } return Task.FromResult(items); } diff --git a/src/OneWare.Verilog/VerilogModule.cs b/src/OneWare.Verilog/VerilogModule.cs index 543805a5..1496ad63 100644 --- a/src/OneWare.Verilog/VerilogModule.cs +++ b/src/OneWare.Verilog/VerilogModule.cs @@ -13,6 +13,7 @@ public class VerilogModule : IModule { public const string LspName = "Verible"; public const string LspPathSetting = "VerilogModule_VeriblePath"; + public const string EnableSnippetsSetting = "VerilogModule_EnableSnippets"; public static readonly Package VeriblePackage = new() { @@ -157,6 +158,9 @@ public void OnInitialized(IContainerProvider containerProvider) containerProvider.Resolve().RegisterTitledFilePath("Languages", "Verilog", LspPathSetting, "Verible Path", "Path for Verible executable", "", null, containerProvider.Resolve().PackagesDirectory, File.Exists, PlatformHelper.ExeFile); + + containerProvider.Resolve().RegisterTitled("Languages", "Verilog", EnableSnippetsSetting, + "Enable Snippets", "Enable snippets that provide rich completion. These are not smart or context based.", true); containerProvider.Resolve().RegisterErrorSource(LspName); containerProvider.Resolve().RegisterTextMateLanguage("verilog", diff --git a/src/OneWare.Vhdl/LanguageServiceVhdl.cs b/src/OneWare.Vhdl/LanguageServiceVhdl.cs index 553ccffe..c90e8f0c 100644 --- a/src/OneWare.Vhdl/LanguageServiceVhdl.cs +++ b/src/OneWare.Vhdl/LanguageServiceVhdl.cs @@ -15,7 +15,7 @@ public class LanguageServiceVhdl(string workspace, ISettingsService settingsServ { public override ITypeAssistance GetTypeAssistance(IEditor editor) { - return new TypeAssistanceVhdl(editor, this); + return new TypeAssistanceVhdl(editor, this, settingsService); } protected override IEnumerable ConvertErrors(PublishDiagnosticsParams pdp, IFile file) diff --git a/src/OneWare.Vhdl/TypeAssistanceVhdl.cs b/src/OneWare.Vhdl/TypeAssistanceVhdl.cs index 088f9ee0..4b13f025 100644 --- a/src/OneWare.Vhdl/TypeAssistanceVhdl.cs +++ b/src/OneWare.Vhdl/TypeAssistanceVhdl.cs @@ -3,7 +3,9 @@ using OneWare.Essentials.EditorExtensions; using OneWare.Essentials.Helpers; using OneWare.Essentials.LanguageService; +using OneWare.Essentials.Services; using OneWare.Essentials.ViewModels; +using OneWare.Settings; using OneWare.Vhdl.Folding; using OneWare.Vhdl.Formatting; using OneWare.Vhdl.Indentation; @@ -14,7 +16,10 @@ internal class TypeAssistanceVhdl : TypeAssistanceLanguageService { private static List? _snippets; - public TypeAssistanceVhdl(IEditor editor, LanguageServiceVhdl ls) : base(editor, ls) + private readonly ISettingsService _settingsService; + + public TypeAssistanceVhdl(IEditor editor, LanguageServiceVhdl ls, ISettingsService settingsService) : base(editor, + ls) { CodeBox.TextArea.IndentationStrategy = IndentationStrategy = new VhdlIndentationStrategy(CodeBox.Options); FormattingStrategy = new VhdlFormatter(); @@ -22,6 +27,8 @@ public TypeAssistanceVhdl(IEditor editor, LanguageServiceVhdl ls) : base(editor, LineCommentSequence = "--"; _snippets ??= TextMateSnippetHelper.ParseVsCodeSnippets("avares://OneWare.Vhdl/Assets/vhdl.json"); + + _settingsService = settingsService; } protected override Task ShowCompletionAsync(CompletionTriggerKind triggerKind, string? triggerChar) @@ -35,11 +42,13 @@ protected override Task> GetCustomCompletionItemsAsync() { var items = new List(); - if (_snippets != null) + if (_settingsService.GetSettingValue(VhdlModule.EnableSnippetsSetting) && _snippets != null) + { items.AddRange(_snippets.Select(snippet => new CompletionData(snippet.Content, snippet.Label, null, snippet.Description, TypeAssistanceIconStore.Instance.Icons[CompletionItemKind.Snippet], 0, CodeBox.CaretOffset))); - + } + return Task.FromResult(items); } diff --git a/src/OneWare.Vhdl/VhdlModule.cs b/src/OneWare.Vhdl/VhdlModule.cs index fa5215f2..e282dc11 100644 --- a/src/OneWare.Vhdl/VhdlModule.cs +++ b/src/OneWare.Vhdl/VhdlModule.cs @@ -13,6 +13,7 @@ public class VhdlModule : IModule { public const string LspName = "RustHDL"; public const string LspPathSetting = "VhdlModule_RustHdlPath"; + public const string EnableSnippetsSetting = "VhdlModule_EnableSnippets"; public static readonly Package RustHdlPackage = new() { @@ -154,6 +155,9 @@ public void OnInitialized(IContainerProvider containerProvider) containerProvider.Resolve().RegisterTitledFilePath("Languages", "VHDL", LspPathSetting, "RustHDL Path", "Path for RustHDL executable", "", null, containerProvider.Resolve().PackagesDirectory, File.Exists, PlatformHelper.ExeFile); + + containerProvider.Resolve().RegisterTitled("Languages", "VHDL", EnableSnippetsSetting, + "Enable Snippets", "Enable snippets that provide rich completion. These are not smart or context based.", true); containerProvider.Resolve().RegisterErrorSource(LspName); containerProvider.Resolve().RegisterTextMateLanguage("vhdl",