-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This adds basic completion of keys in the REPL scope (including global scope). There might be bugs here, but it seems to work fairly well in basic cases.
- Loading branch information
Showing
6 changed files
with
99 additions
and
19 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
using Antlr4.Runtime; | ||
using Colibri.Core; | ||
using PrettyPrompt.Completion; | ||
|
||
namespace Colibri.PromptConfig; | ||
|
||
public static class PromptCompletions | ||
{ | ||
public static IReadOnlyList<CompletionItem> GetCompletionItems( | ||
ColibriRuntime runtime, | ||
string text, | ||
int caret) | ||
{ | ||
// HACK.PI: this code is _highly_ inefficient | ||
var keys = runtime.UserScope.FlattenAllKeys(); | ||
var lexer = new ColibriLexer(new AntlrInputStream(text)); | ||
|
||
var tokens = lexer.GetAllTokens(); | ||
|
||
if (tokens.Count > 0) | ||
{ | ||
var lastToken = tokens[^1]; | ||
var lastTokenText = lastToken.Text; | ||
|
||
if (lastToken.Type == ColibriLexer.IDENTIFIER) | ||
{ | ||
keys = keys.Where(i => i.StartsWith(lastTokenText)); | ||
} | ||
} | ||
|
||
return keys.Select(i => new CompletionItem(i)).ToList(); | ||
} | ||
} |
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