VS Code C++ Parameter Autocomplete - c++

In VS Code, with the C++ extension, is there any way I can get the parameter names for functions to be filled out automatically after e.g. selecting a function name suggested by intellisense? The parameters should then be filled out as if they were a snippet. This feature is common in several IDEs, such as Eclipse.

I think this is a perfectly valid question and nothing to do with IDE-like features as some are suggesting in the comments.
Short answer is No.
VS Code's C/C++ extension will not expand the autocompletion feature to the argument list of a function.
The more involved answer is that the authors of the C/C++ extension could do so but for some reason (probably a good one) have chosen not to.
The autocomplete feature is actually handled by the Language Server for C/C++. A Language Server is an implementation of the Language Server Protocol (LSP) which is simply a way to provide programming language-specific features for multiple code editors / IDEs.
The LSP, written by Microsoft originally for VSCode, absolutely permits such types of completion. After all, that is how snippets are handled. If you have a look at LSP's specification page you will see this bit
insertText is just a string so theoretically the server could pass the function name + argument list in the format of a snippet, set the variable InsertTextFormat == 2, marking it as a snippet and then pressing Tab would autocomplete to exactly what you want.
Here is an example of how it looks like (implemented in our Fortran language server)
You might want to open a feature request/ask the question in their repo. They will probably have a better answer as to why it is the way it is. If I had to guess I would say that it is related to overloading.

Related

What are 'user keywords' in the codeblocks IDE?

I've just noticed something interesting in the codeblocks IDE, via the editor settings > syntax highlighting, Saying 'User keywords', I am aware that they are reserved keywords such as for, int, signed, etc but what are these supposed to be?
My best guess is that it really means 'symbolic constants'. Google and Stack overflow doesn't seem to give me any information on what they are. However I do know that you can't really create your own keywords because they are part of the C/C++ language.
Any ideas? just curious.
However I do know that you can't really create your own keywords because they are part of the C/C++ language
You can't create your own in such a way that a compiler will understand. You need to separate what your IDE does from what your compiler does. The IDE has a facility for displaying keywords with a special color. That's easy to understand. But CodeBlocks doesn't rely on the compiler you use to "figure out" a token is a keyword. It has its own processor for this.
So what happens when you update your compiler and it supports a newer version of the language? Your IDE can't magically follow suit. It won't support those new keywords out of the box. That's why it allows you to specify "user keywords". So you may see the new keywords highlighted.
You are right, you can not create new keywords in C++. As you noticed this option is for syntax highlighting. You can enter there any words if you want to highlight them in the code editor. The code editor will highlight your words to make it easier to identify them in the code. Highlighting or in other words colorizing is the only purpose of that settings.
An example of a user keyword might be emit when invoking a Qt signal. Although qt signals are technically functions, they are meta compiled and are designed to mutate state outside their class scope. That's why many developers like to explicitly decorate them.
Typically emit evaluates macro expands to nothing
See this question for an explanation on how emit works:
Using emit vs calling a signal as if it's a regular function in Qt
Often compilers will have their own keywords that aren't officially in the standard. For example, GCC (C++) supports numerous C11 keywords like __thread or __restrict. You might need to manually add these to get syntax highlighting.

How to model noexcept, override, final or any further C++ specifier in Visual Paradigm?

Scenario:
I am creating the design for a software in UML2, using Visual Paradigm as a tool. The idea is to be as close as possible of the C++11 language, for code generation and documentation.
Current state of the art:
In Visual-Paradigm, for C++ special specifiers, I followed the next steps (VP 12):
Windows->Configuration->Configure Programming Language
Selected C++ and Accept (Ok).
Any function in a class can now be set to virtual or const by:
right-click -> Code details ->
But, I cannot found C++11 details, so I wonder if there is a way to add them or not.
Question
My question is: Is it a way to add those specifiers to code detail?
An other alternative would be to use stereotypes, but the result is not as good, specially for code generation.
Visual paradigm has no support for C++11, so it is not possible currently.
From the answer from the VPP support, it seem they have this feature as an already planned feature, so we could expect this in following version (14?).
Until then, the best alternative I found is just to set a stereotype and manage it manually.

C++ Intellisense doesn't work (not even Ctrl+Space), no function name, no parameter list, nothing

I have recently install the C++ in order to re-learn the language (have done some small project on it). One thing that really annoys me is that the auto-complete function when implementation doesn't work anymore.
More specifically the auto-completing of the parameters and function name. I have already declared my class and functions in respective headers. Though my memory is a bit hazy, I remember back in 2008, once you enter the name in the cpp file, it will automatically give you a dropdown box for the respective parameters.
Then I have searched for forums and pages for possible solution and was informed that the intellisense feature was removed from the C++ environment in the new VS 2010 (why?). But one can retrieve the parameter list by:
(1) checking the 'Tool -> Text Editor -> C++ -> Autolist Members" and also in the advanced tab to see if the feature has been disabled.
(2) to use Ctrl-Space while completing the statement.
I have tried both of these and they don't work (and I have read some the forums that the ctrl+space should at least work in some degree). Declaration should be correct because when I am defining the function and right-click and name to "Go to Declaration" it will highlight the declaration in the header file (where the whole parameter list is provided).
And the Ctrl+J would show me that indeed VS recognize the function declaration.
I would like to not use the 3rd party software such as (visual assist X), but I am running out of options.
Thank you so much in advance.
Make sure you are not targeting the .NET framework (compiler option /clr )
Otherwise it should work for all native C++ programs

Are there any lint tools for C and C++ that check formatting?

I have a codebase that is touched by many people. While most people make an effort to keep the code nicely formatted (e.g. consistent indentation and use of braces), some don't, and even those that do can't always do it because we all use different editors, so settings like spaces vs. tabs are different.
Is there any standard lint tool that checks that code is properly formatted, but doesn't actually change it (like indent but that returns only errors and warnings)?
While this question could be answered generally, my focus is on C and C++, because that's what this project is written in.
Google uses cpplint. This is their style guide.
The Linux kernel uses a tool that does exactly this - it's called checkpatch. You'd have to modify it to check your coding standards rather than theirs, but it could be a good basis to work from. (It is also designed for C code rather than C++).
Take a look at Vera++, it has a number of rules already available but the nice part is that you can modify them or write your own.
There are several programs that can do formatting for you automatically on save (such as Eclipse). You can have format settings that everyone can use ensuring the same formatting.
It is also possible to automatically apply such formatting when code is committed. When you use SVN, the system to do this is called svn hooks. This basically starts a program to process (or check and deny) the formatting when a commit happens.
This site explains how you can make your own. But also ones already exist to do this.

C++ Developer Tools: The Dark Areas [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 5 years ago.
Improve this question
While C++ Standards Committee works hard to define its intricate but powerful features and maintain its backward compatibility with C, in my personal experience I've found many aspects of programming with C++ cumbersome due to lack of tools.
For example, I recently tried to refactor some C++ code, replacing many shared_ptr by T& to remove pointer usages where not needed within a large library. I had to perform almost the whole refactoring manually as none of the refactoring tools out there would help me do this safely.
Dealing with STL data structures using the debugger is like raking out the phone number of a stranger when she disagrees.
In your experience, what essential developer tools are lacking in C++?
My dream tool would be a compile-time template debugger. Something that'd let me interactively step through template instantiations and examine the types as they get instantiated, just like the regular debugger does at runtime.
In your experience, what essential developer tools are lacking in C++?
Code completion. Seriously. Refactoring is a nice-to-have feature but I think code completion is much more fundamental and more important for API discoverabilty and usabilty.
Basically, tools that require any undestanding of C++ code suck.
Code generation of class methods. When I type in the declaration you should be able to figure out the definition. And while I'm on the topic can we fix "goto declaration / goto definition" always going to the declaration?
Refactoring. Yes I know it's formally impossible because of the pre-processor - but the compiler could still do a better job of a search and replace on a variable name than I can maually. You could also syntax highlight local, members and paramaters while your at it.
Lint. So the variable I just defined shadows a higher one? C would have told me that in 1979, but c++ in 2009 apparently prefers me to find out on my own.
Some decent error messages. If I promise never to define a class with the same name inside the method of a class - do you promise to tell me about a missing "}". In fact can the compiler have some knowledge of history - so if I added an unbalanced "{" or "(" to a previously working file could we consider mentioning this in the message?
Can the STL error messages please (sorry to quote another comment) not look like you read "/dev/random", stuck "!/bin/perl" in front and then ran the tax code through the result?
How about some warnings for useful things? "Integer used as bool performance warning" is not useful, it doesn't make any performance difference, I don't have a choice - it's what the library does, and you have already told me 50 times.
But if I miss a ";" from the end of a class declaration or a "}" from the end of a method definition you don't warn me - you go out of your way to find the least likely (but theoretically) correct way to parse the result.
It's like the built in spell checker in this browser which happily accepts me misspelling wether (because that spelling is an archaic term for a castrated male goat! How many times do I write about soprano herbivores?)
How about spell checking? 40 years ago mainframe Fortran compilers had spell checking so if misspelled "WRITE" you didn't come back the next day to a pile of cards and a snotty error message. You got a warning that "WRIET" had been changed to WRITE in line X. Now the compiler happily continues and spends 10mins building some massive browse file and debugger output before telling you that you misspelled prinft 10,000 lines ago.
ps. Yes a lot of these only apply to Visual C++.
pps. Yes they are coming with my medication now.
If talking about MS Visual Studio C++, Visual Assist is a very handy tool for code completition, some refactorings - e.g. rename all/selected references, find/goto declaration, but I still miss the richness of Java IDEs like JBuilder or IntelliJ.
What I still miss, is a semantic diff tool - you know, one which does not compare the two files line-by-line, but statements/expressions. What I've found on the internet are only some abandoned tries - if you know one, please write in comment
The main problem with C++ is that it is hard to parse. That's why there are so very few tools out there that work on source code. (And that's also why we're stuck with some of the most horrific error messages in the history of compilers.) The result is, that, with very few exceptions (I only know doxygen and Visual Assist), it's down to the actual compiler to support everything needed to assist us writing and massaging the code. With compilers traditionally being rather streamlined command line tools, that's a very weak foundation to build rich editor support on.
For about ten years now, I'm working with VS. meanwhile, its code completion is almost usable. (Yes, I'm working on dual core machines. I wouldn't have said this otherwise, wouldn't I?) If you use Visual Assist, code completion is actually quite good. Both VS itself and VA come with some basic refactoring nowadays. That, too, is almost usable for the few things it aims for (even though it's still notably less so than code completion). Of course, >15 years of refactoring with search & replace being the only tool in the box, my demands are probably much too deteriorated compared to other languages, so this might not mean much.
However, what I am really lacking is still: Fully standard conforming compilers and standard library implementations on all platforms my code is ported to. And I'm saying this >10 years after the release of the last standard and about a year before the release of the next one! (Which just adds this: C++1x being widely adopted by 2011.)
Once these are solved, there's a few things that keep being mentioned now and then, but which vendors, still fighting with compliance to a >10 year old standard (or, as is actually the case with some features, having even given up on it), never got around to actually tackle:
usable, sensible, comprehensible compiler messages (como is actually pretty good, but that's only if you compare it to other C++ compilers); a linker that doesn't just throw up its hands and says "something's wrong, I can't continue" (if you have taught C++ as a first language, you'll know what I mean); concepts ('nuff said)
an IO stream implementation that doesn't throw away all the compile-time advantages which overloading operator<<() gives us by resorting to calling the run-time-parsing printf() under the hood (Dietmar Kühl once set out to do this, unfortunately his implementation died without the techniques becoming widespread)
STL implementations on all platforms that give rich debugging support (Dinkumware is already pretty good in that)
standard library implementations on all platforms that use every trick in the book to give us stricter checking at compile-time and run-time and more performance (wnhatever happened to yasli?)
the ability to debug template meta programs (yes, jalf already mentioned this, but it cannot be said too often)
a compiler that renders tools like lint useless (no need to fear, lint vendors, that's just wishful thinking)
If all these and a lot of others that I have forgotten to mention (feel free to add) are solved, it would be nice to get refactoring support that almost plays in the same league as, say, Java or C#. But only then.
A compiler which tries to optimize the compilation model.
Rather than naively include headers as needed, parsing them again in every compilation unit, why not parse the headers once first, build complete syntax trees for them (which would have to include preprocessor directives, since we don't yet know which macros are defined), and then simply run through that syntax tree whenever the header is included, applying the known #defines to prune it.
It could even be be used as a replacement for precompiled headers, so every header could be precompiled individually, just by dumping this syntax tree to the disk. We wouldn't need one single monolithic and error-prone precompiled header, and would get finer granularity on rebuilds, rebuilding as little as possible even if a header is modified.
Like my other suggestions, this would be a lot of work to implement, but I can't see any fundamental problems rendering it impossible.
It seems like it could dramatically speed up compile-times, pretty much rendering it linear in the number of header files, rather than in the number of #includes.
A fast and reliable indexer. Most of the fancy features come after this.
A common tool to enforce coding standards.
Take all the common standards and allow you to turn them on/off as appropriate for your project.
Currently just a bunch of perl scrips usullay has to supstitute.
I'm pretty happy with the state of C++ tools. The only thing I can think of is a default install of Boost in VS/gcc.
Refactoring, Refactoring, Refactoring. And compilation while typing. For refactorings I am missing at least half of what most modern Java IDEs can do. While Visual Assist X goes a long way, a lot of refactoring is missing. The task of writing C++ code is still pretty much that. Writing C++ code. The more the IDE supports high level refactoring the more it becomes construction, the more mallable the structure is the easier it will be to iterate over the structure and improve it. Pick up a demo version of Intellij and see what you are missing. These are just some that I remember from a couple of years ago.
Extract interface: taken a view classes with a common interface, move the common functions into an interface class (for C++ this would be an abstract base class) and derive the designated functions as abstract
Better extract method: mark a section of code and have the ide write a function that executes that code, constructing the correct parameters and return values
Know the type of each of the symbols that you are working with so that not only command completion can be correct for derived values e.g. symbol->... but also only offer functions that return the type that can be used in the current expression e.g. for
UiButton button = window->...
At the ... only insert functions that actually return a UiButton.
A tool all on it's own: Naming Conventions.
Intelligent Intellisense/Code Completion even for template-heavy code.
When you're inside a function template, of course the compiler can't say anything for sure about the template parameter (at least not without Concepts), but it should be able to make a lot of guesses and estimates. Depending on how the type is used in the function, it should be able to narrow the possible types down, in effect a kind of conservative ad-hoc Concepts. If one line in the function calls .Foo() on a template type, obviously a Foo member method must exist, and Intellisense should suggest it in the rest of the function as well.
It could even look at where the function is invoked from, and use that to determine at least one valid template parameter type, and simply offer Intellisense inside the function based on that.
If the function is called with a int as a template parameter, then obviously, use of int must be valid, and so the IDE could use that as a "sample type" inside the function and offer Intellisense suggestions based on that.
JavaScript just got Intellisense support in VS, which had to overcome a lot of similar problems, so it can be done. Of course, with C++'s level of complexity, it'd be a ridiculous amount of work. But it'd be a nice feature.