Skip to content
This repository was archived by the owner on Nov 2, 2022. It is now read-only.

Commit 2f34b16

Browse files
committed
Insert valid yarnspinner text on keyword completion (ie "if" instead of "COMMAND_IF")
1 parent b55670b commit 2f34b16

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

LanguageServer/src/Server/Handlers/CompletionHandler.cs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -57,11 +57,13 @@ public Task<CompletionList> Handle(CompletionParams request, CancellationToken c
5757
var vocabulary = yarnFile.Parser.Vocabulary;
5858
foreach (var token in candidates.Tokens)
5959
{
60-
var label = vocabulary.GetSymbolicName(token.Key);
61-
if (label == null) { continue; } // unrecognized token
60+
var tokenname = vocabulary.GetSymbolicName(token.Key);
61+
62+
if (tokenname == null) { continue; } // unrecognized token
63+
64+
var label = UserFriendlyTokenText.GetValueOrDefault(tokenname, tokenname);
65+
var text = TokenSnippets.GetValueOrDefault(tokenname, label);
6266

63-
var text = TokenSnippets.GetValueOrDefault(label, label);
64-
label = UserFriendlyTokenText.GetValueOrDefault(label, label);
6567
results.Add(new CompletionItem
6668
{
6769
Label = label,
@@ -225,8 +227,8 @@ public Task<CompletionList> Handle(CompletionParams request, CancellationToken c
225227

226228
public static readonly Dictionary<string, string> UserFriendlyTokenText = new Dictionary<string, string>
227229
{
228-
{ "COMMAND_IF", "if" }, { "COMMAND_ELSEIF", "elseif" }, { "COMMAND_ELSE", "else" }, { "COMMAND_SET", "set" },
229-
{ "COMMAND_ENDIF", "endif" }, { "COMMAND_CALL", "call" }, { "COMMAND_DECLARE", "declare" }, { "COMMAND_JUMP", "jump" },
230+
{ "COMMAND_IF", "if " }, { "COMMAND_ELSEIF", "elseif " }, { "COMMAND_ELSE", "else" }, { "COMMAND_SET", "set " },
231+
{ "COMMAND_ENDIF", "endif" }, { "COMMAND_CALL", "call " }, { "COMMAND_DECLARE", "declare " }, { "COMMAND_JUMP", "jump " },
230232
{ "KEYWORD_FALSE", "false" }, { "KEYWORD_TRUE", "true" }, { "KEYWORD_NULL", "null" },
231233
};
232234

0 commit comments

Comments
 (0)