vscode-cpp-helper icon indicating copy to clipboard operation
vscode-cpp-helper copied to clipboard

CppHelper.SourcePattern is very constraining for non-"all in one folder" source layouts

Open RoyAwesome opened this issue 3 years ago • 5 comments

I'm not a fan of the traditional 'all files in one folder' approach to C++ development, and I often create folders in my source tree for different logical components, ie:

src
 - public/
 -  - example/
 -  - - example.hpp
 - - - example2.hpp
 - - core.hpp
 - private/
 - - example/
 - - - example.cpp
 - - - example2.cpp
 - - core.cpp

As far as I can tell, I can't pass regex paths or any other mechanism to have this plugin search for the proper source files when creating an implementation. I can work around this by adding the folder structure to the plugin, but I often create new folders for different logical parts of my codebase and modifying the search paths every time I decide to add or rename a folder is very tedious.

It would be nice to specify a path like "private/**/{file}.cpp", and have the plugin search through my paths to find the source file. It may also be helpful to be able to walk up the directory tree any number of folders to a given folder name, since I sometimes go 2 or 3 deep in folders.

RoyAwesome avatar Oct 20 '21 21:10 RoyAwesome

I have same problem when work with unreal engine project

high-cloud avatar Dec 03 '21 11:12 high-cloud

I'm not a typescript expert, nor have I ever created a VS Code extension, so I'm not familiar with the process of compiling this repository into a usable extension. That being said, I've looked into the source code a bit, and it looks like in Helpers.ts, there's an openSourceFile() function which grabs the current file and attempts to find the match with a simple replacement. I believe if you swap the fs.existsSync() with some sort of globbing, that would give you the wildcard functionality, and make this extension 1000x more useful for Unreal projects. With enough poking around, I think I could figure out how to handle this, but if someone with a bit more expertise in this area could help, I would be forever grateful.

knetworx avatar Aug 22 '23 05:08 knetworx

Another possibility: What if, in the settings, we could specify replacement pairs, e.g. { replace: "Public", with: "Private" } And each of the requested replacements would be applied when searching for the cpp file. The above could replace "/somedir/Public/someotherdir/myfile.h" with "somefir/Private/someotherdir/myfile.cpp", allowing the directory structure to be whatever the user wants it to be.

knetworx avatar Aug 22 '23 07:08 knetworx

Alright, I toyed around with it a bit last night and this morning, and have submitted a pull request: https://github.com/amir9480/vscode-cpp-helper/pull/70

knetworx avatar Aug 22 '23 21:08 knetworx

@RoyAwesome @knetworx contribution is now available in v0.3.3. You can now use CppHelper.FindReplaceStrings configuration.

Maybe something like this can fix your issue:

"CppHelper.FindReplaceStrings": [
        {
            "find": "/public",
            "replace": "/private"
        }
],

amir9480 avatar Oct 09 '23 08:10 amir9480