Browse Source

Support for type-based completions without tags

pull/165/head
Ionite 1 year ago
parent
commit
f825d5312f
No known key found for this signature in database
  1. 17
      StabilityMatrix.Avalonia/Behaviors/TextEditorCompletionBehavior.cs
  2. 2
      StabilityMatrix.Avalonia/DesignData/MockCompletionProvider.cs
  3. 14
      StabilityMatrix.Avalonia/Models/TagCompletion/CompletionProvider.cs
  4. 12
      StabilityMatrix.Avalonia/Models/TagCompletion/CompletionType.cs
  5. 4
      StabilityMatrix.Avalonia/Models/TagCompletion/ICompletionProvider.cs

17
StabilityMatrix.Avalonia/Behaviors/TextEditorCompletionBehavior.cs

@ -100,9 +100,9 @@ public class TextEditorCompletionBehavior : Behavior<TextEditor>
{
Logger.ConditionalTrace($"Text entered: {e.Text.ToRepr()}");
if (!IsEnabled || CompletionProvider?.IsLoaded != true)
if (!IsEnabled || CompletionProvider is null)
{
Logger.ConditionalTrace("Skipping, not enabled or not loaded");
Logger.ConditionalTrace("Skipping, not enabled");
return;
}
@ -141,7 +141,18 @@ public class TextEditorCompletionBehavior : Behavior<TextEditor>
// Get the segment of the token the caret is currently in
if (GetCaretCompletionToken() is not { } completionRequest)
{
Logger.Trace("Token segment not found");
Logger.ConditionalTrace("Token segment not found");
return;
}
// If type is not available, skip
if (!CompletionProvider.AvailableCompletionTypes.HasFlag(completionRequest.Type))
{
Logger.ConditionalTrace(
"Skipping, completion type {CompletionType} not available in {AvailableTypes}",
completionRequest.Type,
CompletionProvider.AvailableCompletionTypes
);
return;
}

2
StabilityMatrix.Avalonia/DesignData/MockCompletionProvider.cs

@ -10,7 +10,7 @@ namespace StabilityMatrix.Avalonia.DesignData;
public class MockCompletionProvider : ICompletionProvider
{
/// <inheritdoc />
public bool IsLoaded => false;
public CompletionType AvailableCompletionTypes { get; set; }
/// <inheritdoc />
public Func<ICompletionData, string>? PrepareInsertionText { get; } = data => data.Text;

14
StabilityMatrix.Avalonia/Models/TagCompletion/CompletionProvider.cs

@ -42,7 +42,19 @@ public partial class CompletionProvider : ICompletionProvider
private InMemoryIndexSearcher? searcher;
public bool IsLoaded => searcher is not null;
/// <inheritdoc />
public CompletionType AvailableCompletionTypes
{
get
{
var types = CompletionType.ExtraNetwork | CompletionType.ExtraNetworkType;
if (searcher is not null)
{
types |= CompletionType.Tag;
}
return types;
}
}
public Func<ICompletionData, string>? PrepareInsertionText { get; }

12
StabilityMatrix.Avalonia/Models/TagCompletion/CompletionType.cs

@ -1,11 +1,15 @@
namespace StabilityMatrix.Avalonia.Models.TagCompletion;
using System;
namespace StabilityMatrix.Avalonia.Models.TagCompletion;
/// <summary>
/// Type of completion requested.
/// </summary>
[Flags]
public enum CompletionType
{
Tag,
ExtraNetwork,
ExtraNetworkType
None = 0,
Tag = 1 << 1,
ExtraNetwork = 1 << 2,
ExtraNetworkType = 1 << 3
}

4
StabilityMatrix.Avalonia/Models/TagCompletion/ICompletionProvider.cs

@ -9,9 +9,9 @@ namespace StabilityMatrix.Avalonia.Models.TagCompletion;
public interface ICompletionProvider
{
/// <summary>
/// Whether the completion provider is loaded.
/// Currently available completion types.
/// </summary>
bool IsLoaded { get; }
CompletionType AvailableCompletionTypes { get; }
/// <summary>
/// Optional function to transform the text to be inserted

Loading…
Cancel
Save