-
Notifications
You must be signed in to change notification settings - Fork 409
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Toolshed tweaks * oops * Apply suggestions from code review Co-authored-by: Moony <[email protected]> * Re-add NotImplementedException * Move error message --------- Co-authored-by: Moony <[email protected]> Co-authored-by: metalgearsloth <[email protected]>
- Loading branch information
1 parent
df0945f
commit b4c1618
Showing
10 changed files
with
111 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
using System.Diagnostics; | ||
using System.Diagnostics.CodeAnalysis; | ||
using System.Threading.Tasks; | ||
using Robust.Shared.Console; | ||
using Robust.Shared.IoC; | ||
using Robust.Shared.Localization; | ||
using Robust.Shared.Maths; | ||
using Robust.Shared.Player; | ||
using Robust.Shared.Toolshed.Errors; | ||
using Robust.Shared.Toolshed.Syntax; | ||
using Robust.Shared.Utility; | ||
|
||
namespace Robust.Shared.Toolshed.TypeParsers; | ||
|
||
/// <summary> | ||
/// Parse a username to an <see cref="ICommonSession"/> | ||
/// </summary> | ||
internal sealed class SessionTypeParser : TypeParser<ICommonSession> | ||
{ | ||
[Dependency] private ISharedPlayerManager _player = default!; | ||
|
||
public override bool TryParse(ParserContext parser, [NotNullWhen(true)] out object? result, out IConError? error) | ||
{ | ||
var start = parser.Index; | ||
var word = parser.GetWord(); | ||
error = null; | ||
result = null; | ||
|
||
if (word == null) | ||
{ | ||
error = new OutOfInputError(); | ||
return false; | ||
} | ||
|
||
if (_player.TryGetSessionByUsername(word, out var session)) | ||
{ | ||
result = session; | ||
return true; | ||
} | ||
|
||
error = new InvalidUsername(Loc, word); | ||
error.Contextualize(parser.Input, (start, parser.Index)); | ||
return false; | ||
} | ||
|
||
public override async ValueTask<(CompletionResult? result, IConError? error)> TryAutocomplete(ParserContext parserContext, | ||
string? argName) | ||
{ | ||
var opts = CompletionHelper.SessionNames(true, _player); | ||
return (CompletionResult.FromHintOptions(opts, "<player session>"), null); | ||
} | ||
|
||
public record InvalidUsername(ILocalizationManager Loc, string Username) : IConError | ||
{ | ||
public FormattedMessage DescribeInner() | ||
{ | ||
return FormattedMessage.FromMarkup(Loc.GetString("cmd-parse-failure-session", ("username", Username))); | ||
} | ||
|
||
public string? Expression { get; set; } | ||
public Vector2i? IssueSpan { get; set; } | ||
public StackTrace? Trace { get; set; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters