amir9480 / vscode-cpp-helper

vscode extension to create implementation for c++ function prototypes.
https://marketplace.visualstudio.com/items?itemName=amiralizadeh9480.cpp-helper
MIT License
355 stars 31 forks source link

Adding support for find/replace config that allows alternative directory structures #70

Closed knetworx closed 11 months ago

knetworx commented 1 year ago

I wanted a way to support more configuration for split-directory setups without having to specify every directory.

For Unreal Engine, the structure will often look like this: \Source\ProjectName\Public\directory\file.h and the matching source file will look like this: \Source\ProjectName\Private\directory\file.cpp

I've added a configuration that will do a find and replace in the file path, allowing you to specify your directory structure. The configuration I'm currently using locally looks like this: "CppHelper.FindReplaceStrings": [ { "find": "\\Public\\", "replace": "\\Private\\" } ],

With this change, I've now simplified my SourcePattern to look like this: "CppHelper.SourcePattern": [ "{FILE}.cpp", "{FILE}.cc", "{FILE}.c", ],

And it's now able to find all of my source files. (You could also use {"find": "header", "replace": "source"} or something similar to replace the rest of the defaults in "CppHelper.SourcePattern")

I'm also using the FindReplaceStrings for determining where to create the matching source file when using "Create source file" for "CppHelper.SourceNotFoundBehavior".

I've also added the ability to do nothing or show an error message if the matching source file can't be found. For Unreal projects, I don't want to automatically create a new source file, and I don't necessarily want to create the implementation in the header either. I do, however, want to see a message that tells me the file wasn't found or created, so I know it's doing something.

Feel free to use any, all, or none of these changes - this is a super handy extension, and these changes made configuration much easier for my Unreal project.

knetworx commented 1 year ago

Looks like this could help with:

knetworx commented 1 year ago

Noticing some weird issues, going to do some more testing and hammer them out.

knetworx commented 1 year ago

The issues I'm seeing seem to be unrelated to my changes. Even so, I'm hesitant to reopen the pull request until I can figure out why it's happening. I believe I've narrowed it down to a parsing issue with Unreal UCLASS specifiers. If the class I'm working with contains multiple specifiers, the editor hangs whenever I try to create an implementation for one of its member functions.

For example, if I have a UCLASS specified like this: UCLASS() or this: UCLASS(Config = Game) Creating an implementation works fine. However, if I have one specified like this: UCLASS(Config = Game, Meta = ()) or this: UCLASS(Config = Game, Category = "") The editor hangs when I try to create an implementation.

knetworx commented 1 year ago

Alright, I've got it fixed. The UCLASS specifier was breaking function parsing. I added a line to strip all the Unreal specifiers before parsing, and everything works as expected now.

amir9480 commented 11 months ago

@knetworx Thanks