microsoft / vscode-arduino

Visual Studio Code extension for Arduino
Other
1.17k stars 221 forks source link

C/C++ Configuration Auto-generator Triggers If Path Separators Are Edited #1211

Open GaiaBlitz opened 3 years ago

GaiaBlitz commented 3 years ago

I refer to PR #1183 which provided the feature of auto-generating c_cpp_configuration.json to the vscode-arduino extension.

The auto-generation of the config file is a welcome one and saves effort in preparing an Arduino workspace. However, editing the config file after its generation can sometimes lead to the auto-generator triggering on (re-)startup, leading to duplicate/redundant string values within the file.

Version Information

OS used: Windows 10 (10.0.19042) VS Code: 1.54.1 (user setup) vscode-arduino: 0.3.5 (master) Relevant for later report on steps taken as well as suggestion: ms-vscode.cpptools: 1.2.2

Configuration File Used

I am including the file as a code block below:

{
    "configurations": [
        {
            "name": "Win32",
            "includePath": [
                "${workspaceFolder}/**",
                "C:\\Users\\jiaju\\AppData\\Local\\Arduino15\\packages\\arduino\\hardware\\avr\\1.8.3\\**",
                "C:\\Program Files (x86)\\Arduino\\libraries\\**",
                "C:\\Users\\jiaju\\Documents\\Arduino\\libraries\\**",
                "C:\\Users\\jiaju\\AppData\\Local\\Arduino15\\packages\\arduino\\tools\\**"
            ],
            "defines": [
                "_DEBUG",
                "UNICODE",
                "_UNICODE",
                "USBCON"
            ],
            "cStandard": "c11",
            "cppStandard": "c++11",
            "compilerPath": "C:/Program Files (x86)/Arduino/hardware/tools/avr/bin/avr-gcc.exe",
            "intelliSenseMode": "gcc-x64",
            "forcedInclude": [
                "C:\\Users\\jiaju\\AppData\\Local\\Arduino15\\packages\\arduino\\hardware\\avr\\1.8.3\\cores\\arduino\\Arduino.h"
            ]
        }
    ],
    "version": 4
}

Steps Taken

  1. Using the find and replace function (Ctrl+H) I replaced all instances of \\ with /. The changed parts of the file would be
            "includePath": [
                "${workspaceFolder}/**",
                "C:/Users/jiaju/AppData/Local/Arduino15/packages/arduino/hardware/avr/1.8.3/**",
                "C:/Program Files (x86)/Arduino/libraries/**",
                "C:/Users/jiaju/Documents/Arduino/libraries/**",
                "C:/Users.jiaju/AppData/Local/Arduino15/packages/arduino/tools/**"
            ],

    and

            "forcedInclude": [
                "C:/Users/jiaju/AppData/Local/Arduino15/packages/arduino/hardware/avr/1.8.3/cores/arduino/Arduino.h"
            ]
  2. I saved the configuration file without any renaming.
  3. I closed the VS Code window and opened it again.
    • I expected to not find any changes to the configuration file, however I found the following in the sections that I changed:
          "includePath": [
              "${workspaceFolder}/**",
              "C:/Users/jiaju/AppData/Local/Arduino15/packages/arduino/hardware/avr/1.8.3/**",
              "C:/Program Files (x86)/Arduino/libraries/**",
              "C:/Users/jiaju/Documents/Arduino/libraries/**",
              "C:/Users.jiaju/AppData/Local/Arduino15/packages/arduino/tools/**",
              "C:\\Users\\jiaju\\AppData\\Local\\Arduino15\\packages\\arduino\\hardware\\avr\\1.8.3\\**",
              "C:\\Program Files (x86)\\Arduino\\libraries\\**",
              "C:\\Users\\jiaju\\Documents\\Arduino\\libraries\\**",
              "C:\\Users\\jiaju\\AppData\\Local\\Arduino15\\packages\\arduino\\tools\\**"
          ],
          "forcedInclude": [
              "C:/Users/jiaju/AppData/Local/Arduino15/packages/arduino/hardware/avr/1.8.3/cores/arduino/Arduino.h",
              "C:\\Users\\jiaju\\AppData\\Local\\Arduino15\\packages\\arduino\\hardware\\avr\\1.8.3\\cores\\arduino\\Arduino.h"
          ]
  4. I retested steps 1-3 but only changing one string's separators to / at a time, leaving the other relevant strings with \\ separators and deleting the redundant strings, with similar results as above.
  5. I changed the setting "C_cpp: Preferred Path Separator" (C_Cpp.preferredPathSeparator in settings.json) from the default 'Forward Slash' to 'Backslash' thinking that it may be related to the issue. This did not affect the results of subsequent retests, and I reverted this change on my settings.

Impact

This does not appear to have any significant performance impact other than additional startup time for VS Code to write in the auto-generated lines. However, this does impact on code uniformity especially since other string values such as for the compilerPath key are accepted and do not trigger the auto-generator even with the / separator.

Suggestions

Thank you for reading this admittedly long issue post and hope that this situation can be improved.

jorritsmit commented 3 years ago

i have a related issue where this is preventing me from sharing my cpp properties between linux and windows