-
Notifications
You must be signed in to change notification settings - Fork 53
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
autocomplete entity names in the repl #798
Conversation
src/Swarm/TUI/Controller.hs
Outdated
kwMatches = filter (lastWord `T.isPrefixOf`) possibleWords | ||
|
||
-- checks the "parity" of the number of quotes. If odd, then there is an open quote. | ||
hasOpenQuotes = (== 1) . (`mod` 2) . T.count "\"" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't know if it's worth fixing this, but technically this will break if there are any escaped quote characters in a string literal.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This approach sounds good enough for now. 👍
Realistically, I think complex programs using escaped quotes will be written in the editor, not REPL.
If we add suggestions to the LSP, then we can think about a more robust check.
src/Swarm/TUI/Controller.hs
Outdated
theEntityMap = s ^. gameState . entityMap | ||
entityNames = M.keys $ entitiesByName theEntityMap | ||
lastQuotedString = T.takeWhileEnd (/= '"') t | ||
strMatches = filter (lastQuotedString `T.isPrefixOf`) entityNames |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I feel like this could be nicer if we filtered using some Map function and then got the list of keys.
But maybe that is just useless optimization. 🤷
src/Swarm/TUI/Controller.hs
Outdated
[m] -> CmdPrompt (completeWith lastQuotedString m) [] | ||
(m : ms) -> CmdPrompt (completeWith lastQuotedString m) (ms ++ [m]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I forgot what the idea was with this completing code.
I would expect it to cycle on the suggestions, which makes me wonder why the "one element" and "more element" branches can not be the same.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've added explanatory comments.
556d938
to
2aff6b9
Compare
Code is now cleaned up. Will merge if I get an "Approve". |
2aff6b9
to
419383b
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks great, and thanks for adding the detailed comments!
419383b
to
90fb57a
Compare
No description provided.