Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can’t get simple zsh completion to work #6

Closed
adaszko opened this issue Jul 31, 2023 · 4 comments · Fixed by #8
Closed

Can’t get simple zsh completion to work #6

adaszko opened this issue Jul 31, 2023 · 4 comments · Fixed by #8

Comments

@adaszko
Copy link
Contributor

adaszko commented Jul 31, 2023

Hi 👋

I’m on macOS, trying to write a simple test case. This just outputs a bunch of files from the current directory, not bar, as it should have. When I source the completion script from the shell, it works fine.

    #[test]
    fn completest_reduction() {
        let script = r#"
#compdef foo

_foo () {
    compadd bar
    return 0
}
compdef _foo foo
"#;
        let term = completest::Term::new();
        let mut runtime = completest::ZshRuntime::new(PathBuf::from_str("/opt/homebrew/bin/zsh").unwrap(), PathBuf::from_str("./completest-temporary-directory").unwrap()).unwrap();
        runtime.register("foo", &script).unwrap();
        let output = runtime.complete("foo \t", &term).unwrap();
        dbg!(output);
    }
    Running unittests src/main.rs (target/debug/deps/complgen-fd528e5e370143a6)

running 1 test
[src/zsh.rs:404] output = "adaszko@pryk complgen % foo\nCONTRIBUTING.md                  e2e/                             psql.usage\nCargo.lock                       examples/                        psql.zsh\nCargo.toml                       help.usage                       pytest.ini\nLICENSE                          help.zsh                         run-e2e-tests.bash*\nREADME.md                        lsof.bash                        src/\nassets/                          lsof.zsh                         strace.fish\ncapture_postamble.zsh            my.bash                          strace.usage\ncapture_preamble.zsh             my.fish                          strace.zsh\ncargo.fish                       my.usage                         target/\ncompletest-temporary-directory/  my.zsh                           usage/\ndfa.dot                          pgservice.conf                   venv/\ndfa.svg                          proptest-regressions/"
test zsh::tests::completest_reduction ... ok
@epage
Copy link
Contributor

epage commented Jul 31, 2023

I'm seeing the same thing with your test case. I will say I am not a completion expert and I've only installed zsh on my system to run the tests which is a barrier to debugging this. I do know the clap completions pass their tests.

One thing I noticed that is incorrect that doesn't fix this is that the ZshRuntime::new parameter bin_root is meant to be a directory to add to PATH. We should probably clarify that in the API (created #7).

When I source the completion script from the shell, it works fine.

Can you reproduce with

$ ZDOTDIR=completest-temporary-directory zsh
% foo \t

Part of the design for completest is to make it easy for people to drop into the exact shell that is being tested

@adaszko
Copy link
Contributor Author

adaszko commented Jul 31, 2023

One thing I noticed that is incorrect that doesn't fix this is that the ZshRuntime::new parameter bin_root is meant to be a directory to add to PATH. We should probably clarify that in the API (created #7).

BTW, I also accidentally overwrote my .zshenv because I set the ZshRuntime::new()’s home parameter to my actual home directory. Had to restore it from backups. That may be something worth documenting as well ;) Or better yet, use a mktemp directory by default.

Can you reproduce with […]

That didn’t work either. What fixed it was the addition of rm $ZDOTDIR/.zcompdump at the beginning of completest-temporary-directory/.zshenv (i.e. somewhere before compinit call).

@epage
Copy link
Contributor

epage commented Jul 31, 2023

BTW, I also accidentally overwrote my .zshenv because I set the ZshRuntime::new()’s home parameter to my actual home directory. Had to restore it from backups. That may be something worth documenting as well ;) Or better yet, use a mktemp directory by default.

Mind creating an issue on how we can clarify this?

Since we are writing directly to the directory and there are users today not using a temp directory (clap), we need to make sure this is handled in the right way.

That didn’t work either. What fixed it was the addition of rm $ZDOTDIR/.zcompdump at the beginning of completest-temporary-directory/.zshenv.

shrug no idea. I guess we could always delete that file when initializing to reduce the chance of bugs

I think I had missed that because I copy I do a lot of filesystem shenanigans

@adaszko
Copy link
Contributor Author

adaszko commented Jul 31, 2023

Created #9 :)

@epage epage closed this as completed in #8 Jul 31, 2023
epage added a commit that referenced this issue Oct 6, 2023
…holder

README.md 'Crates Status' icon link
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 a pull request may close this issue.

2 participants