Commit Graph

54 Commits

Author SHA1 Message Date
Herlon Aguiar
dd1d9b7623
nu-cli/completions: completion for use and source (#5210)
* nu-cli/completions: completion for use and source

* handle subfolders for different base dirs

* fix clippy errors
2022-04-19 00:59:13 +12:00
Tomoki Aonuma
c17129a92a
Fix env capture (#5205)
* Fix env capture

* Add test for env capture
2022-04-16 10:38:27 +12:00
Yutaro Ohno
210d25f2a0
Add into duration (#4683)
* Add `into duration` command

* Avoid using unwrap()

* Use existing logic to parse duration strings
2022-03-03 08:16:04 -05:00
JT
25712760ba
Add support for math-like externals (#4606) 2022-02-22 10:55:28 -05:00
JT
56b3fc61a3
Remove statements, replaced by pipelines (#4482) 2022-02-15 14:31:14 -05:00
JT
a16e485cce
Add support for defining known externals with their own custom completions (#4425)
* WIP for known externals

* Now completions can work from scripts

* Add support for definiing externs

* finish cleaning up old proof-of-concept
2022-02-11 13:38:10 -05:00
JT
e6db37bc82
Fix multi-command variable captures (#4413) 2022-02-10 18:15:15 -05:00
JT
d70d91e559 Remove old nushell/merge engine-q 2022-02-07 14:54:06 -05:00
Fernando Herrera
fdce6c49ab engine-q merge 2022-02-07 19:11:34 +00:00
JT
83ec374995
Add -c flag and others to cmdline args (#853)
* Add -c flag and others to cmdline args

* finish a little bit of cleanup

* Oops, forgot file
2022-01-26 12:26:43 -05:00
JT
8ee619954d
Start support for commandline args to nu itself (#851)
* cmdline args wip

* WIP

* redirect working

* Add help and examples

* Only show flags in signature of more than help
2022-01-27 01:42:39 +11:00
Jakub Žádník
52dba91e1a
Wrap captured env var names into quotes as well (#546) 2021-12-21 23:31:30 +02:00
JT
bee7ef21eb
Add in variable and sub-command completions (#480)
* WIP

* wip

* Add in variable and subcommand completions

* clippy
2021-12-13 10:18:31 +11:00
Fernando Herrera
f3c8d35eb7
Plugin repeated (#417)
* not repeated decl in file and help

* implemented heashmap for repeated

* sorted scope commands
2021-12-03 14:29:55 +00:00
JT
14a2918bba
Fix some nightly clippy warnings (#329) 2021-11-13 13:42:13 +13:00
Fernando Herrera
12eed1f98a plugin feature flag 2021-11-02 20:56:00 +00:00
Fernando Herrera
a390f66dbf call and response serializers 2021-10-31 08:17:01 +00:00
JT
d29208dd9e WIP 2021-10-26 09:04:23 +13:00
JT
abb0d7bd22 Add support for module imports 2021-09-27 07:39:19 +13:00
Fernando Herrera
f7a19d37c6 one parser function 2021-09-06 21:41:30 +01:00
JT
94687a7603 Back to working state 2021-09-03 06:21:37 +12:00
JT
e1be8f61fc WIP 2021-09-02 20:25:22 +12:00
JT
3d252a9797 Add nu-protocol 2021-09-02 13:29:43 +12:00
Markus Westerlind
1c1c58e802
Remove duplicate dependencies (#3961)
* chore: Replace surf with reqwest

Removes a lot of older, duplication versions of some dependencies
(roughtly 90 dependencies removed in total)

* chore: Remove syn 0.11

* chore: Remove unnecessary features from ptree

Removes some more duplicate dependencies

* cargo update

* Ensure we run the fetch and post plugins on the tokio runtime

* Fix clippy warning

* fix: Github requires a user agent on requests

Co-authored-by: Darren Schroeder <343840+fdncred@users.noreply.github.com>
2021-08-28 15:34:11 +12:00
JT
2f43cc353b Fix some expects, add subcommand alias 2021-08-17 11:00:00 +12:00
JT
1355a5dd33 refactor to subcrates 2021-08-11 06:51:08 +12:00
JT
93b5f3f421
Make lexing configurable wrt newlines (#3682) 2021-06-25 17:50:24 +12:00
Andrés N. Robalino
03c9eaf005
Variable completions. (#3666)
In Nu we have variables (E.g. $var-name) and these contain `Value` types.
This means we can bind to variables any structured data and column path syntax
(E.g. `$variable.path.to`) allows flexibility for "querying" said structures.

Here we offer completions for these. For example, in a Nushell session the
variable `$nu` contains environment values among other things. If we wanted to
see in the screen some environment variable (say the var `SHELL`) we do:

```
> echo $nu.env.SHELL
```

with completions we can now do: `echo $nu.env.S[\TAB]` and we get suggestions
that start at the column path `$nu.env` with vars starting with the letter `S`
in this case `SHELL` appears in the suggestions.
2021-06-23 19:21:39 +12:00
Niklas Jonsson
a8f6a13239
Move path handling to nu-path (#3653)
* fixes #3616
2021-06-20 11:07:26 +12:00
Andrés N. Robalino
6fdfc84904
Parse key=value named flag support. (#3515) 2021-05-29 20:42:03 -05:00
WatsonThink
0795d56c1c
Source path including tilda (#3059)
* Use expand_path to handle the path including tilda

* Publish path::expand_path for using in nu-command

* cargo fmt

Co-authored-by: Wataru Yamaguchi <nagisamark2@gmail.com>
2021-02-15 21:41:49 +13:00
Michael Angerman
011b7c4a07
refactor parser: rename method pub fn block to parse_block (#3047)
* refactor parser: rename method block to parse_block

* nu-cli/src/completion/engine.rs block to parse_block
2021-02-13 09:31:11 +13:00
Leonhard Kipp
ef4e3f907c
parser/refactor def (#2986)
* Move tests into own file

* Move data structs to own file

* Move functions parsing 1 Token (primitives) into own file

* Rename param_flag_list to signature

* Add tests

* Fix clippy lint

* Change imports to new lexer structure
2021-02-08 08:10:14 +13:00
Yehuda Katz
d07789677f
Clean up lexer (#2956)
* Document the lexer and lightly improve its names

The bulk of this pull request adds a substantial amount of new inline
documentation for the lexer. Along the way, I made a few minor changes
to the names in the lexer, most of which were internal.

The main change that affects other files is renaming `group` to `block`,
since the function is actually parsing a block (a list of groups).

* Further clean up the lexer

- Consolidate the logic of the various token builders into a single type
- Improve and clean up the event-driven BlockParser
- Clean up comment parsing. Comments now contain their original leading
  whitespace as well as trailing whitespace, and know how to move some
  leading whitespace back into the body based on how the lexer decides
  to dedent the comments. This preserves the original whitespace
  information while still making it straight-forward to eliminate leading
  whitespace in help comments.

* Update meta.rs

* WIP

* fix clippy

* remove unwraps

* remove unwraps

Co-authored-by: Jonathan Turner <jonathandturner@users.noreply.github.com>
Co-authored-by: Jonathan Turner <jonathan.d.turner@gmail.com>
2021-02-04 20:20:21 +13:00
Leonhard Kipp
3e6e3a207c
Feature/def signature with comments (#2905)
* Put parse_definition related funcs into own module

* Add failing lexer test

* Implement Parsing of definition signature

This commit applied changes how the signature of a function is parsed. Before
there was a little bit of "quick-and-dirty" string-matching/parsing involved.
Now, a signature is a little bit more properly parsed.
The grammar of a definition signature understood by these parsing-functions is
as follows:
 `[ (parameter | flag | <eol>)* ]`
where
parameter is:
    `name (<:> type)? (<,> | <eol> | (#Comment <eol>))?`
flag is:
    `--name (-shortform)? (<:> type)? (<,> | <eol> | (#Comment <eol>))?`
(Note: After the last item no <,> has to come.)
Note: It is now possible to pass comments to flags and parameters
Example:
[
  d:int          # The required d parameter
  --x (-x):string # The all powerful x flag
  --y (-y):int    # The accompanying y flag
]

(Sadly there seems to be a bug (Or is this expected behaviour?) in the lexer, because of which `--x(-x)` would
be treated as one baseline token and is therefore not correctly recognized as 2. For
now a space has to be inserted)

During the implementation of the module, 2 question arose:
Should flag/parameter names be allowed to be type names?
Example case:
```shell
def f [ string ] { echo $string }
```
Currently an error is thrown

* Fix clippy lints

* Remove wrong comment

* Add spacing

* Add Cargo.lock
2021-01-12 06:53:58 +13:00
Yehuda Katz
f410fb6689
Document lexer (#2865)
* Update dependencies

* Document the lexer and lightly improve its names

The bulk of this pull request adds a substantial amount of new inline
documentation for the lexer. Along the way, I made a few minor changes
to the names in the lexer, most of which were internal.

The main change that affects other files is renaming `group` to `block`,
since the function is actually parsing a block (a list of groups).

* Fix rustfmt

* Update lock

Co-authored-by: Jonathan Turner <jonathandturner@users.noreply.github.com>
Co-authored-by: Jonathan Turner <jonathan.d.turner@gmail.com>
2021-01-07 16:03:00 +13:00
Jonathan Turner
ac578b8491
Multiline scripts part 2 (#2795)
* Begin allowing comments and multiline scripts.

* clippy

* Finish moving to groups. Test pass

* Keep going

* WIP

* WIP

* BROKEN WIP

* WIP

* WIP

* Fix more tests

* WIP: alias starts working

* Broken WIP

* Broken WIP

* Variables begin to work

* captures start working

* A little better but needs fixed scope

* Shorthand env setting

* Update main merge

* Broken WIP

* WIP

* custom command parsing

* Custom commands start working

* Fix coloring and parsing of block

* Almost there

* Add some tests

* Add more param types

* Bump version

* Fix benchmark

* Fix stuff
2020-12-18 20:53:49 +13:00
Jonathan Turner
8df748463d
Getting ready for multiline scripts (#2737)
* WIP

* WIP

* WIP

* Tests are passing

* make parser more resilient

* lint
2020-11-10 05:27:07 +13:00
Jason Gedge
cda53b6cda
Return incomplete parse from lite_parse (#2284)
* Move lite_parse tests into a submodule

* Have lite_parse return partial parses when error encountered.

Although a parse fails, we can generally still return what was successfully
parsed. This is useful, for example, when figuring out completions at some
cursor position, because we can map the cursor to something more structured
(e.g., cursor is at a flag name).
2020-08-02 06:39:55 +12:00
Jonathan Turner
b89976daef
let format access variables also (#1842) 2020-05-19 16:20:09 +12:00
Jonathan Turner
0743b69ad5
Move from language-reporting to codespan (#1825) 2020-05-19 06:44:27 +12:00
Kevin Del Castillo
9ec2aca86f
Support completion for paths with multiple dots (#1640)
* refactor: expand_path and expand_ndots now work for any string.

* refactor: refactor test and add new ones.

* refactor: convert expanded to owned string

* feat: pub export of expand_ndots

* feat: add completion for ndots in fs-shell
2020-04-23 16:17:38 +12:00
Jonathan Turner
eec94e4016
Semicolon (#1613)
* WIP on blocks

* Getting further

* add some tests
2020-04-20 18:41:51 +12:00
Kevin Del Castillo
928188b18e
Redesign custom canonicalize, enable multiple dots expansion earlier. (#1588)
* Expand n dots early where tilde was also expanded.

* Remove normalize, not needed.
New function absolutize, doesn't follow links neither checks existence.
Renamed canonicalize_existing to canonicalize, works as expected.

* Remove normalize usages, change canonicalize.

* Treat strings as paths
2020-04-16 11:29:22 +12:00
Jonathan Turner
08a09e2273
Pipeline blocks (#1579)
* Making Commands match what UntaggedValue needs

* WIP

* WIP

* WIP

* Moved to expressions for conditions

* Add 'each' command to use command blocks

* More cleanup

* Add test for 'each'

* Instead use an expression block
2020-04-13 19:59:57 +12:00
Jonathan Turner
c4daa2e40f
Add experimental new parser (#1554)
Move to an experimental new parser
2020-04-06 19:16:14 +12:00
Andrés N. Robalino
b36d21e76f
Infer types from regular delimited plain text unstructured files. (#1494)
* Infer types from regular delimited plain text unstructured files.

* Nothing resolves to an empty string.
2020-03-16 15:50:45 -05:00
Yehuda Katz
7efb31a4e4 Restructure and streamline token expansion (#1123)
Restructure and streamline token expansion

The purpose of this commit is to streamline the token expansion code, by
removing aspects of the code that are no longer relevant, removing
pointless duplication, and eliminating the need to pass the same
arguments to `expand_syntax`.

The first big-picture change in this commit is that instead of a handful
of `expand_` functions, which take a TokensIterator and ExpandContext, a
smaller number of methods on the `TokensIterator` do the same job.

The second big-picture change in this commit is fully eliminating the
coloring traits, making coloring a responsibility of the base expansion
implementations. This also means that the coloring tracer is merged into
the expansion tracer, so you can follow a single expansion and see how
the expansion process produced colored tokens.

One side effect of this change is that the expander itself is marginally
more error-correcting. The error correction works by switching from
structured expansion to `BackoffColoringMode` when an unexpected token
is found, which guarantees that all spans of the source are colored, but
may not be the most optimal error recovery strategy.

That said, because `BackoffColoringMode` only extends as far as a
closing delimiter (`)`, `]`, `}`) or pipe (`|`), it does result in
fairly granular correction strategy.

The current code still produces an `Err` (plus a complete list of
colored shapes) from the parsing process if any errors are encountered,
but this could easily be addressed now that the underlying expansion is
error-correcting.

This commit also colors any spans that are syntax errors in red, and
causes the parser to include some additional information about what
tokens were expected at any given point where an error was encountered,
so that completions and hinting could be more robust in the future.

Co-authored-by: Jonathan Turner <jonathandturner@users.noreply.github.com>
Co-authored-by: Andrés N. Robalino <andres@androbtech.com>
2020-01-21 17:45:03 -05:00
Jonathan Turner
72838cc083
Move to using clippy (#1142)
* Clippy fixes

* Finish converting to use clippy

* fix warnings in new master

* fix windows

* fix windows

Co-authored-by: Artem Vorotnikov <artem@vorotnikov.me>
2019-12-31 20:36:08 +13:00
Andrés N. Robalino
87cc6d6f01 Separate internal and external command definitions. 2019-12-15 01:24:31 -05:00