Skip to content

Commit

Permalink
fix completionlist filtering
Browse files Browse the repository at this point in the history
add setting to turn of snippets for vhdl + verilog
  • Loading branch information
HendrikMennen committed Jul 30, 2024
1 parent 2a0536f commit 3f1e2ce
Show file tree
Hide file tree
Showing 11 changed files with 54 additions and 21 deletions.
2 changes: 1 addition & 1 deletion build/props/AvaloniaEdit.TextMate.props
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<PackageReference Include="OneWare.AvaloniaEdit.TextMate" Version="11.1.0"/>
<PackageReference Include="OneWare.AvaloniaEdit.TextMate" Version="11.1.0.2"/>
</ItemGroup>
</Project>
2 changes: 1 addition & 1 deletion build/props/AvaloniaEdit.props
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<PackageReference Include="OneWare.AvaloniaEdit" Version="11.1.0"/>
<PackageReference Include="OneWare.AvaloniaEdit" Version="11.1.0.2"/>
</ItemGroup>
</Project>
2 changes: 1 addition & 1 deletion src/OneWare.Core/Styles/Editor.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
Width="{Binding #CompletionName.Bounds.Height}"
Height="{Binding #CompletionName.Bounds.Height}" />
<TextBlock VerticalAlignment="Center" Padding="0" Name="CompletionName"
Margin="8,0,0,0" Text="{Binding Content}"
Margin="8,0,0,0" Text="{Binding Label}"
Foreground="{DynamicResource ThemeForegroundBrush}" />
</StackPanel>
<TextBlock Grid.Column="2" Text="{Binding Detail}"
Expand Down
14 changes: 7 additions & 7 deletions src/OneWare.Essentials/EditorExtensions/CompletionData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ public CompletionData(string insertText, string label, string? detail, string? d
double priority,
CompletionItem completionItem, int offset, Action? afterCompletion = null)
{
Text = insertText;
Content = label;
InsertText = insertText;
Label = label;
Detail = detail;
Description = description;
Image = icon;
Expand All @@ -30,8 +30,8 @@ public CompletionData(string insertText, string label, string? detail, string? d
public CompletionData(string insertText, string label, string? detail, string? description, IImage? icon,
double priority, int offset, Action? afterCompletion = null)
{
Text = insertText;
Content = label;
InsertText = insertText;
Label = label;
Detail = detail;
Description = description;
Image = icon;
Expand All @@ -48,9 +48,9 @@ public CompletionData(string insertText, string label, string? detail, string? d

public IImage? Image { get; }

public string Text { get; }
public string InsertText { get; }

public object Content { get; }
public string Label { get; }

public object? Description { get; }

Expand All @@ -64,7 +64,7 @@ public void Complete(TextArea textArea, ISegment completionSegment, EventArgs in

var newLine = TextUtilities.GetNewLineFromDocument(textArea.Document, segmentLine.LineNumber);

var formattedText = Text.Replace("\r", "").Replace("\n", newLine)
var formattedText = InsertText.Replace("\r", "").Replace("\n", newLine)
.Replace("\t", textArea.Options.IndentationString);

var filteredText = formattedText!;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -550,22 +550,32 @@ protected virtual async Task ShowCompletionAsync(CompletionTriggerKind triggerKi
{
var insert = false;
for (var c = 0; c < Completion.CompletionList.CompletionData.Count; c++)
if (string.Compare(Completion.CompletionList.CompletionData[c].Text, customItem.Text,
StringComparison.Ordinal) > 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);
}

//Calculate CompletionWindow width
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;
Expand Down
2 changes: 1 addition & 1 deletion src/OneWare.Verilog/LanguageServiceVerilog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<ErrorListItem> ConvertErrors(PublishDiagnosticsParams pdp, IFile file)
Expand Down
10 changes: 8 additions & 2 deletions src/OneWare.Verilog/TypeAssistanceVerilog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,21 @@
using OneWare.Essentials.EditorExtensions;
using OneWare.Essentials.Helpers;
using OneWare.Essentials.LanguageService;
using OneWare.Essentials.Services;
using OneWare.Essentials.ViewModels;
using OneWare.Verilog.Folding;

namespace OneWare.Verilog;

internal class TypeAssistanceVerilog : TypeAssistanceLanguageService
{
private readonly ISettingsService _settingsService;
private static List<TextMateSnippet>? _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);
Expand All @@ -29,10 +33,12 @@ protected override Task<List<CompletionData>> GetCustomCompletionItemsAsync()

if (IsInComment(CodeBox.CaretOffset)) return Task.FromResult(items);

if (_snippets != null)
if (_settingsService.GetSettingValue<bool>(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);
}
Expand Down
4 changes: 4 additions & 0 deletions src/OneWare.Verilog/VerilogModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
{
Expand Down Expand Up @@ -157,6 +158,9 @@ public void OnInitialized(IContainerProvider containerProvider)
containerProvider.Resolve<ISettingsService>().RegisterTitledFilePath("Languages", "Verilog", LspPathSetting,
"Verible Path", "Path for Verible executable", "",
null, containerProvider.Resolve<IPaths>().PackagesDirectory, File.Exists, PlatformHelper.ExeFile);

containerProvider.Resolve<ISettingsService>().RegisterTitled("Languages", "Verilog", EnableSnippetsSetting,
"Enable Snippets", "Enable snippets that provide rich completion. These are not smart or context based.", true);

containerProvider.Resolve<IErrorService>().RegisterErrorSource(LspName);
containerProvider.Resolve<ILanguageManager>().RegisterTextMateLanguage("verilog",
Expand Down
2 changes: 1 addition & 1 deletion src/OneWare.Vhdl/LanguageServiceVhdl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<ErrorListItem> ConvertErrors(PublishDiagnosticsParams pdp, IFile file)
Expand Down
15 changes: 12 additions & 3 deletions src/OneWare.Vhdl/TypeAssistanceVhdl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -14,14 +16,19 @@ internal class TypeAssistanceVhdl : TypeAssistanceLanguageService
{
private static List<TextMateSnippet>? _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();
FoldingStrategy = new RegexFoldingStrategy(FoldingRegexVhdl.FoldingStart, FoldingRegexVhdl.FoldingEnd);
LineCommentSequence = "--";

_snippets ??= TextMateSnippetHelper.ParseVsCodeSnippets("avares://OneWare.Vhdl/Assets/vhdl.json");

_settingsService = settingsService;
}

protected override Task ShowCompletionAsync(CompletionTriggerKind triggerKind, string? triggerChar)
Expand All @@ -35,11 +42,13 @@ protected override Task<List<CompletionData>> GetCustomCompletionItemsAsync()
{
var items = new List<CompletionData>();

if (_snippets != null)
if (_settingsService.GetSettingValue<bool>(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);
}

Expand Down
4 changes: 4 additions & 0 deletions src/OneWare.Vhdl/VhdlModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
{
Expand Down Expand Up @@ -154,6 +155,9 @@ public void OnInitialized(IContainerProvider containerProvider)
containerProvider.Resolve<ISettingsService>().RegisterTitledFilePath("Languages", "VHDL", LspPathSetting,
"RustHDL Path", "Path for RustHDL executable", "",
null, containerProvider.Resolve<IPaths>().PackagesDirectory, File.Exists, PlatformHelper.ExeFile);

containerProvider.Resolve<ISettingsService>().RegisterTitled("Languages", "VHDL", EnableSnippetsSetting,
"Enable Snippets", "Enable snippets that provide rich completion. These are not smart or context based.", true);

containerProvider.Resolve<IErrorService>().RegisterErrorSource(LspName);
containerProvider.Resolve<ILanguageManager>().RegisterTextMateLanguage("vhdl",
Expand Down

0 comments on commit 3f1e2ce

Please sign in to comment.