Vscode-cpptools: IntelliSense issue

Created on 14 Dec 2018  路  7Comments  路  Source: microsoft/vscode-cpptools

Type: LanguageService
Cpp IntelliSense quirk: works sometimes or in special cases.
I verified the same behaviour on two different machines.

Note that this project uses C++ _unity build_ approach: compiling single compilation unit "main.cpp". It's totally legal C/C++ code.

I would propose specifying "*.cpp" compilation units in order to kickstart recursive headers parsing. Which, as I assume, Visual Studio does.

Example in project:

  • "demo_game/main.cpp" -> lots of common headers go there
  • "demo_game/pathtracing/main.h" -> specific headers go there

Now, there is a header "demo_game/platform_globals.h", which is included inside "pathttracing/main.h", and is relying on headers from "demo_game/main.cpp". Unless I open "main.cpp" before I open "platform_globals.h", I don't get proper headers parsing from IntelliSense.

Describe the bug

  • OS and Version: Windows_NT x64 10.0.17134
  • VS Code Version: Version: 1.30.0 (system setup), c6e592b2b5770e40a98cb9c2715a8ef89aec3d74
  • C/C++ Extension Version: Version 0.20.1: October 31, 2018
  • IntelliSense works sporadically or for special cases
  • Other extensions, disabled:

    • ms-vscode.csharp


    • vector-of-bool.cmake-tools


    • vadimcn.vscode-lldb


    • unity.unity-debug


    • circledev.glsl-canvas


    • ms-vscode.mono-debug


    • rust-lang.rust


    • slevesque.shader


    • stevensona.shader-toy

To Reproduce
repository is here

  1. Enable "C_Cpp.loggingLevel": "Debug" in the workspace
  2. Go to "code/demo_game/main.cpp"
  3. No IntelliSense here at all
  4. Add a whitespace
  5. Save the file
  6. See outup window C++ demo_game logs
  7. Follow the all-caps path from the logger
  8. Any IntelliSense works here 100%

Expected behavior
IntelliSense works for any absolute or relative path.
For any workspace structure.
For settings from *.code-workspace, settings.json, c_cpp_properties.json.

Screenshots
Similiar relative path, and "demo_game" is excluded from workspace folders list:

normal case (1): just open the file
fantom errors

quirky case (2): follow the all-caps path
full fledged IntelliSense

case (3): workspace has only root "." folder, note selected file in the top-right
wrong IntelliSense
erratical IntelliSense

case (4): I open "demo_game/main.cpp" before opening "code/platform_globals.h"
unity build quirks

Additional context

Edit and save a file yields this log:

textDocument/codeAction
textDocument/didChange
textDocument/didSave
  tag parsing file: C:\PROJECTS\CUSTOMENGINESTUDY\CODE\DEMO_GAME\MAIN.CPP
Database safe to open

normal case (1): just open the file
its relative path is "main.cpp"
"Search Symbols" can't find symbols even in the same file
F12 to a header yields this log:

textDocument/codeAction
textDocument/definition
textDocument_definition() - file:///c%3A/Projects/CustomEngineStudy/code/demo_game/main.cpp, 23:24

quirky case (2): follow the all-caps path
its relative path is "CODE\DEMO_GAME\MAIN.CPP"
"Search Symbols" easily fetches any struct, typedef, function, anything
Jump to a definition from an "auto" just works
F12 to a header yields this log:

cpptools/activeDocumentChange
cpptools/resumeParsing

More observations:

If "demo_game" is excluded from the workspace folders list, IntelliSense still won't work well:

  • sporadically F12 works and I can jump to definition
  • IntelliSense finds far from all symbols and behaves erratically overall
  • trick with followng a path from the C++ output logger still works and presents better IntelliSense

case (3): workspace has only root "." folder
relative paths are similiar and are like "code/demo_game/main.cpp" all-caps or not
Edit and save a file yields this log:

textDocument/didChange
textDocument/didSave
Checking for syntax errors: file:///f%3A/Projects/CustomEngineStudy/code/demo_game/platform_globals.h
queue_update_intellisense for files in tu of: F:\PROJECTS\CUSTOMENGINESTUDY\CODE\DEMO_GAME\TETRIS\MAIN.H
  tag parsing file: F:\PROJECTS\CUSTOMENGINESTUDY\CODE\DEMO_GAME\PLATFORM_GLOBALS.H
sending 1 changes to server
errorSquiggles count: 40
Language Service bug investigate more info needed

All 7 comments

Yeah, when you open just the header we make an attempt to find the correct .cpp file, but in this case, it seems that we fail and try to create TU with just the header file in it. Add the name of the source file used in the status bar with the ability to change it when clicked might solve this. I'm not sure if you're describing additional bugs. We capitalizes the file paths when they're not case-sensitive (for our database)...for the purposes of the output log we could probably clean that up a little.

Appreciate the response.

As for additional bugs, I would say there is only one excerpt from this issue is:

  1. Go to "code/demo_game/main.cpp"
  2. No IntelliSense here at all

... Which I assume is that "CustomEngineStudy.code-workspace" folders structure prevents IntelliSense from working properly. If I drop all but "." folders from there, only then I'll be able to F12 to a header. Specializing a "*.cpp" doesn't help here, as it is one already.

Also thank you for your work, this extension is greatly useful.

This is caused by the CustomEngineStudy-master having demo_game as a child folder, which isn't a scenario we "support", although ideally we should do a better job communicating this. In particular, the CustomEngineStudy-master process is stealing the textDocument/didOpen, so the demo_game process doesn't receive it, causing the Go to Definition to fail. Maybe @bobbrow might have some ideas how we should deal with this. Currently, the only way would be to not have a multi-root workspace with one folder being a parent of another. Another user recently tried to do the same thing at https://github.com/Microsoft/vscode-cpptools/issues/2954 . We could use this issue to track better handling of this multi-root scenario or we could create a new issue.

If the issue is just with textDocument/didOpen, we might be able to send that message to all clients containing the file. We currently filter the messages and just pick one workspaceFolder client to send messages to.

Yeah, sending the did open to all clients with the file sounds good to me. I don't know if there are "other" issues after doing that.

@Feacur Our multi-root support has changes significantly since this issue last had activity. Are you still seeing this issue?

@Colengms Hi! Didn't have a chance to test if intellisense works for nested roots. Since then I've been using a slightly different approach as a workaround, and thus don't see the issue in question:

instead of putting projects inside a workspace

- repository folder and workspace root
- - projects roots

... they are put at the same level with it

- repository folder
- - workspace root
- - projects roots

... which makes the extensions satisfied and decouples responsibilities quite nicely. An issue with rerouting C_Cpp.intelliSenseCachePath rises sometimes: despite the setting I have, ipch folder might end up inside the workspace root instead of a target path. Quite a minor nuisance anyways.

repository is here

image

Was this page helpful?
0 / 5 - 0 ratings