Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow merge of C_Cpp_Properties & configuration provider. #8174

Conversation

willson556
Copy link
Contributor

@willson556 willson556 commented Sep 19, 2021

Partially resolves #6909 (doesn't yet work with compile_commands.json,
just custom configuration providers).

Adds a configuration that enables the include paths, defines, and forced
includes from c_cpp_properties.json to be merged with those provided
by a configuration provider.

This is especially helpful for projects that use unsupported compilers
as defines/includePaths/forcedIncludes can be provided as shims for
intellisense.

Adds a configuration that enables the include paths, defines, and forced
includes from `c_cpp_properties.json` to be merged with those provided
by a configuration provider.

This is especially helpful for projects that use unsupported compilers
as defines/includePaths/forcedIncludes can be provided as shims for
intellisense.
@willson556 willson556 force-pushed the feature/MergeC_CppPropertiesWithConfigurationProvider branch from 77322f5 to c6f97a0 Compare September 19, 2021 03:28
@gerhardol
Copy link

A step in the right direction I guess, but not helping in my use case as the cpp/cmake provider has no information (CMake could generate compile_commands.json, that would be useful if it could be merged),
Code looks reasonable.

@michelleangela
Copy link
Contributor

michelleangela commented Sep 20, 2021

The new property mergeConfigurations in c_cpp_properties.json will need to be added to the IntelliSense configuration UI (use command C/C++: Edit configurations (UI) to view UI) as well. under the Advanced section, right after compile commands property.

See https://github.com/microsoft/vscode-cpptools/blob/main/Extension/ui/settings.html and the UI element for "see Browse: limit symbols to included headers for example of creating a boolean checkbox. Also add to corresponding TS file https://github.com/microsoft/vscode-cpptools/blob/main/Extension/ui/settings.ts.

Also add this new property to https://github.com/microsoft/vscode-cpptools/blob/main/Extension/src/LanguageServer/settingsPanel.ts so that the UI will be updated with values from c_cpp_properties.json.

How to localize string in HTML.
To localize HTML content, the following 2 attributes are used on HTML nodes:

data-loc-id
Specifying a unique string key value using this attribute causes the content of the node to be localized associated with that key

data-loc-id-<attribute-name>
Specifying a unique string key value using this attribute causes the specified attribute of this node to be localized. For example, to localize the title attribute of a node, use: data-loc-id-title="some.title.id"

The following is an example of a span with localized content, containing a sub-node with a localized title attribute.

<span data-loc-id="switch.to.json">Switch to the <a href="command:C_Cpp.ConfigurationEditJSON" title="Edit configurations in JSON file" data-loc-id-title="edit.configurations.in.json">c_cpp_properties.json</a> file by clicking on the file link or using the command:</span>

Child nodes are not included when content of a parent node is localized. In the outer nodes of the above example, the following string will be extracted for localization:

"Switch to the {0} file by clicking on the file link or using the command:"

@sean-mcmanus
Copy link
Collaborator

sean-mcmanus commented Sep 21, 2021

Can a "C_Cpp.default.mergeConfigurations" setting be added? See https://github.com/microsoft/vscode-cpptools/pull/7845/files for an example; however, that PR has been updated to use "markdownDescription" instead of "description".

Extension/ui/settings.html Outdated Show resolved Hide resolved
const fileConfiguration: configs.Configuration | undefined = this.configuration.CurrentConfiguration;
if (fileConfiguration?.mergeConfigurations ?? false) {
configs.forEach(config => {
fileConfiguration?.includePath?.forEach(p => {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does anybody have any idea why these lint errors exist? It seems like a false positive to me but similar code in other places in this file isn't causing this error.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sean-mcmanus do you know about these lint errors?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I'm not sure why the linter is giving these errors, but they appear to be fixable via changing the forEach calls with for loops, e.g. for (const p in fileConfiguration.includePath) {

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Before 621ca46, I was still getting an unused expression error from the linter on line 1825 on the old side of that commit.

Seems the ?. expressions might confuse the linter?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, the issue seems to be eslint/eslint#12642.

@willson556
Copy link
Contributor Author

Can a "C_Cpp.default.mergeConfigurations" setting be added? See https://github.com/microsoft/vscode-cpptools/pull/7845/files for an example; however, that PR has been updated to use "markdownDescription" instead of "description".

Added

Extension/package.json Outdated Show resolved Hide resolved
const fileConfiguration: configs.Configuration | undefined = this.configuration.CurrentConfiguration;
if (fileConfiguration?.mergeConfigurations ?? false) {
configs.forEach(config => {
fileConfiguration?.includePath?.forEach(p => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sean-mcmanus do you know about these lint errors?

Extension/src/LanguageServer/configurations.ts Outdated Show resolved Hide resolved
@sean-mcmanus sean-mcmanus added this to the 1.7.0-insiders3 milestone Sep 29, 2021
Copy link
Collaborator

@sean-mcmanus sean-mcmanus left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See Michelle's comment.

@michelleangela michelleangela merged commit a62acdb into microsoft:main Oct 5, 2021
@michelleangela
Copy link
Contributor

@willson556 these changes are now merged and will be available in 1.7.0-insiders3. Thank you for your work and contribution to the C++ extension.

@willson556 willson556 deleted the feature/MergeC_CppPropertiesWithConfigurationProvider branch October 5, 2021 15:31
@willson556
Copy link
Contributor Author

Thank you @michelleangela and @sean-mcmanus for taking the time to review and merge these changes!

This is going to significantly improve our experience with IAR and VSCode!

@github-actions github-actions bot locked and limited conversation to collaborators Nov 19, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
5 participants