This commit makes error messages when the native messenger is
unavailable easier to read. Since they're easier to read, there's no
need for custom errors in setclip/getclip anymore, provided that the
errors they throw are correctly logged. In order to make sure of that,
we remove the try/catch in excmds.ts:clipboard(), which should let
errors bubble up as needed.
I also noticed that while {set,get}Clipboard relied on the command line
being focused in order to work, they didn't do that themselves and
instead expected their callers to have set things up. This didn't make
sense to me so I moved the focusing code inside of {set,get}Clipboard.
This was all done while chasing the elusive #1135 but probably doesn't
change anything about it.
Before this commit, keyEvents was never reset. This caused weird issues
like control closing the commandline after a first ex command had been
accepted. We now reset keyEvents in two places ; when an ex command is
accepted (which could happen when inserting a completion, for example)
and when the command line is closed (which could be triggered by an
outside event).
We re-use the ex-command parser in order to enable rebinding keys in
command-line mode. Command-line manipulation is re-implemented using
previously-abstracter editor commands.
The commandline_frame document does not have a window.tri object. This
makes the commandline throw an exception on page load. We fix this by
using 'window.tri || {}' in order to avoid to avoid issues should
'window.tri' be defined in the command line one day.
The help completion source provides completions for settings, excmds,
aliases and bindings, sorted in lexicographical order. It's basically a
huge copy-paste of the Settings and Excmd completion sources but should
be enough until we have a way to provide multiple completion sources for
a single excmd.
Because of the await in the input handler, exceptions that are thrown
for previous computations will be thrown for the current one too, even
if there's no reason for it to go wrong. We fix this by surrounding the
await keyword with a try/catch and simply logging the error.
This commit makes completions a bit less slow by making sure that the
previous completion round finished before starting a new one. The
optimal thing to do here would be to interrupt previous computations and
starting new ones right off the bat but this doesn't seem possible with
the current JS APIs.
Complete a circular buffer so we don't log too much data, config
settings for turning it on and off (default off, becuase performance)
and for changing the size of the buffer, an excmd for dumping the raw
json so you can pore over it, and for when you just want to
sanity-check yourself instead of groveling over your data for six days
with a deep learning toolkit and three hundred CPUs of compute, an
excmd for pretty-printing your stats in a nice histogram.
I didn't think far enough ahead and only implemented the easy way to
instrument a function, which is with a decorator. I'm getting _really_
angry at typescript not being able to handle decorators on free
functions. bah. I'll figure out a good way to wrap free
functions. Maybe just go the stupid route and make you change
`export async function foo(args)` to `export foo = measured(async
function(args) ...`. But that would break excmd parsing, so... :/
I think that I already want to do a refactor to break excmd.ts into a
bunch of one-line wrappers referencing implementations spread
throughout a bunch of libraries. This would go nicely with that.
Other things I did while I was here:
* Fix the ugliness we had with (window as any).tri by monkey-patching
the tri property into the window object in tridactyl.d.ts
As mentioned in https://github.com/cmcaine/tridactyl/issues/912, there
was a problem with aliases preventing some excmd completion options from
being displayed. For example, `b` would be expanded to `buffer` in the
command line completion mechanism and thus prevent `back` from being
displayed.
This commit fixes that by treating aliases as "real" excmds when
building completion sources. Basically, we check for aliases to the
prefixes given as CompletionSource parameter and add them to the list of
prefixes that can trigger the completion source.
We use this opportunity to remove the constraint of having to add a
space to each prefix, they're instead automatically added by the
CompletionSource constructor.
This implements excmd completion. We're using the typescript compiler
API in order to get the documentation and the type of every function of
Tridactyl and generate a file named "src/metadata.ts" which contains
this information. Since this file is dependency-less it can be imported
from every source file.
We then write a regular completion source which just uses the data
contained in metadata.ts in order to generate its completions.
I don't quite understand how it worked at all without focusing the commandline first.
Peppered code with some more awaits as part of debugging and couldn't be bothered to test which were necessary.