microsoft / vscode-cpptools

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

"go to definition" function doesn't work on vs code for c/c++ #2450

Closed wafei closed 6 years ago

wafei commented 6 years ago

hello, i can't figure out how to get the function( "go to the definition" ) working.

i already installed the extensions: the c/c++ extension(0.18.1), the c/c++ clang command adapter(0.2.2), the c++ intellisense(0.2.2). and the command gtags or clang works well.

I don't know why doesn't work the vs code behavior to 'go to definition' when I do 'command + click' or 'F12'.

vs code version: 1.26.1 os version: windows 10 x64

many thanks for your help

bobbrow commented 6 years ago

We're going to need a little more information about your workspace to answer that. If you have a c_cpp_properties.json file in your ${workspaceFolder}/.vscode folder, can you please share that? Is the definition you are trying to navigate to defined in a source file under your ${workspaceFolder}?

wafei commented 6 years ago

i do have a c_cpp_properties.json file , the 'includepath' is generated automatically. and the definition is in the source file under my ${workspaceFolder}, but when i do 'go to the definiton', it showed me 'no definition found for ... '

c_cpp_properties.json : `{ "version": 4, "configurations": [ { "name": "IAR", "intelliSenseMode": "clang-x64", "browse": { "path": [ "E:\documents\SVN_TEMP\platform_v1.5\trunk\Meter_Indonesia\Firmware\src\", "E:\documents\SVN_TEMP\platform_v1.5\trunk\Meter_Indonesia\Firmware\src\specific\inc\", "E:\documents\SVN_TEMP\platform_v1.5\trunk\Meter_Indonesia\Firmware\src\specific\EPM\", "E:\documents\SVN_TEMP\platform_v1.5\trunk\Meter_Indonesia\Firmware\src\specific\CM\DLMS\", "E:\documents\SVN_TEMP\platform_v1.5\trunk\Meter_Indonesia\Firmware\src\specific\HD\", "E:\documents\SVN_TEMP\platform_v1.5\trunk\Meter_Indonesia\Firmware\src\specific\LOG\", "E:\documents\SVN_TEMP\platform_v1.5\trunk\Meter_Indonesia\Firmware\src\specific\MEMORY\", "E:\documents\SVN_TEMP\platform_v1.5\trunk\Meter_Indonesia\Firmware\src\specific\METERING\", "E:\documents\SVN_TEMP\platform_v1.5\trunk\Meter_Indonesia\Firmware\src\specific\PREPAY\", "E:\documents\SVN_TEMP\platform_v1.5\trunk\Meter_Indonesia\Firmware\src\specific\TOU\", "E:\documents\SVN_TEMP\platform_v1.5\trunk\Meter_Indonesia\Firmware\src\specific\UI\", "E:\documents\SVN_TEMP\platform_v1.5\trunk\Meter_Indonesia\Firmware\src\common\CMSIS\CM0\CoreSupport\", "E:\documents\SVN_TEMP\platform_v1.5\trunk\Meter_Indonesia\Firmware\src\common\CMSIS\CM0\DeviceSupport\Renergy\RN8213\", "E:\documents\SVN_TEMP\platform_v1.5\trunk\Meter_Indonesia\Firmware\src\common\inc\", "E:\documents\SVN_TEMP\platform_v1.5\trunk\Meter_Indonesia\Firmware\src\common\lib\NVM\", "E:\documents\SVN_TEMP\platform_v1.5\trunk\Meter_Indonesia\Firmware\src\common\lib\RTC\", "E:\documents\SVN_TEMP\platform_v1.5\trunk\Meter_Indonesia\Firmware\src\common\lib\SYSCTL\", "E:\documents\SVN_TEMP\platform_v1.5\trunk\Meter_Indonesia\Firmware\src\common\CM\", "E:\documents\SVN_TEMP\platform_v1.5\trunk\Meter_Indonesia\Firmware\src\common\CM\CALI\", "E:\documents\SVN_TEMP\platform_v1.5\trunk\Meter_Indonesia\Firmware\src\common\CM\DLMS\", "E:\documents\SVN_TEMP\platform_v1.5\trunk\Meter_Indonesia\Firmware\src\common\CM\GPRS\", "E:\documents\SVN_TEMP\platform_v1.5\trunk\Meter_Indonesia\Firmware\src\common\CM\IEC\", "E:\documents\SVN_TEMP\platform_v1.5\trunk\Meter_Indonesia\Firmware\src\common\CM\RF\", "E:\documents\SVN_TEMP\platform_v1.5\trunk\Meter_Indonesia\Firmware\src\common\CM\TEST\", "E:\documents\SVN_TEMP\platform_v1.5\trunk\Meter_Indonesia\Firmware\src\common\EPM\", "E:\documents\SVN_TEMP\platform_v1.5\trunk\Meter_Indonesia\Firmware\src\common\FUNCTION\", "E:\documents\SVN_TEMP\platform_v1.5\trunk\Meter_Indonesia\Firmware\src\common\HD\", "E:\documents\SVN_TEMP\platform_v1.5\trunk\Meter_Indonesia\Firmware\src\common\MEMORY\", "E:\documents\SVN_TEMP\platform_v1.5\trunk\Meter_Indonesia\Firmware\src\common\MISC\", "E:\documents\SVN_TEMP\platform_v1.5\trunk\Meter_Indonesia\Firmware\src\common\PREPAY\", "E:\documents\SVN_TEMP\platform_v1.5\trunk\Meter_Indonesia\Firmware\src\common\PREPAY\STS\", "E:\documents\SVN_TEMP\platform_v1.5\trunk\Meter_Indonesia\Firmware\src\common\UI\", "E:\softwares\office tools\IAR 7.4\arm\inc", "E:\softwares\office tools\IAR 7.4\arm\inc\c" ], "limitSymbolsToIncludedHeaders": true, "databaseFilename": ".vscode/iar.db" }, "includePath": [ "E:\documents\SVN_TEMP\platform_v1.5\trunk\Meter_Indonesia\Firmware\src\", "E:\documents\SVN_TEMP\platform_v1.5\trunk\Meter_Indonesia\Firmware\src\specific\inc\", "E:\documents\SVN_TEMP\platform_v1.5\trunk\Meter_Indonesia\Firmware\src\specific\EPM\", "E:\documents\SVN_TEMP\platform_v1.5\trunk\Meter_Indonesia\Firmware\src\specific\CM\DLMS\", "E:\documents\SVN_TEMP\platform_v1.5\trunk\Meter_Indonesia\Firmware\src\specific\HD\", "E:\documents\SVN_TEMP\platform_v1.5\trunk\Meter_Indonesia\Firmware\src\specific\LOG\", "E:\documents\SVN_TEMP\platform_v1.5\trunk\Meter_Indonesia\Firmware\src\specific\MEMORY\", "E:\documents\SVN_TEMP\platform_v1.5\trunk\Meter_Indonesia\Firmware\src\specific\METERING\", "E:\documents\SVN_TEMP\platform_v1.5\trunk\Meter_Indonesia\Firmware\src\specific\PREPAY\", "E:\documents\SVN_TEMP\platform_v1.5\trunk\Meter_Indonesia\Firmware\src\specific\TOU\", "E:\documents\SVN_TEMP\platform_v1.5\trunk\Meter_Indonesia\Firmware\src\specific\UI\", "E:\documents\SVN_TEMP\platform_v1.5\trunk\Meter_Indonesia\Firmware\src\common\CMSIS\CM0\CoreSupport\", "E:\documents\SVN_TEMP\platform_v1.5\trunk\Meter_Indonesia\Firmware\src\common\CMSIS\CM0\DeviceSupport\Renergy\RN8213\", "E:\documents\SVN_TEMP\platform_v1.5\trunk\Meter_Indonesia\Firmware\src\common\inc\", "E:\documents\SVN_TEMP\platform_v1.5\trunk\Meter_Indonesia\Firmware\src\common\lib\NVM\", "E:\documents\SVN_TEMP\platform_v1.5\trunk\Meter_Indonesia\Firmware\src\common\lib\RTC\", "E:\documents\SVN_TEMP\platform_v1.5\trunk\Meter_Indonesia\Firmware\src\common\lib\SYSCTL\", "E:\documents\SVN_TEMP\platform_v1.5\trunk\Meter_Indonesia\Firmware\src\common\CM\", "E:\documents\SVN_TEMP\platform_v1.5\trunk\Meter_Indonesia\Firmware\src\common\CM\CALI\", "E:\documents\SVN_TEMP\platform_v1.5\trunk\Meter_Indonesia\Firmware\src\common\CM\DLMS\", "E:\documents\SVN_TEMP\platform_v1.5\trunk\Meter_Indonesia\Firmware\src\common\CM\GPRS\", "E:\documents\SVN_TEMP\platform_v1.5\trunk\Meter_Indonesia\Firmware\src\common\CM\IEC\", "E:\documents\SVN_TEMP\platform_v1.5\trunk\Meter_Indonesia\Firmware\src\common\CM\RF\", "E:\documents\SVN_TEMP\platform_v1.5\trunk\Meter_Indonesia\Firmware\src\common\CM\TEST\", "E:\documents\SVN_TEMP\platform_v1.5\trunk\Meter_Indonesia\Firmware\src\common\EPM\", "E:\documents\SVN_TEMP\platform_v1.5\trunk\Meter_Indonesia\Firmware\src\common\FUNCTION\", "E:\documents\SVN_TEMP\platform_v1.5\trunk\Meter_Indonesia\Firmware\src\common\HD\", "E:\documents\SVN_TEMP\platform_v1.5\trunk\Meter_Indonesia\Firmware\src\common\MEMORY\", "E:\documents\SVN_TEMP\platform_v1.5\trunk\Meter_Indonesia\Firmware\src\common\MISC\", "E:\documents\SVN_TEMP\platform_v1.5\trunk\Meter_Indonesia\Firmware\src\common\PREPAY\", "E:\documents\SVN_TEMP\platform_v1.5\trunk\Meter_Indonesia\Firmware\src\common\PREPAY\STS\", "E:\documents\SVN_TEMP\platform_v1.5\trunk\Meter_Indonesia\Firmware\src\common\UI\", "E:\softwares\office tools\IAR 7.4\arm\inc", "E:\softwares\office tools\IAR 7.4\arm\inc\c" ],

bobbrow commented 6 years ago

Are you trying to do goto definition on a local variable (in a function)? That doesn't work yet and #255 will address that.

wafei commented 6 years ago

local variable doesn't work, but global variable neither

wafei commented 6 years ago

so strange, the function works well in a minor project, maybe it can't work when the project is too complex?

bobbrow commented 6 years ago

It is also possible that macros are interfering with the tag parsing of the global variables. Is the source code public? Can I download it to check?

wafei commented 6 years ago

i have done nothing, but today it all works well, confused

bobbrow commented 6 years ago

Perhaps the extension took a long time indexing the files. We display a database icon in the status bar while the source files are being parsed.

Let us know if you continue to have any problems in the future.

mkitby commented 5 years ago

two functions are defined in the same file and are called in another file, go to definition works for one function, while does not work as expected for the other function. Maybe sometimes, it can work.

{
    "configurations": [
        {
            "name": "IAR",
            "includePath": [
                "${workspaceFolder}/**",
                "${workspaceFolder}/../Config/exec/arm/inc/c",
                "${workspaceFolder}/../Config/exec/arm/inc/cpp"
            ],
            "defines": [
                "CPU_S32K146",
                "__ICCARM__",
                "__IAR_SYSTEMS_ICC__"
            ],
            "compilerPath": "",
            "cStandard": "c11",
            "cppStandard": "c++17",
            "intelliSenseMode": "clang-x64"
        }
    ],
    "version": 4
}

cpptools_go_to_definition

sean-mcmanus commented 5 years ago

@mkitby I've moved your issue to a new bug https://github.com/microsoft/vscode-cpptools/issues/3981 .