bigbahss / vscode-cmantic Goto Github PK
View Code? Open in Web Editor NEWC/C++ code generation for VS Code: Generate Definitions, Getters, Setters, and much more.
Home Page: https://bigbahss.github.io/vscode-cmantic/
License: MIT License
C/C++ code generation for VS Code: Generate Definitions, Getters, Setters, and much more.
Home Page: https://bigbahss.github.io/vscode-cmantic/
License: MIT License
This probably goes without saying, but I thought I would formalize this with an issue (maybe someone can offer ideas). Certain 'disruptive' macros can affect C-mantic's parsing. The language server does a lot of the heavy-lifting, but C-mantic still has to do some parsing of it's own.
Examples of disruptive macros would be ones that insert keywords, such as public
or override
. In these cases, C-mantic might fail to place a new member function in public-access will insert a redundant public:
before a new member function, or fail to remove override
when creating a function definition. This problem is solvable by having C-mantic resolve the definitions of macros. But, this is sub-optimal because it would require resolving every identifier that is not defined in the language, which goes against the idea of "Don't pay for what you don't use".
It's possible that this is not a significant problem (in the examples I gave it's more of a mild inconvenience if anything). If you find this to be a problem, up-vote this or post a comment.
Right now if I use the "switch header/source in workspace" command and no matching header was found, then the extension will helpfully throw an error saying "no matching header/source found".
It would be better if there was an option to create the missing header or source file and switching to that instead.
A nice addition to the 'Switch Header/Source in Workspace' command would be to optionally open the matching header/source file in a new editor column, next to the current file.
Hi,
first of all, thank you for your extension.
I have two suggestions for new features :
Given a class like that :
class Test
{
public:
Test( void );
Test( const Test & src );
~Test( void );
Test & operator=( const Test & src );
private:
std::string _value;
std::string _value2;
};
It would be nice to have possibility to create definition for copy constructor and operator= :
Test::Test( const Test& src )
: _value( src._value ),
_value2( src._value2 )
{
}
And :
Test& Test::operator=( const Test& src )
{
if ( this != &src )
{
_value = src._value;
_value2 = src._value2;
}
return *this;
}
These operations are frequently error prone (missing argument, wrong initialization) and may be encountered frequently in old project (prior to C++11).
Yours.
Most of C++ projects either have the Cpp/header files in the same directory or in a separate src*/inc* folders in the same parent directory.
I suggest altering the searching techniques to first the parent directory, then the whole workspace folders if not found.
This will boost the search especially in remotely edited workspaces. ( Our projects are on linux servers in HQ, while we access remotely via VPN - due to COVID).
The setter generator generates a declaration like void setSomething(const Something& &something)
for a member of type Something&
, which is a syntax error.
One of the most powerful refactorings is possibly the extraction of a block of code into a new function/method.
Would it be possible to add this feature?
The 'Add Definition' commands sometimes don't properly reveal the inserted function (The editor doesn't scroll all the way to where the function was inserted). This seems to only happen for large files with a lot of DocumentSymbols
, and it is unclear why. I've spent a good amount of time trying to debug and fix this problem, and it doesn't seem to be a problem in the C-mantic code. The Range
passed to TextEditor.revealRange()
is always correct, but the editor doesn't always scroll to that range. The editor does scroll in the direction of the function, but only a little bit. I haven't found consistent setup to reproduce the problem, other than that it only happens for large files. Also, this happens for ms-vscode.cpptools
, clangd
, and ccls
, so it doesn't seem to be a problem with the language server. I'm considering opening an issue with vscode. If I do I'll link it here.
Hi there!
I'm investigating using your plugin for improved productivity in C++ in a cloud environment - gitpod.io.
However, gitpod only supports extensions that are uploaded to the openvsx registry [1] [2].
Do you have any plans on adding this extension to Open VSX Registry? [3]
Cheers!
Links
1 OpenVSX registry - https://open-vsx.org/
2 GitPod FAQ on VS Code Extension support - https://www.gitpod.io/docs/references/ides-and-editors/vscode-extensions#where-do-i-find-extensions
3 How to register at OpenVSX - https://github.com/eclipse/openvsx/wiki/Publishing-Extensions
I've noticed a regression in the amount of time it takes to generate getters and setters (even with C_mantic.cpp.resolveTypes
disabled). It used to be very quick, and now it seems to hang for a couple seconds (sometimes more) before they are generated. I'm not sure what could be causing this, since it's the only feature that is having this problem. This "slowness" is also independent of the language server, so it must be something in the C-mantic code (In general, clangd
is much faster than cpptools
, which is usually a good indication of whether a problem exists with C-mantic or the language server. This is not the case here).
For reference, the GIF in the README was real-time performance of generating a getter and setter, and that was with C_mantic.cpp.resolveTypes
enabled. Trying it on the same code now takes 2-3 seconds on my machine. With C_mantic.cpp.resolveTypes
disabled it's about 1-2 seconds, still noticeably slower.
\\ .cpp file
namespace NamespaceA {
using NamespaceB::RetType;
RetType ClassA::func() {
...
}
}
\\ .hpp file
namespace NamespaceA {
class ClassA {
public:
NamespaceB::RetType func();
}
}
If I want to update the function declaration from the .cpp PoV then it will remove NamespaceB
, but it will be incorrect from header file PoV.
Please add UUID as a header guard component.
Also see https://github.com/AkiraMiyakoda/cppIncludeGuard
C-mantic experiences some problems with overloaded functions when using cpptools. This is a result of how cpptools provides definitions for overloaded functions. For instance, say you have an overload set of 4 functions, 1 of which is already defined, the others are not. If you try 'Go to Definition' on any of the undefined declarations, cpptools will go to the overload that is defined (which is not the same function). This affects C-mantic, as you will not be able to use 'Add Definition' on any of the undefined functions, since it thinks a definitions already exists (since cpptools is incorrectly providing a definition for it). I'm not sure what the best way to handle this is, besides getting cpptools to change this behavior, because frankly, it's the job of the language server to understand overloads and know that one function is different from another.
Hello BigBahss,
This tool saved me a lot of pain, but how about if one can right click on a class and move all implementations from header to source file directly instead of clicking one at a time? I tried using multiple cursors but the action is only applied to the first cursor.
Something like this: in Visual Studio: https://docs.wholetomato.com/default.asp?W684
Thanks,
Utsav
Hello. I am a Korean developer who loves programming. After installing the extension cmantic, if i compile using gcc/g++ in the terminal, rg.exe runs infinitely and uses the cpu abnormally. To be honest, I'm not sure which extension conflicts with this problem, but below are extensions related to C/C++ that I use.
C snippets
C/C++ Extension Pack
C/C++
CMake
CMake Tools
C-mantic (here)
I hope this gets resolved and I'm wondering if anyone else has the same problems as me.
This is article that i wrote about problem
https://pgh268400.tistory.com/551
Hi BigBahss,
thank you for making this extension :D
One feature I'd love to see is the possibility to automatically create Constructors with either no arguments, required arguments or all arguments with initializer lists.
This would be a very neat feature. Add a member, forget it in an initializer list and get an option to add it, no more going through the list and find the one that is missing.
Not sure how everyone is doing the formatting, we use clang-format on save, so just pasting it anywhere in the list would be fine as it would get moved accordingly on save.
It would be nice to add completion suggestions for the 'Add Include' command. Although, this doesn't seem straightforward with the current implementation that uses the input box.
One idea is that 'Add Include' could open a small to the spot where the new include would be added, in which case auto-completions would be provided automatically by other extensions. I think I like this idea, except in order to place includes based on if they are a system header (CodeLens
#include <...>
) or a project header (#include "..."
) it would probably require 2 different commands in order to automatically place the starting #include
prompt in the right spot. I'm not a big fan of requiring 2 different commands since it seems a little clunky, but (counterintuitively) this might be mitigated by having a third command that just goes to the end largest block of includes, not caring if they are system or project headers.
Also, I have no experience with the , so I don't know how easy this would be. Suggestions on how to implement this are welcome.CodeLens
api
It seems like 'Add Definition' has had a regression of how it adjusts whitespace alignment for multi-lined declarations. In particular, when it removes leading keywords (like virtual
, static
, etc.), the definition in will no longer be aligned properly.
I would like having an refactoring option to update parameter name in function declaration once I change it in definition.
When using \r\n
line endings, a lot of excess lines appear.
It turns out, that there is a bug in the formatting function, adding \t
in between and after \r\n
line endings.
This results in vscode replacing \r
and \n
into \r\n
respectivly, so the total replacement will be \r\n\t\r\n\t
instead of \r\n\t
I have created a pull-request, as a proposal to fix this issue.
Type: Bug
open c++ file
Extension version: 0.9.0
VS Code version: Code 1.87.2 (863d2581ecda6849923a2118d93a088b0745d9d6, 2024-03-08T15:14:59.643Z)
OS version: Linux x64 5.4.0-144-generic
Modes:
Item | Value |
---|---|
CPUs | Intel(R) Core(TM) i3-10110U CPU @ 2.10GHz (4 x 2999) |
GPU Status | 2d_canvas: enabled canvas_oop_rasterization: disabled_off direct_rendering_display_compositor: disabled_off_ok gpu_compositing: enabled multiple_raster_threads: enabled_on opengl: enabled_on rasterization: enabled raw_draw: disabled_off_ok skia_graphite: disabled_off video_decode: enabled video_encode: disabled_software vulkan: disabled_off webgl: enabled webgl2: enabled webgpu: disabled_off |
Load (avg) | 5, 5, 6 |
Memory (System) | 7.47GB (3.63GB free) |
Process Argv | . --crash-reporter-id c0a30e7b-e08e-4e61-93bf-39b3792e40bf |
Screen Reader | no |
VM | 0% |
DESKTOP_SESSION | cinnamon |
XDG_CURRENT_DESKTOP | X-Cinnamon |
XDG_SESSION_DESKTOP | cinnamon |
XDG_SESSION_TYPE | x11 |
vsliv368:30146709
vspor879:30202332
vspor708:30202333
vspor363:30204092
vswsl492:30256859
vscorecescf:30445987
vscod805:30301674
binariesv615:30325510
vsaa593cf:30376535
py29gd2263:30899288
c4g48928:30535728
azure-dev_surveyone:30548225
962ge761:30959799
pythongtdpath:30769146
welcomedialog:30910333
pythonidxpt:30866567
pythonnoceb:30805159
asynctok:30898717
pythontestfixt:30902429
pythonregdiag2:30936856
pyreplss1:30897532
pythonmypyd1:30879173
pythoncet0:30885854
2e7ec940:31000449
pythontbext0:30879054
accentitlementsc:30995553
dsvsc016:30899300
dsvsc017:30899301
dsvsc018:30899302
cppperfnew:31000557
d34g3935:30971562
fegfb526:30981948
bg6jg535:30979843
ccp2r3:30993541
dsvsc020:30976470
pythonait:31006305
gee8j676:31009558
dsvsc021:30996838
gd77d436:30999572
It would be very useful if alternative naming styles would be supported. Currently the extension always uses getSomething
and setSomething
, but other styles are used as well, for instance get_something
/set_something
.
Currently, C-mantic does not account for raw string literals. This might impact parsing if they are present, and support should be added for them.
There is a file1.cpp
and a file1.h
in my workspace.
For normal function, it works fine as follows:
But the plugin only provides Add definition in this file
for the template function:
The c++ intellisense plugin I used was clangd.
Thanks for your efforts.
There is a bug when using Add Declaration
on a member function of a class template, the template statements for parent class(es) will be added to the declaration. This is an error since those template statements exist on the class definitions.
How about the ability to add a suppression pragmas around selected rows?
If current row is already in a block a new suppression is added and we go to point 4
Hi,
Using with the default Microsoft C++ extension; I think cpptools is installed and working properly (1.19.9), I can see the process in top - but all I see in the logs output from C-mantic is the below:
[18:00:48 Info] C-mantic extension activated.
[18:01:19 Warn] No language server detected after 30 seconds.
Anything I can do to find out more? Would it also be possible to log more when the server isn't detected?
Thanks!
Currently, 'Move Definition' is basically a copy-and-paste after smart-placement is determined. It does not account for changes in scope at the target position. For instance, if the definition exists within a namespace block, and the target position is not within that same namespace, the definition will be lacking scope-resolution.
For instance:
namespace foo {
int bar() {
return 42;
}
}
If bar is moved to a position that is not within namespace foo
, the definition should become:
int foo::bar() {
return 42;
}
This is something I did not account for when I created the command, and it is being worked on. This will probably be fixed in the next feature release which will add moving a definition into/out of a class body (which also needs to account for the same thing, but with the class name).
'Add definition in this file' always add the 'inline' keyword.
For header declarations, where the definition will be placed also in the header, this is correct.
But if the declaration is in the implementation file, it is not required.
In general, it would be nice to add an option to not adding the inline keyword if the declaration does not contain 'inline', so we can control if it should be generated or not.
By the way, great tool! vscode absolutely needed something like this!
Currently, C-mantic's template support is incomplete. For instance, adding definitions for member functions of a class template will generate incorrect code. The definitions will be missing the template statement, and the scope resolution will be missing the template parameter(s). Additionally, 'Add Definition' should not allow adding definitions in source files for function templates (I've realized that the 'add_definition.gif' in the readme does this, which is more embarrassing than anything).
when I define a static function in source file, then I do a "add declaration" refactor, seems "static" keyword will loss.
Right now the getters and setters are generated with names like foo
and setFoo
, respectively.
My workplace requires the "get" prefix, so it would be nice to be able to generate getters with names like getFoo
.
The members are initialized in the order they appear in the header (if I'm not mistaken). So ordering the initializer list to reflect the header would be nice to tidy things up.
Of course this would need a detection, that the list is not in order in the first place.
As a feature request, it would be helpful if the Header Guard format could also have variables for the path relative to its source git (or other source control repo) repo. So something like ${REPO_REL_PATH}
. Thanks!
I can imagine that some users might want to turn off the light-bulb menu for C-mantic, because it might be annoying. Of course, the light-bulb menu can be turned off entirely in VS Code's settings, but this affects all extensions and might not be what the user is looking for.
VS Code's API does not appear to offer extensions a way to provide refactorings without them being auto-suggested in the light-bulb menu. Ideally, the user could control whether refactorings are suggested, while still being available in the Refactor...
menu either way. It seems like the best that could be done would to to disable refactorings entirely for users that just want to use the commands directly.
A potential workaround I can think of would be to change provided refactorings into source actions, which would then be available in the Source Actions...
menu and would not be suggested in the light-bulb menu. That feels kind of messy though. Maybe this is a non-issue though, and users that want to disable refactorings wouldn't care if they are also removed from the Refactor...
menu.
I'd love to see a feature which generates all cases for a switch statement for all enumeration values.
So if you have:
enum class IicChannel
{
Iic1,
Iic2,
Iic3
};
And write something along the lines of:
IicChannel channel = GetChannel();
switch (channel)
{
}
Have a hint to generate all case statements like:
switch (channel)
{
case IicChannel::Iic1:
/* code */
break;
case IicChannel::Iic2:
/* code */
break;
case IicChannel::Iic3:
/* code */
break;
default:
break;
}
This would be awesome, I used that feature on ReSharper a lot. Not sure if the parsing you are doing is extensive enough to be able to do this.
I was testing on ccls
and I noticed that Add Definition
isn't working for constructors. The reason is that when invoking Go to Definition
on an undefined constructor, ccls
goes to the name of the class itself. I'm thinking this must be a regression in ccls
, because I'm 99% sure I've tested this before and it was working.
I found #11, but it does not work for me.
my code is like this:
class WatchData {
public:
std::string GetSubscribeName() const { return SubscribeName; }
void SetSubscribeName(const std::string &subscribeName) {
mSubscribeName = subscribeName;
}
private:
std::string mSubscribeName;
};
however, when use the plugin, i cannot generate code above.
Is there any way to generate code for customization
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.