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

Fix autocompletion hint for toolshed strings #5584

Open
wants to merge 3 commits into
base: master
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
2 changes: 1 addition & 1 deletion RELEASE-NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ END TEMPLATE-->

### New features

*None yet*
* Console completion options now have a new flags for preventing suggestions from being escaped or quoted.

### Bugfixes

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -276,10 +276,14 @@ private void CompletionKeyDown(GUIBoundKeyEventArgs args)
// This means that letter casing will match the completion suggestion.
CommandBar.CursorPosition = lastRange.end;
CommandBar.SelectionStart = lastRange.start;
var insertValue = CommandParsing.Escape(completion);

var insertValue = (completionFlags & CompletionOptionFlags.NoEscape) == 0
? CommandParsing.Escape(completion)
: completion;

// If the replacement contains a space, we must quote it to treat it as a single argument.
var mustQuote = insertValue.Contains(' ');
var mustQuote = (completionFlags & CompletionOptionFlags.NoQuote) == 0 && insertValue.Contains(' ');

if ((completionFlags & CompletionOptionFlags.PartialCompletion) == 0)
{
if (mustQuote)
Expand Down
11 changes: 11 additions & 0 deletions Robust.Shared/Console/CompletionResult.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Robust.Shared.Utility;

namespace Robust.Shared.Console;

Expand Down Expand Up @@ -74,4 +75,14 @@ public enum CompletionOptionFlags
/// (instead of adding a space to go to the next one).
/// </summary>
PartialCompletion = 1 << 0,

/// <summary>
/// Prevents suggestions containing spaces from being automatically wrapped in quotes.
/// </summary>
NoQuote = 1 << 1,

/// <summary>
/// Prevents suggestions from being escaped using <see cref="CommandParsing.Escape"/>.
/// </summary>
NoEscape = 1 << 2,
}
4 changes: 2 additions & 2 deletions Robust.Shared/Toolshed/TypeParsers/StringTypeParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ namespace Robust.Shared.Toolshed.TypeParsers;

internal sealed class StringTypeParser : TypeParser<string>
{
// Completion option for hinting that all strings must start with an quote
private static readonly CompletionOption[] Option = [new("\"", Flags: CompletionOptionFlags.PartialCompletion)];
// Completion option for hinting that all strings must start with a quote
private static readonly CompletionOption[] Option = [new("\"", Flags: CompletionOptionFlags.PartialCompletion | CompletionOptionFlags.NoEscape)];

public override bool TryParse(ParserContext ctx, [NotNullWhen(true)] out string? result)
{
Expand Down
Loading