Giter Club home page Giter Club logo

vscode-cpp-helper's Introduction

C++ Helper

Screen Shot C++ Helper extension for VSCode.

Features

  • Generating implementation for c++ declarations.
  • Generating header guard for headers.

Configuration

CppHelper.SourcePattern:

The array of possible patterns to find the source of a header file.

Example:

"CppHelper.SourcePattern": [
    "{FILE}.cpp",
    "{FILE}.c",
    "{FILE}.inl",
    "/src/{FILE}.cpp"
]

Where {FILE} is your active header file name.

If you don't want a relative pattern then put a / as first character.

CppHelper.HeaderGuardPattern:

The pattern of header guard. Example:

"CppHelper.HeaderGuardPattern": "{FILE}_H"

Where {FILE} is your active header file name in UPPERCASE format.

CppHelper.ContextCreateImplementation

Show or hide "Create Implementation" in context menu.

CppHelper.ContextCreateImplementationHere

Show or hide "Create Implementation Here" in context menu.

CppHelper.ContextCopyImplementation

Show or hide "Copy Implementation" in context menu.

CppHelper.ContextCreateHeaderGuard

Show or hide "Create Header Guard" in context menu.

CppHelper.SourceNotFoundBehavior

What happen if source file of a header file not found.

  • Implement in same file
  • Create source file
  • Show error
  • Do nothing

CppHelper.FindReplaceStrings

Pairs of strings to find/replace within the path

Example:

"CppHelper.FindReplaceStrings": [
    {
        "find": "/include/Public",
        "replace": "/src/Private"
    }
],

Above configuration will replace all /include/Public in your path to /src/Private when trying to find source code of header file. You can also use regular expressions.

"CppHelper.FindReplaceStrings": [
    {
        "find": "/include/Public/([^\\/]+)",
        "replace": "/src/Private/$1"
    }
],

Known Issues

If you implement a previously implemented function duplicate implementation will happen.

This extension created using regex and there is no parser/compiler. so any wrong implementation may happen. If you found any wrong implementation please let me know in issues and also don't forget to send your code sample.

Change Log

0.3.3

Add new CppHelper.FindReplaceStrings configuration (#70)

0.3.1

  • Bug fixes (#49, #47, #41)

0.3.0

  • Add functions and classes attributes support.
  • Fix default parameter with parentheses bug (#35).
  • Fix trailing parameters comment issue (#31).

0.2.1

  • Fix code indent bug when EOL was LF.
  • Fix member operator +, operator - bug.
  • Cast operator support added.

0.2.0

  • Fix bugs (#12, #13).
  • Copy Implementation to clipboard command added (#11).
  • Create source file if not found (#14).
  • Improved order of implementation.

0.1.0

  • Add Create Implementation Here command. (#7)
  • Add setting to hide context menu items.

0.0.7

  • Bug #5 fixed.

0.0.6

  • Bug #4 fixed.

0.0.5

  • Fix bug in Linux. (#1, #2)

0.0.4

  • Argument with default value implementation bug fixed.
  • Class template specialization support added.
  • Regex to find previous implementation improved.
  • Bug with operator() fixed.
  • SourcePattern configuration bug fixed.

0.0.3

  • Keeping the order of implementations synced to declarations as much as possible.

vscode-cpp-helper's People

Contributors

amir9480 avatar armandas avatar clearlykyle avatar geometror avatar hyperupcall avatar knetworx avatar paulelong avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

vscode-cpp-helper's Issues

Create implementation bug

Hello friends,

The "create implementation" option in the context menu is creating the implementation in the header file rather than its .cpp file. How do I fix this?

Function not detected

Clicking on function name and creating implementation doesn't work and says "Function not dectected" but create implementation here works.

Extension issue

  • Issue Type: Bug
  • Extension Name: cpp-helper
  • Extension Version: 0.3.0
  • OS Version: Windows_NT x64 10.0.19041
  • VS Code version: 1.61.1

⚠️ We have written the needed data into your clipboard. Please paste! ⚠️

"Create Implementation" function stopped working properly.

I don't know what I did wrong, but at some point I used the Create Implementation function and then I wanted to move the implementation code somewhere else, so I just selected the block and pressed Ctrl+X to cut. Maybe I pressed some other key combination instead, IDK, but after that Create Implementation doesn't work properly anymore.

If I declare a new function in the header and press Create Implementation, I get an error that reads "Function Not Detected". If I try to Create Implementation of a function that was declared before the function broke down, it creates Implementation of some other function or even of a declared variable for some reason.

I tried reinstalling the plugin, but it didn't help. Tried uninstalling VSCode and reinstalling it from scratch (deleted the Code folder in AppData too to get rid of all the cache), but it didn't help either.

Has anyone encountered a similar error and how can I fix it? It's a mild inconvenience, I can create implementations manually, but I just got used to using a hotkey for that.

Thank you in advance!

not creating implementation in .cpp correctly

My file layout is simply like this
Screen Shot 2020-06-19 at 5 27 34 PM

I changed the settings to this
Screen Shot 2020-06-19 at 5 28 14 PM

You can see, even though i click on create implementation. It's creating all the implementations in place in stead of in .cpp.

bug_impl
Would appreciate your help

Change definition / declaration

Thank you for the awesome plugin! Very convenient tool.

I would like to suggest one awesome feature from QtCreator. When you changing function definition manually it suggest to correct declaration and vice versa. Is it possible to implement something similar? Very often needed to do.

[Feature Request] Move Implementation to Source File

I use the "Move Implementation to Source File" feature of Visual Assist constantly. It basically moves whatever implementation is currently defined (if it exists) in the header to the source file, adds the necessary <Class>:: text, and so on.

Unfortunately VS Code does not have a similar functionality.

This plugin has done a lot of the legwork toward getting this feature implemented, but how difficult would it be to implement a similar functionality?

[[nodiscard]] attribute support

First of all, thank you for this extension, I just started using and already love it!

I have found one issue: if a [[nodiscard]] attribute is present in the function declaration, part of it appears in the implementation output.

Header file:

#ifndef TEST_H
#define TEST_H

class Test
{
public:

    [[nodiscard]] bool test() const;
};

#endif // TEST_H

Implementation output:

nodiscard]] bool Test::test() const
{
    
}

Expected output:

bool Test::test() const
{
    
}

The extension fails to find the source file when it's not in "an obvious location".

I have a complicated project where the header and source files are not in the same directory, and they more than one directory level away from each other. However, the include directories are properly configured in the project settings.

The default switch "header / source" option in VS doesn't work, however, I installed a different extension (first match) for the search "header source" and it works.

I know the proper way to find the source is to consider include directories in the project settings, then look for the C / C++ file that includes the current header and its name matches the header name.

Somehow it's not what this extension does, since it doesn't find my source file. So for now I can create the implementation in the header file and then manually move it to the source file.

Creating an implementation sometimes breaks the C++ language server?

Creating an implementation of a member function sometimes causes C++ features to break, in general. For example, the Problems tab no longer updates; existing errors remain highlighted even if I add or remove lines of code.

I know very little about reporting these kinds of issues, but I did see this in the Window log:

[2022-02-16 14:31:46.882] [renderer1] [warning] UNRESPONSIVE extension host, 'amiralizadeh9480.cpp-helper' took 100% of 5062.333ms, saved PROFILE here: 'file:///var/folders/tf/62gdm4xx4bddtyz106q__5340000gn/T/exthost-cdeae8.cpuprofile' [{"id":"amiralizadeh9480.cpp-helper","total":5062208,"percentage":100}]

I believe this started after the update from two days ago. I am running on MacOS Monterey. I tried removing and reinstalling the extension, but the behavior is the same.

It's not a consistent problem. I tried to reproduce it with a simple example and failed, but just had it happen again a few minutes ago.

Let me know what diagnostics I should be looking for!

Creating implementation sometimes doesn't work

Hi!
Thanks a lot for creating this! Really awesome stuff...
Sometimes I have an issue, where when I want to create an implementation, nothing happens, or the .cpp file is opened. But either way no implementation is created. Also, my cpu is getting really really busy and I cannot save the .cpp file anymore. Repoening vscode is my current solution for this.
Is there any way I can log what is going on and provide you with more details?
Thanks a lot!
Konrad

Function not detected

When I right click a member function with default value and click 'Create Implementation', I got a message: Function not detected.

my code:

class ResourceModel : public QAbstractItemModel {
public:
    // Cannot impl by cpp-helper
    QModelIndex index(int row, int column, const QModelIndex& parent = QModelIndex()) const override;
    // Worked well
    QModelIndex parent(const QModelIndex& child) const override;
};

Do include guards properly

When generating an include guard, don't use a name that's reserved for the implementation.
Mimicing what is seen in the standard headers is a common mistake, and one reason for using an automated tool is to always get it right.

Create cpp file if now exists

It would be good when you click on Create Implementation, if the .cpp file does not exist, it should create a new .cpp file with the same name of the .hpp.

Feature Request: focus on already opened file instead of creating a duplicate tab

Hi, it's me again (this time I checked multiple times before opening a new issue)

I often work with my editor splitted vertically with .h files on the left and .cpp files on the right, if I click "Create implementation" and the .cpp file is visible, everything works fine and it focuses on the right window as you can see here:

image

If the .cpp is not focused on the right window, when I click "Create implementation" it creates another tab of the .cpp file in the current panel, despite I have the option "workbench.editor.revealIfOpen": true activated,.
If I open an already opened file by clicking it in the file explorer, the editor will focus it instead of opening a new tab in the current editor (where I have the cursor), this doesn't work with the extension so I think it could be something related to the command it uses to open the file.

image

Thank you!

Issue with a nested class defined "externally"

I have a structure like

template <typename T>
struct A {
  struct B;
};

template <typename T>
struct A::B {
  void myMethod();
};

When I click on myMethod() to generate definition, it does not do it right.

Bug of creating implementation of the very first function of a header file

when I use the plugin to create the implementation of the very first function declaration of a header file with a header guard, part of the header guard exists along with the implementation.
example as follows:

// test.h
#ifndef __TEST_H__
#define __TEST_H__

void test();

#endif // __TEST_H__
// test.cpp
#include "test.h"

__TEST_H__

void test()
{
    
}

Better friend function support

It doesn't seem to generate friend functions correctly. The friend token was not removed and the class scope :: was added.
Amazing plugin by the way! Saved me a lot of work.

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

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.

Extension no longer working after update

Hi, I've just updated the extension and NONE of the command is working..

I tried uninstalling and resetting the settings.
I Tested:

  • Create implementation (nothing happens)
  • Create implementation here (nothing happens)
  • Copy Implementation (nothing happens)
  • Create Header Guard (nothing happens)

I rolled back to previous version, If you want me to test please tell me and I will update again!
I really use this extension everyday!

"Create Implementation" fails when header file contains comments

When a header file contains comments of any kind the function cannot be found or the wrong function is selected. (due to a position mismatch, since line comments are removed before the functions are parsed, so the positon of the function in the active editor is always greater when comments are present)

"Create implementation" is opening a new tab instead of using the already opened one.

Hi, thank's for this excellent extension.
I have a little enhancement in mind. For illustration, the editor is split into two views. "Test.h" is opened in the left pane and "Test.cpp" in the right pane.
When using the "Create implementation" command from "Test.h", a new "Test.cpp" tab is created in the left pane.
It will be helpful if, instead, it focuses on the already opened tab in the right pane.

example:
openToCurrentlyOpened

Create implementation doesn't work (0.0.6)

Hi, cool extension but on version 0.0.6 "Create implementation" doesn't work.
On version 0.0.5 everything works fine.
What information do I need to provide so that you can fix the bug?

VSCode version: 1.43.2
OS:Windows 10 x64.

inside class problem

while creating implementation for inside class extonison is not working properly
for operator == from class :

class RectangleMatrix::Iterator
{
public:
    //...
    bool operator==(const Iterator it);
    //...

should be :

bool RectangleMatrix::Iterator::operator==(const Iterator it)
{
//....
}

but instead create :

bool RectangleMatrix::operator==(const Iterator it) 
{
  //... 
}

Commands not found

I keep getting these notifications whenever i try to use any of the features:

command 'cpp-helper.create-header-guard' not found
command 'cpp-helper.create-implementation' not found

My settings are:

"CppHelper.HeaderGuardPattern": "__{FILE}_H__",
"CppHelper.SourcePattern": [
"{FILE}.cpp",
]

I'm on VSCode version: 1.43.2

I tried reinstalling the extension, reloading the window, disable/enable of the extension and binding commands to shortcuts.
I can find the commands in the keybindings and it knows they're valid.

Template implementation within header file

(Update): I found that I could do that by adding the {FILE}.hpp in my settings file. So this should not be an issue now...

Could we add a feature to implement the template within the same header file? Thanks.

Trailing comment symbol "//"

Hi, I came across this issue when declaration is on different lines with trailing comment session, the implementation created has numerous trailing backslash "//" for those lines. Please take a look at this example:
image

Extension issue

  • Issue Type: Bug
  • Extension Name: cpp-helper
  • Extension Version: 0.3.0
  • OS Version: Windows_NT x64 10.0.19042
  • VS Code version: 1.62.2

⚠️ We have written the needed data into your clipboard. Please paste! ⚠️

{
	"messages": [],
	"activationTimes": {
		"codeLoadingTime": 19,
		"activateCallTime": 338,
		"activateResolvedTime": 14,
		"activationReason": {
			"startup": false,
			"extensionId": {
				"value": "amiralizadeh9480.cpp-helper",
				"_lower": "amiralizadeh9480.cpp-helper"
			},
			"activationEvent": "onLanguage:cpp"
		}
	},
	"runtimeErrors": [],
	"runningLocation": 1
}

Add trailing return type

It is very useful option for class methods which have inner class types as return type. It can be an option in the VS Code setting or something more intelligent like auto detection of specific return types.

Implementations of multiple methods

Hi!
When I select multiple methods and do "Create implementation" implementation is created for the 1st one only, while on your preview you easily create implementations for all selected methods.

Maybe there's some special way of selecting methods I'm unaware of? I'm just selecting regularly with cursor and Shift.

Create implementation implements the function in h file

Both the command "Create implementation" and "Create implementation here" result in the same thing. That is, they both create the implementation in the h file. Now, I am writing C++ code for Unreal Engine which may be the underlying issue here.

An example of code:

#pragma once

#include "CoreMinimal.h"
#include "SMWeapon.h"
#include "SMShotgun.generated.h"

/**
 * 
 */
UCLASS()
class SHOOTERMANIAC_API ASMShotgun : public ASMWeapon
{
	GENERATED_BODY()

public:
	ASMShotgun();

protected:

	UPROPERTY(EditDefaultsOnly, Category = "SMShotgun | Ammo")
	/** The number of pellets per shell */
	int ShotgunPellets;

	UPROPERTY(EditDefaultsOnly, Category = "SMShotgun | Ammo", meta = (ClampMin="0.0", ClampMax="90.0"))
	float SpreadAngle;

protected:

	virtual void Fire() override;

	void test();
};

Trying to create an implementation of the "test" function results in:

#pragma once

#include "CoreMinimal.h"
#include "SMWeapon.h"
#include "SMShotgun.generated.h"

/**
 * 
 */
UCLASS()
class SHOOTERMANIAC_API ASMShotgun : public ASMWeapon
{
	GENERATED_BODY()

public:
	ASMShotgun();

protected:

	UPROPERTY(EditDefaultsOnly, Category = "SMShotgun | Ammo")
	/** The number of pellets per shell */
	int ShotgunPellets;

	UPROPERTY(EditDefaultsOnly, Category = "SMShotgun | Ammo", meta = (ClampMin="0.0", ClampMax="90.0"))
	float SpreadAngle;

protected:

	virtual void Fire() override;

	void test();
};
void ASMShotgun::test() 
{
	
}

I am using VSCode v. 1.45.1, C++ Helper 0.1.0, running on Windows 10

Not working on vscode 1.43.1

Hi,

First thank you for working on this missing feature of vscode.

I can't get this extension working though. Right clicking on the declaration and clicking "Create implementation" does not give any error nor result.

on a side not, it is also impossible for me to set

"CppHelper.SourcePattern": [
    "{FILE}.cpp",
    "{FILE}.c",
    "{FILE}.inl",
    "/src/{FILE}.cpp"
]

in my settings:

image

Thanks for your help.

getter/setter helper

thank you for convenient tool!

it would be great if it supports getter/setter implementation as well.
thank you

No License information

The project is missing any kind of licensing, this means it cannot be used in areas where you have to have permission to use a software (like commerically).

Support globs in source patterns

With some directory structures it becomes cumbersome to define all the source patterns required. This is particularly problematic with large projects. Having support for globs would help a lot to deal with these scenarios.

On a side note the extension https://github.com/ryzngard/header-source-switch does a very good job in automatically detecting the corresponding header/source file. Could be a nice approach for the future.

How to set the SourcePattern dynamically for an Unreal Engine 4 Project

Hi, I discovered today your extension and I think it's great, It saves me a lot of time even if I have to copy and paste the implementation manually!

I tried to configure the Source Pattern in several ways but only one worked and the path is hardcoded.

For example

This is the typical hierarchy in UE4

The .h file can be in two different folders, the cpp file is always in the private folder:

ProjectName/Source/ProjectName/Public/File.h
ProjectName/Source/ProjectName/Private/File.h
ProjectName/Source/ProjectName/Private/File.cpp

If they are both in the private folder it's easy, the default "{file}.cpp" is enough to detect the correct file.

If the .h file is in public I have to hardcode the "/Source/ProjectName/Private/{file}.cpp" string, so I have to do this for every project with a different path.

Do you think is there a way to get the {ProjectName} in the same way as you get the {file}?

Thank you in advance <3

file patterns: leading "/" here

If structure of src and header is next

├── Dispatcher.hpp
└── private
└── Dispatcher.cpp

then having pattern
"/private/{FILE}.cpp"

doesn't help to find Dispatcher.cpp (via, for example, create implementation for new method)

Istead, pattern "private/{FILE}.cpp" works great. Please, check code for pattern matching with leading "/".

OS: linux

Search by file name doesn't work in VSCode - Insiders

Hi y'all, I was using the older version of vs code and while searching for any file name, it was showing me the whole files in the directory, after updating, I can see only the recently opened files. I am working in a remote workplace.

I have read other entries about the same issue and later downloaded VSCode Insiders, however, when I try to ctrl + p and search for the folder, still, I get the only recently opened files. Do you have any idea about how to fix this error?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.