Commit Graph

5031 Commits

Author SHA1 Message Date
Qi Xiao
d844d80ebb Fix format of elvdoc for -source. 2021-01-03 22:36:13 +00:00
Qi Xiao
09b8dcdf2f Handle the global namespace correctly in the -source command.
The -source command now runs with a temporary namespace that is amalgamated
from the local and up namespace of the caller -source; this means that it can
no longer mutate its caller's local scope, which is the only possible sensible
behavior anyway.

This fixes #1202.
2021-01-03 22:31:55 +00:00
Qi Xiao
086038fa0f pkg/eval: Remove (*Evaler).Close. 2021-01-03 20:55:04 +00:00
Qi Xiao
5fbeb781ff pkg/eval: Remove (*Frame).Eval. 2021-01-03 20:54:35 +00:00
Qi Xiao
d140e98f3c Fix definition of recursive functions with fn.
Also document explicitly that the function body may refer to the function being
defined.

This fixes #1206.
2021-01-03 20:44:52 +00:00
Qi Xiao
7932f58201 pkg/eval: Add a (*Evaler).Call method for calling a function.
Most of the places that need to directly call a function is in the edit package,
which need to call user-defined callbacks.

This change eliminates most call sites of NewTopFrame (including all call sites
outside the eval package). Remove the function and inline it in the remaining
few call sites.

Remove NewTopFrame means that the eval package no longer offers other packages
a way to construct Frame instances. This is intended: Frame is a relatively
low-level concept, and all code outside the eval package now uses the more
high-level Eval, Call, Check/CheckTree methods of *Evaler. The most notable
exception is packages that implement modules; they may still use Frame to access
the information kept in it, but they never construct Frame instances.

In future, the Frame type can be changed to an interface.
2021-01-03 18:57:11 +00:00
Qi Xiao
261861888a pkg/eval: Support specifying an alternative global Ns in EvalCfg.
This feature supersedes the CompileWithGlobal method, and simplifies the only
use of that method in pkg/edit, where the default binding is evaluated using the
edit: namespace as the global Ns.
2021-01-03 17:20:56 +00:00
Qi Xiao
9323912c98 pkg/eval: De-export (*Evaler).Compile, and expose a (*Evaler).CheckTree.
The Compile method was used only by the syntax highlighting code to find
compilation errors. Since it only needs the error part but not the Op part,
provide an alternative API that only exposes the error.
2021-01-03 17:05:15 +00:00
Qi Xiao
3f6b5da2b9 pkg/shell: Print both parse and compile errors when using -compileonly -json.
The new (*Evaler).Check method allows the implementation to be simpler.

Also test the JSON format feature in an integration test instead of unit test;
this makes it unnecessary for the eval package to expose NewCompilationError.
2021-01-03 16:32:04 +00:00
Qi Xiao
7663d9a0ce pkg/eval: Replace the NoExecute option of (*Evaler).Eval with a new Check method.
This method has the property that it always tries to compile the code even if
there is a parse failure. This is the more desirable behavior when checking
code: if there is a parse failure near the end of a chunk of code, the user may
like to learn about compile errors earlier in the code.
2021-01-03 16:01:24 +00:00
Kurtis Rader
ad558b1e0d Include cross-package invocations in test coverage
The default behavior of `go test -cover` ignores coverage by integration
tests. That is, it ignores coverage by tests in a different package. This
penalizes Elvish since Elvish has a lot of integration tests that are
meant to indirectly, but explicitly, exercise code in other packages that
do not have explicit unit tests.

This change makes the test coverage more accurate for the purposes of
this project.

Resolves #1062
Resolves #1187
2021-01-03 02:05:44 +00:00
Qi Xiao
2d971d2cd0 pkg/eval: De-export (*Evaler).ParseAndCompile.
All code outside the eval package now uses (*Evaler).Eval to evaluate code, and
do not need this method anymore.
2021-01-02 02:41:36 +00:00
Qi Xiao
5642dc3756 pkg/eval: Test compile-time deprecations using (*Evaler).Eval. 2021-01-02 02:39:38 +00:00
Qi Xiao
e43492ba17 pkg: Move edit.capturePort to eval.CaptureStringPort. 2021-01-02 02:39:03 +00:00
Qi Xiao
f92ae06a04 pkg/edit: In instant mode, use (*Evaler).Eval to evaluate the code.
This avoids the use of the more low-level eval.NewTopFrame call, and is another
step in making (*Evaler).Eval a unified entry point for evaluating code.
2021-01-02 02:24:12 +00:00
Qi Xiao
9b5dc09f14 pkg/eval: In (*Evaler).Eval, replace nil ports with placeholder ports.
This allows callers of this method to only supply the ports it is interested in
setting and leave the rest either unspecified or nil.
2021-01-02 02:22:44 +00:00
Qi Xiao
7cd2745c03 Deflake the test against "sleep" by delaying the SIGINT slightly.
The test contained a race condition: when the mock TimeAfter implementation
sends the process a SIGINT, the "sleep" function may not have entered the
"select" block, meaning that the signal will be ignored.

This commit works around this by waiting 1ms (scaled with
$ELVISH_TEST_TIME_SCALE) before sending SIGINT. The test now consistently
succeeds on my local laptop.
2021-01-02 01:49:40 +00:00
Qi Xiao
4f037aeb2a pkg/eval: Implement output capture in terms of simpler primitives.
Introduces two functions, PipePort and CapturePort, and implement output capture
in terms of them. These two functions return *Port instances, which can also be
used in (*Evaler).Eval calls.
2021-01-02 01:40:04 +00:00
Qi Xiao
dc59cbfeb4 pkg/eval: Make (*Evaler).Eval accept a Source instead of an Op.
Most callers can now call it with the source to evaluate, without having to call
ParseAndCompile first themselves.
2021-01-02 00:10:26 +00:00
Qi Xiao
5f0e4fc196 pkg/eval: Remove the bool return value of GetCompilationError.
This is done for consistency with parse.GetError.
2021-01-01 23:27:11 +00:00
Qi Xiao
7584319b69 pkg/parse: MultiError -> Error; add a GetError function. 2021-01-01 23:19:03 +00:00
Qi Xiao
973a7931de website: Remove link to old Matrix room.
This fixes #1194.
2020-12-29 14:38:38 +00:00
Qi Xiao
e4cebea152 pkg/eval: Simplify the tests for -source by running them in a temp dir. 2020-12-29 13:46:03 +00:00
Qi Xiao
3615988408 Change signature of "exec" and "fg" on Windows to match that on Unix.
This fixes #1195.
2020-12-26 22:59:18 +00:00
Qi Xiao
3e29266ee0 pkg/eval: Remove unused (*Evaler).InstallBundled. 2020-12-26 03:26:10 +00:00
Qi Xiao
719314c029 pkg/eval: Various cleanups for qname handling code. 2020-12-25 22:31:52 +00:00
Qi Xiao
8613527450 pkg/eval: Deduplicate code for command head resolution. 2020-12-25 21:30:57 +00:00
Qi Xiao
41bed735e7 pkg/shell: Install the edit module in the builtin namespace.
Installing it in the global namespace doesn't work, since modules may use the
edit namespace.
2020-12-25 21:01:47 +00:00
Qi Xiao
9a6d53e012 Fix Windows build. 2020-12-25 17:58:03 +00:00
Qi Xiao
6419f4524a Implement namespaces using slices instead of maps.
More related improvements and cleanups will be done in followup commits.

This fixes #1139.
2020-12-25 17:46:46 +00:00
Qi Xiao
09829ae9cd pkg/eval: Update doc of the "not" command. 2020-12-25 17:46:09 +00:00
Qi Xiao
15d69f98ff pkg/ui: Clarify godoc comments for Concat and RConcat implementations. 2020-12-25 17:43:47 +00:00
Kurtis Rader
f94a0ec735 Trivial documentation consistency change
I noticed that most places in the documentation that emit a "note"
about Elvish behavior use `**Note**:`. There were two places that use
all uppercase. Make those consistent with the other uses. Also clarify
the note associated with the `not` builtin.
2020-12-25 17:43:32 +00:00
Kurtis Rader
d52aa03764 In prompts implicitly coerce float64 to string
Including the float64 data type in the prompt value stream causes an error.
This causes those values to be implicitly converted to a string as happens
everywhere else in Elvish.

I initially intended to modify the code to do the implicit string coercion
for any type not otherwise explicitly handled by the pkg/ui `Concat`
methods. I decided against that approach because doing so doesn't make
sense for some types that might appear in the value stream; e.g., Elvish
exceptions.

Fixes #1186
2020-12-25 17:34:49 +00:00
Qi Xiao
2bf7a5d8d1 Apply feedback for PR #1181. 2020-12-25 01:13:19 +00:00
Kurtis Rader
4df5e8e015 Use exported methods to access ports
Commit 734eb95 changed most uses of `fm.ports[x].` to a public method
that makes the intent clearer. This changes a couple of uses that were
overlooked by that prior change.
2020-12-25 01:11:33 +00:00
Kurtis Rader
9c7c9cf7d9 [cleanup] trivial golint suggested changes
As with commit #eb2a792 I acknowledge that `golint` recommendations are
controversial and should not automatically be acted on. Nonetheless,
this change fixes legitimate lint issues such as copy/paste cleanups,
style problems I introduced (`i += 1` versus `i++`) or method/var comments
that are not in the preferred form.
2020-12-25 01:11:33 +00:00
Qi Xiao
bd69facfb2 Add benchmarks for variable access.
Also change the benchmarks to only benchmark eval time, excluding parse and compile.
2020-12-25 00:44:26 +00:00
Qi Xiao
11751f87ac Address feedback in PR #1177. 2020-12-25 00:44:26 +00:00
Kurtis Rader
122ce3b7d1 allow binding to a literal control char
It should be possible to bind a key to a literal control character. For
example, it should be possible to write:

    edit:insert:binding["\e"] = $edit:command:start~

as a logically equivalent alternative to the preferred form:

    edit:insert:binding[Ctrl-'['] = $edit:command:start~

Resolves #1185
2020-12-25 00:39:43 +00:00
Kurtis Rader
3c29912b3f Improve test coverage
I noticed my prior change did not verify that symbolic key name `Ctrl-?`
was equivalent to `Backspace`.
2020-12-25 00:39:43 +00:00
Kurtis Rader
9edcb78050 Make key binding syntax more consistent
Document the format key of names and modifiers; albeit with a TODO
regarding the `Shift` modifier.

Make function key modifier matching case sensitive (`Alt` not `alt`)
to match key name matching (`Enter` not `enter`).

Implement `Ctrl-?` as the logical counterpart to `"\c?"`.

Resolves #1163
2020-12-25 00:39:43 +00:00
Qi Xiao
6f3b8a787b Minor fixup for last commit. 2020-11-07 19:02:44 +00:00
Kurtis Rader
b58b495d77 Fix hang reading value channel from a redirection
Fixes #600
Fixes #1010
2020-11-07 13:52:29 -05:00
Qi Xiao
b11fe9d257 pkg/cli: Treat Ctrl-H the same way as Backspace in CodeArea's default key handler.
This fixes #1178.
2020-11-07 18:44:18 +00:00
Qi Xiao
e919c53c8b Minor fixup for navigation mode. 2020-11-07 18:37:18 +00:00
Kurtis Rader
b5b73c6e3d Address PR feedback regarding testutil.ApplyDir 2020-11-07 13:17:00 -05:00
Kurtis Rader
a943dc764a Improve navigation mode corner cases
There are some Navigation mode corner cases whose current behavior is
surprising. Such as inserting a space before the filename when the space
isn't wanted or redundant. Also, selecting an empty directory and pressing
Enter should insert nothing rather than an empty string.

Fixes #1169
2020-11-07 13:17:00 -05:00
Kurtis Rader
f1baa70a78 Fix the $pwd tests
Not sure what happened but my fix for issue #1120 resulted in the core
unit test module not being executed due to a bogus "// +build wtf"
comment. Apparently I was experimenting with "+build" directives and
forgot to remove that line. This also improves the test coverage of the
$pwd code from 44% to 100%.
2020-10-28 19:36:01 -04:00
Qi Xiao
80208d3972 Remove stale go:generate lines.
This fixes #1175.
2020-10-28 23:12:56 +00:00