microsoft / vscode-cpptools

Official repository for the Microsoft C/C++ extension for VS Code.
Other
5.44k stars 1.53k forks source link

Angle bracket matching #1903

Open sean-mcmanus opened 6 years ago

sean-mcmanus commented 6 years ago

It would be nice if angle bracket matching worked when working with deeply nested templates. I suspect this is impossible to do with the regular expression mechanism due to the difficulty of parsing the angle brackets as an operator versus template arg.

bobbrow commented 6 years ago

Yes, this was cut from TypeScript for similar reasons (https://github.com/Microsoft/vscode/issues/13295). The language-configuration.json isn't smart enough to be able to handle these properly. We'd need some other mechanism to do it.

geoffrey4444 commented 4 years ago

Just wondering if anything has changed in the past two years that might make it possible to address this? I do a lot of template metaprogramming in VSCode, and matching the angled brackets would be very nice to have.

bobbrow commented 4 years ago

No. Unfortunately, no "provider" has been added to allow our extension to do this. But perhaps this could be done with decorators. Please add a 👍 to the first post in the issue to add your vote for us to investigate. If it gets enough votes, we will look into it.

github-actions[bot] commented 3 years ago

This feature request has received enough votes to be added to our backlog.

rgosens2 commented 2 years ago

As long as there is no solution you can always turn it on (and accept the issues). To get angle bracket pairing in vscode to work, change: /Applications/Visual Studio Code.app/Contents/Resources/app/extensions/cpp/language-configuration.json See: https://stackoverflow.com/questions/62068072/how-to-activate-automatic-angle-bracket-pairing-completion-in-visual-studio Works fine in most contexts.

Screenshot 2022-01-03 at 13 05 01

mrx23dot commented 1 month ago

Can we include the solution above to the master branch?

bobbrow commented 1 month ago

No, it will fail for things like: if (x < 0 || x > 10). We're not satisfied with a regex implementation of this feature.

mrx23dot commented 1 month ago

A quick hack for that would be to check file extension (.h .hpp) and ignore the line if there are any parentheses.

bobbrow commented 1 month ago

The file extension doesn't matter. You can write function bodies in the header file too. There are many cases where a conditional can trigger this without parentheses on the line. I was just giving a single example. Here's another: bool b = x < 0 || x > 10;