Skip to content

improve error when name and parameters are not space-separated - #8958

Merged
fdncred merged 7 commits into
nushell:mainfrom
1Kinoti:def
May 12, 2023
Merged

fdncred merged 7 commits into
nushell:mainfrom
1Kinoti:def

Conversation

@1Kinoti

@1Kinoti 1Kinoti commented Apr 21, 2023 •

Copy link
Copy Markdown
Contributor

Description

closes #8934

this pr improves the diagnostic emitted when the name and parameters of either def, def-env or extern are not separated by a space

Error:
  × no space between name and parameters
   ╭─[entry #1:1:1]
 1 │ def err[] {}
   ·        ▲
   ·        ╰── expected space
   ╰────
  help: consider adding a space between the `def` command's name and its parameters

from

Error: nu::parser::missing_positional

  × Missing required positional argument.
   ╭─[entry #1:1:1]
 1 │ def err[] {}
   ╰────
  help: Usage: def <def_name> <params> <body>

@codecov

codecov Bot commented Apr 21, 2023 •

Copy link
Copy Markdown

Codecov Report

Merging #8958 (f4f542e) into main (2a484a3) will increase coverage by 0.12%.
The diff coverage is 91.80%.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #8958      +/-   ##
==========================================
+ Coverage   68.84%   68.97%   +0.12%     
==========================================
  Files         641      641              
  Lines      102325   102490     +165     
==========================================
+ Hits        70450    70691     +241     
+ Misses      31875    31799      -76     
Impacted Files Coverage Δ
crates/nu-protocol/src/parse_error.rs 22.22% <0.00%> (-0.23%) ⬇️
crates/nu-parser/src/parse_keywords.rs 78.05% <93.33%> (+0.29%) ⬆️

... and 15 files with indirect coverage changes

@sophiajt

sophiajt commented Apr 21, 2023 •

Copy link
Copy Markdown
Contributor

Should we detect this and then just let them not have to put the space if they don't want to? 🤔

@1Kinoti

1Kinoti commented Apr 21, 2023 •

Copy link
Copy Markdown
Contributor Author

i haven't figure how to do that yet,😅 since defs are parsed twice? paired with completions, i think it would difficult to do that. but it's possible,

i'd probably have to rewrite parse_def() or find a way to deal with spans. so i think, before that happens, a better error message is okay

@sophiajt

Copy link
Copy Markdown
Contributor

@1Kinoti I wonder if we could check how many args were passed in, and if it's one less than what we expect, we look to see if we can convert the def foo[] {} to def foo [] {} (and same for def foo() {})

@cmidkiff87

cmidkiff87 commented Apr 21, 2023 •

Copy link
Copy Markdown

i haven't figure how to do that yet,sweat_smile since defs are parsed twice? paired with completions, i think it would difficult to do that. but it's possible,

Does Nushell not use a tokenizer before parsing? I feel like a tokenizer would make this trivial (but i have zero experience with making a REPL or tokenizer, so...)

@1Kinoti

1Kinoti commented Apr 21, 2023 •

Copy link
Copy Markdown
Contributor Author

I wonder if we could check how many args were passed in, and if it's one less than what we expect, we look to see if we can convert the def foo[] {} to def foo [] {} (and same for def foo() {})

@jntrnr where would we check this? in parse_predecl() or in parse_def()? or in both? i think this is possible.

edit: also there's the --help flag which can appear anywhere, any number of times

@1Kinoti

1Kinoti commented Apr 21, 2023

Copy link
Copy Markdown
Contributor Author

Does Nushell not use a tokenizer before parsing? I feel like a tokenizer would make this trivial (but i have zero experience with making a REPL or tokenizer, so...)

@cmidkiff87 there is a tokenizer

Comment thread crates/nu-protocol/src/parse_error.rs Resolved
@fdncred

fdncred commented Apr 28, 2023

Copy link
Copy Markdown
Contributor

@1Kinoti we can probably land this if you fix the conflicts please.

@1Kinoti
1Kinoti marked this pull request as draft April 28, 2023 21:15
@1Kinoti
1Kinoti marked this pull request as ready for review April 28, 2023 21:15
@1Kinoti
1Kinoti marked this pull request as draft May 9, 2023 20:45
@1Kinoti

1Kinoti commented May 9, 2023

Copy link
Copy Markdown
Contributor Author

@pingiun, i cannot tell why this test keeps on failing, i see it was introduced in #8956 but before that, this pr passed all CI. can you maybe tell me what i am doing wrong?

@pingiun

pingiun commented May 12, 2023

Copy link
Copy Markdown
Contributor

@pingiun, i cannot tell why this test keeps on failing, i see it was introduced in #8956 but before that, this pr passed all CI. can you maybe tell me what i am doing wrong?

Just on the face of it I think you reverted some of my changes. I got this error before I changed the parser correctly. That is the rough idea but I'll check your changes to see where it goes wrong

@pingiun pingiun left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe this is where your error comes from. Externs can now have more than 3 spans

Comment thread crates/nu-parser/src/parse_keywords.rs Resolved
Comment thread crates/nu-parser/src/parse_keywords.rs Resolved
@1Kinoti
1Kinoti marked this pull request as ready for review May 12, 2023 13:14
@1Kinoti

1Kinoti commented May 12, 2023 •

Copy link
Copy Markdown
Contributor Author

I believe this is where your error comes from. Externs can now have more than 3 spans

aah, because externs can now have bodies!

thanks @pingiun for the catch and @fdncred for the commit

@fdncred

fdncred commented May 12, 2023

Copy link
Copy Markdown
Contributor

let's move forward with this. thanks.

@fdncred
fdncred merged commit a3bf2bf into nushell:main May 12, 2023
@1Kinoti
1Kinoti deleted the def branch May 12, 2023 14:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Omitting a space in custom command declaration causes misleading error

6 participants