Skip to content

fix: fix lexing of comments, such that a#b becomes a coherent Item - #8151

Merged
fdncred merged 1 commit into
nushell:mainfrom
MangoIV:mangoiv/fix-nushell
Feb 22, 2023
Merged

fdncred merged 1 commit into
nushell:mainfrom
MangoIV:mangoiv/fix-nushell

Conversation

@MangoIV

@MangoIV MangoIV commented Feb 21, 2023 •

Copy link
Copy Markdown
Contributor

Description

Previously nix run nixpkgs#hello was lexed as Item, Item, Item, Comment, however, #hello is not supposed to be a comment here and should be parsed as part of the third Item.

This change introduces this behavior by not interrupting the parse of the current token upon seeing a #.

Thank you so much for considering this, I think many nix users will be grateful for this change and I think this will lead to more adaptation in the ecosystem.

User-Facing Changes

  • code like somecode# bla and somecode#bla will not be parsed as somecode, comment but as somecode#bla, hence this is a breaking change for all users who didn't put a space before a comment introducing token (#)

Tests + Formatting

I've added tests that cover this behavior in test_lex.rs

  • cargo fmt --all -- --check to check standard code formatting (cargo fmt --all applies these changes)
  • cargo clippy --workspace -- -D warnings -D clippy::unwrap_used -A clippy::needless_collect to check that you're using the standard code style
  • cargo test --workspace to check that all tests pass

After Submitting

If your PR had any user-facing changes, update the documentation after the PR is merged, if necessary. This will help us keep the docs up to date.

I think this is expected behavior in most other shells, so the documentation was lacking for not documenting the unexpected behavior before and hence now is automatically more complete >D

@codecov

codecov Bot commented Feb 21, 2023

Copy link
Copy Markdown

Codecov Report

Merging #8151 (d4d5060) into main (fa4531f) will increase coverage by 0.00%.
The diff coverage is n/a.

Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff           @@
##             main    #8151   +/-   ##
=======================================
  Coverage   54.61%   54.61%           
=======================================
  Files         608      608           
  Lines       99009    99011    +2     
=======================================
+ Hits        54069    54074    +5     
+ Misses      44940    44937    -3     
Impacted Files Coverage Δ
crates/nu-parser/src/lex.rs 75.96% <ø> (-0.08%) ⬇️
crates/nu-command/src/filesystem/touch.rs 63.73% <0.00%> (-1.04%) ⬇️
crates/nu-color-config/src/style_computer.rs 81.31% <0.00%> (+0.54%) ⬆️
crates/nu-command/src/env/with_env.rs 84.55% <0.00%> (+3.71%) ⬆️

@rgwood

rgwood commented Feb 21, 2023

Copy link
Copy Markdown
Contributor

Nice, thank you for the fix!

@fdncred
fdncred added this pull request to the merge queue Feb 22, 2023
Merged via the queue into nushell:main with commit d0e0701 Feb 22, 2023
sholderbach added a commit to nushell/nushell.github.io that referenced this pull request Apr 4, 2023
@sholderbach sholderbach added the notes:breaking-changes Noted in Breaking Changes section label Apr 4, 2023
sholderbach added a commit to nushell/nushell.github.io that referenced this pull request Apr 4, 2023
* Fix the use of comments

Reflect the lexing change in nushell/nushell#8151 

Addresses nushell/nushell#8731

* Add a warning note to externs

* Add warning note to the command docs

* Fix custom_completions.md

* Fix coloring_and_theming.md

* Fix `0.77` release notes to include the breaking change
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Behaviour of comments in shell usage

4 participants