-
Notifications
You must be signed in to change notification settings - Fork 109
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
Add completions to REPL #407
Conversation
I added |
Apparently it is impossible not to inser the but I did sort out |
src/dex.hs
Outdated
else [] | ||
return (rest, filteredCompletions candidates $ reverse word) | ||
|
||
dexCompletions = completeQuotedWord (Just '\\') "\"'" listFiles completions |
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.
Probably all of the above should be in another file. idk where though
src/dex.hs
Outdated
env <- get | ||
let varNames = map (show . pretty) $ envNames env | ||
-- note: line and thus word and rest have character order reversed | ||
let (word, rest) = break (== ' ') line |
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.
Possibly other whitespace should be allowed
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.
Nice, this looks sweet!
src/dex.hs
Outdated
dexCompletions = completeQuotedWord (Just '\\') "\"'" listFiles completions | ||
|
||
hasklineSettings :: Settings (StateT TopEnv IO) | ||
hasklineSettings = setComplete dexCompletions defaultSettings |
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.
nit: small local definitions like this one (or dexCompletions
) are usually better placed in the where
clauses of the functions that use them (in this caserunMode
).
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.
It seems like if i do that it is too far away from where it is used.
So I have put it side that ReplMode
case
Let's just clean up the formatting a little and this is going to be good to merge! |
src/dex.hs
Outdated
let anywhereKeywords = ["def", "for", "rof", "case", "data", "where", "of", "if", "then", "else", "interface", "instance", "do", "view"] | ||
let startoflineKeywords = ["%bench \"", ":p", ":t", ":html", ":export"] | ||
let candidates = varNames ++ anywhereKeywords ++ | ||
if null rest then startoflineKeywords else [] |
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 is quite minor, but ++
has complexity proportional to the size of the lhs, so it is usually better to sort the concatenated lists according to increasing length. This concatenates them in the complete reverse order, which is the worst case scenario.
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.
TIL, it's an actual linked list i guess
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.
Yup, Haskell lists are linked lists. If you want a contiguous arrays you have to use Data.Vector
(which is a packed array of boxed values; if you want to go unboxed there are Data.Vector.Unboxed
types).
This adds completions to the REPL, both of language keywords and of currently defined top level names;
as well as restricting filename completions to only happen within a quoted string.
Shown is me pressing tab at the end of each line.
A follow up PR would add globally inscope variables to this. I think it would not be too hard, though I don't think I will work out out anytime soon. There is discussion in [this Reddit thread](https://www.reddit.com/r/haskell/comments/1os0yq/haskeline_woes/) about how to dynamically update the list of completions for HasklineIt also would be good to add other things like
:p
and:html
filtered to only be allowed occur at line start