dartBarrelFileGenerator icon indicating copy to clipboard operation
dartBarrelFileGenerator copied to clipboard

how to have a shortcut to barreling command for a hard-coded folder?

Open matthewkooshad opened this issue 2 years ago • 8 comments
trafficstars

having to go to the explorer view, find lib folder, right click and choose the dartBarrelFileGenerator.generateCurrentWithSubfolders command from the context menu I think could be improved, if I could have a shortcut to barreling command for my lib folder. could you advise how to do that please?

matthewkooshad avatar Sep 19 '23 02:09 matthewkooshad

Hey @matthewkooshad, thanks for opening an issue!!

I'm currently not aware of any direct solution, but obviously it would be a nice to have. AFAIK, it is possible to execute the commands from the command palette, where you can seach for generateCurrentWithSubfolders and the option wil show up.

The thing is that the extension would somehow need to know the path in which to generate the barrel file, which is why it has been developed to be used from the file explorer. How would you like it to work? Let's say you are editing a file in /src/widgets/widget-one.dart; where should the barrel file be made? I understand that in /src/widgets/index.dart, right?

mikededo avatar Sep 23 '23 05:09 mikededo

I also realized that I couldn't move forward using command, for what I'm looking for, which is:

I would like a hard-coded path ability to use with the command, as you said currently, it is unusable without explorer interaction. So, the path is not inferred as you're suggesting, but that the path could be simply provided to the command somehow, through hard-coded config or whatever means.

matthewkooshad avatar Sep 23 '23 19:09 matthewkooshad

Hmm, could you provide an example with the hardcoded configuration? What about multiple folders? I have thought about creating a cli tool, as an alternative, but it would be independent from VSCode

mikededo avatar Sep 26 '23 08:09 mikededo

it doesn't matter much to me. i just want a command ability for a path.

a cli tool would work too.

if taking the hardcoded path approach, it could be a relative approach: for example, i am looking to have it always be my lib folder that's always at the same relative position in a flutter app.

since the feature is not available right now that i was curious about, should we close this thread? thanks for your efforts towards this cool tool -- the further convenience talked about here would make it even more of a time saver. thanks!

matthewkooshad avatar Sep 27 '23 01:09 matthewkooshad

The thing is that I believe I could make it work as a CLI tool quite easily (yet not meaning that the dev time will be short, as I have little spare time to invest in OS projects). Yesterday I was thinking to maybe have an NPM package, which could either be used with npx or simply installed globally. I know npm is not in the Dart's environment, but having written everything in TS, it would be way easier to publish it to NPM.

Example usages I have thought:

# dbfg is a shortcut for dart-barrel-file-generator 🥵
$ npx dbfg --mode nested-folders ./lib/some/path

# even maybe add the option to include multiple paths
$ dbfg --mode nested-folters ./lib/some/path ./lib/other/paths

mikededo avatar Sep 27 '23 07:09 mikededo

as i have npm, i'll be glad to report how it performs for me.

it would be nice to not have to see the bubble notification that the command executed too whenever it runs -- maybe that would happen naturally if using npm to run it as you showed.

also, i found i could put something like below in \AppData\Roaming\Code\User\keybindings.json (key bindings json command to open this file) to submit a command to terminal with a shortcut key:

{
    "key": "ctrl+shift+z",
    "command": "workbench.action.terminal.sendSequence",
    "args": {
      "text": "npx dbfg --mode nested-folders ./lib/some/path \u000D"
    }
  }

matthewkooshad avatar Sep 28 '23 03:09 matthewkooshad

Looks great. I did not know you could attach shortcuts to commands. Nonetheless, as said in other issues, I have barely time to work in this project. I will try to update it when possible.

mikededo avatar Oct 04 '23 13:10 mikededo

Answering this comment

Hmm, it is strange that the fsPath module cannot be found. I don't really know how VSCode runs commands under the hood. The main issue here is that the extension is not capable (as of now) of knowing the file path of the current focused file. That's why it requires to either right-click a folder or select a folder using the file selector.

My idea would be to add a new command that would only work when there's a file focused and it would allow the user to generate the barrel file for the current file parent folder, if there's any. This way, the user would be able to generate the barrel file without having to right-click a folder. What do you think?

mikededo avatar Apr 05 '24 05:04 mikededo