weixin_39603609
weixin_39603609
2020-11-26 16:26

Exclusive access to target dir collides with `cargo check`. Please don't try to lock the target dir immediately when file changes

My usual workflow is to use sublime where I do cargo check and it shows inline errors when the build fails, while having a console open with cargo watch -x run. But both try to get exclusive access to the target dir as soon as I save a file. Often cargo watch gets the lock first when I press Ctrl-B in Sublime (which saves the file and then does cargo check), and then I have to wait until BOTH builds have failed until I get the inline error messages in Sublime. So I would really appreciate it if cargo watch could wait like 100ms to let cargo check go first :)

该提问来源于开源项目:passcod/cargo-watch

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答

8条回答

  • weixin_39883256 weixin_39883256 5月前

    The lock is a cargo thing, so perhaps this could be something to raise with them as well.

    Waiting before running could be done two ways: - As a sleep 0.1, or - As an option.

    The sleep way requires positioned flag parsing, which wasn't possible with Clap when I built cargo watch. It might be possible now, but I don't think so. In that case, that's a feature that needs to be requested of Clap.

    The option way needs to be done and exposed on Watchexec first before it can be used and exposed here.

    点赞 评论 复制链接分享
  • weixin_39603609 weixin_39603609 5月前

    Btw, clap supports positional args now..

    点赞 评论 复制链接分享
  • weixin_39883256 weixin_39883256 5月前

    No, no, I mean positional flags. As in, we need to be able to tell where each -x and -s flag was given absolutely, not the order within one kind as it is now.

    Currently, this line:

    
    cargo watch -s baz -x foo -s bar
    

    is interpreted to mean:

    
    cargo watch -x foo -s baz -s bar
    

    because Clap only provides order within kind, so we know that -s baz comes before -s bar, but not that -s baz came before -x foo.

    点赞 评论 复制链接分享
  • weixin_39883256 weixin_39883256 5月前

    Also, as a hacky workaround, you can plop this in your path named, e.g. cargo-sleep:

    bash
    #!/bin/sh
    sleep $1
    

    And then use: cargo watch -x "sleep 0.1" -x run...

    点赞 评论 复制链接分享
  • weixin_39603609 weixin_39603609 5月前

    I'm on windows though.. I tried this:

    
    > cargo watch -x "ping 127.0.0.1 -n 2 > nul" -x run
    error: no such subcommand: `run']`
    
            Did you mean `run`?
    
    > cargo watch -q -x "ping 127.0.0.1 -n 2 > nul" -x run
    error: no such subcommand: `ping`
    
            Did you mean `init`?
    

    Why doesn't it work?

    点赞 评论 复制链接分享
  • weixin_39883256 weixin_39883256 5月前

    -x is for cargo subcommands. -s will run arbitrary shell commands. See the readme for more details.

    You want -s, but you also want -s before -x, which (see the readme/help message) is not supported, because of clap not supporting positional flags.

    You can adapt the script I posted for windows, just make a batch script or something. The important part is it needs to be named cargo-NAME so that it can be run as a cargo subcommand.

    点赞 评论 复制链接分享
  • weixin_39603609 weixin_39603609 5月前

    Ah, I see. Ok, I created the file "C:\Users\me\.cargo\bin\cargo-sleep.bat" with this content:

    bat
     off
    ping 127.0.0.1 -n 2 > nul
    

    But it's still not working, any idea why? :/

    
    > cargo watch -x sleep -x run                   
    [Running 'cargo sleep                           
    error: no such subcommand: `run']`              
    
            Did you mean `run`?                     
    
    
    
    > cargo watch -x sleep                          
    [Running 'cargo sleep']                         
    error: no such subcommand: `sleep`              
    
            Did you mean `clean`?                   
    
    
    
    > cargo sleep                                   
    error: no such subcommand: `sleep`              
    
            Did you mean `clean`?                   
    
    

    Shouldn't .bat files work like any exe on windows?

    点赞 评论 复制链接分享
  • weixin_39883256 weixin_39883256 5月前

    At this point that's a cargo question. I'm not sure of what cargo does internally to pick those up or not.

    点赞 评论 复制链接分享

相关推荐