microsoft / vscode-cpptools

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

IntelliSense does not refresh after editing source code #7197

Open sean-mcmanus opened 3 years ago

sean-mcmanus commented 3 years ago

@sean-mcmanus Yes, I do experience buggy symptoms. The bug that I encounter is that the intellisense does not refresh after editing source code. When reloading the plugin, the intellisense works as expected, but after some source code edits the intellisense does not seem to refresh autonomously.

I experience visual bugs like these as example: image

Jumping to definitions is also broken at that moment as it jumps to incorrect lines. Seems like it tries to jump to old locations, before the file was edited.

I do not seem to experience the "Command not found error" which you are referring to. Where would I expect to encounter this?

Originally posted by @Tuweky in https://github.com/microsoft/vscode-cpptools/issues/7168#issuecomment-802654660

sean-mcmanus commented 3 years ago

The IntelliSense/cpptools-srv process may be crashing. When you view the C/C++ pane in the Output window do you see any "crash" messages?

Also, what OS and version of the C/C++ extension are you using?

dimitry-boersma commented 3 years ago

I am experiencing this exact same issue. What I have also noticed is that when I run htop, I see a single thread of the C/C++ extension constantly at 100% cpu usage. This happens anytime I compile the code and lasts until I close VSCode.

SW Versions:

The output window only has a single 'instance' for the C/C++ extension: "C/C++ Configuration Warnings". In this window it seems to be switching between IntelliSense modes willy-nilly. A small excerpt of the logs (in reality it is quite lengthy, but a lot of them are duplicate entries):

[3/23/2021, 3:06:10 PM] For C source files, IntelliSenseMode was changed from "linux-clang-x64" to "linux-gcc-x64" based on compiler args and querying compilerPath: "/usr/bin/gcc"
[3/23/2021, 3:06:10 PM] For C++ source files, IntelliSenseMode was changed from "linux-clang-x64" to "linux-gcc-x64" based on compiler args and querying compilerPath: "/usr/bin/gcc"
[3/23/2021, 3:06:14 PM] For C source files, IntelliSenseMode was changed from "linux-clang-x64" to "linux-gcc-arm" based on compiler args and querying compilerPath: "/usr/bin/arm-none-eabi-gcc"
[3/23/2021, 3:06:14 PM] For C++ source files, IntelliSenseMode was changed from "linux-clang-x64" to "linux-gcc-x64" based on compiler args and querying compilerPath: "/usr/bin/gcc"

If I manually specify for it to use any of these compilerPaths, it will warn about changing to clang (effectively printing the same, but reversed). This doesn't fix the issue however.

chrisdunelm commented 3 years ago

I'm also seeing this problem (or one very similar). Intellisense works OK when I first load a .cc or .h file, but after a few (maybe one) edit it does not update, so becomes out of date as the file is edited - showing more and more errors incorrectly - e.g. In a .cc file a method has a parameter of type std::string, it's currently showing a red squiggly under std::s with the error identifier "tring" is undefined. In contrast to @dimitry-boersma I do not see 100% CPU usage.

I see many of the following errors/warnings in "Log (extension host)":

[2021-03-23 15:01:19.954] [exthost] [warning] ms-vscode.cpptools - Code actions of kind 'quickfix 'requested but returned code action does not have a 'kind'. Code action will be dropped. Please set 'CodeAction.kind'.
[2021-03-23 15:01:21.085] [exthost] [error] [ms-vscode.cpptools] provider FAILED
[2021-03-23 15:01:21.085] [exthost] [error] undefined

In the "C/C++" output pane I see: Quick info operation failed: FE: 'Unknown error'

Ubuntu 20.04; VSCode 1.54.3; C/C++ plugin 1.2.2

sean-mcmanus commented 3 years ago

@chrisdunelm The "FE: Unknown error" is the problem (the other errors can be ignored. It looks like something is causing our IntelliSense processing to fail, most likely some point when processing a header file in the TU. You may want to try preprocessing the TU by passing your compiler the -E flag along with the other compilerArgs to generate a single file to see what errors are being show and/or just manually opening the included header files to look for errors. It's possibly caused by the wrong includes/defines being set as well. It's possible we might need some sort of isolated repro in order to investigate further.

chrisdunelm commented 3 years ago

@sean-mcmanus Thank you. Would the header parsing problem you describe lead to intellisense partially working within a single source file? I'm now editing a .cc file. It has similar mis-colouring in some places as shown by @Tuweky in this original issue. But when currently typing most of the intellisense and errors shown are correct in the function I'm currently editing, but after typing a few lines it's now persistently showing an incorrect error - red squiggly under } stating expected a ";" - the } is the end of a for loop, so no ; required. And now, after a little more editing, that red squiggly has gone. But later down the file, there's still mis-colouring, and another red squiggly under the nt of a call to std::snprintf with the error expected a ";".

I've enabled debug logging of the C/C++ extension; I don't see any more Quick info operation failed: FE: 'Unknown error' during all of this. The latest couple of log entry shows:

Error squiggle count: 0
Update IntelliSense time (sec): 2.281

despite there being one (incorrect) error squiggle - the std::snprintf as described above.

sean-mcmanus commented 3 years ago

No, the header parsing (Unknown error) issue would indicate complete IntelliSense failure (that might have been a temporary failure). If the errors update after moving the cursor to a new line that that would be "by design". The "Error squiggle count: 0" should normally mean there are no error squiggles....that means we got back 0 errors from IntelliSense...I don't know how the squiggle could still be there after that.

Tuweky commented 3 years ago

The IntelliSense/cpptools-srv process may be crashing. When you view the C/C++ pane in the Output window do you see any "crash" messages?

Also, what OS and version of the C/C++ extension are you using?

OS: Ubuntu 20.04.2 LTS

VS Code: 1.54.3 C/C++: 1.2.2

VS Code Insiders: 1.55.0 C/C++: 1.3.0-insiders

I can confirm the same issues as @chrisdunelm is experiencing. In the following screenshot you can see a related error: image

Obviously <stdbool.h> has been included, but something does not seem to refresh correctly. As you can see that true is stated as tru without the e for some reason.

After a few line edits later, the same few lines of code look like this with incorrect colors: image

Then after reloading Code, the same snippet displays this: image

This sample test was done in VS Code insiders.

And no, I do not receive any crash messages at the output window.

Mihir-D commented 2 years ago

Saw your issue from here. I had different error and my references were not working, but I think unexpected behaviors might be resolved with clearing cache and configs. Providing my issue and fix below. Issue: Error: Error: Command failed: global --encode-path " " -xa <function_name> global: GTAGS not found.global --encode-path " " -xa (exited with error code 3) Solution: Remove the following files and reinstall vscode

  1. ~/.vscode
  2. ~/.cache/vscode-cpptools
  3. ~/.config/Code I am not sure if you'd need even reinstall, just removing cache and other files might be sufficient. This solution has worked for other people with similar unexpected behaviors. OS - Ubuntu 18.04