amir9480 / vscode-cpp-helper

vscode extension to create implementation for c++ function prototypes.

Home Page:https://marketplace.visualstudio.com/items?itemName=amiralizadeh9480.cpp-helper

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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

RoyAwesome opened this issue · 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.

I have same problem when work with unreal engine project

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.

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.

Alright, I toyed around with it a bit last night and this morning, and have submitted a pull request:
#70

@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"
        }
],