vscode-clangd icon indicating copy to clipboard operation
vscode-clangd copied to clipboard

Disabling an intellisense for specific folders

Open arekzaluski opened this issue 3 years ago • 9 comments

Question: Is it possible to disable C/C++ intellisense for specific folders/files? I do not see that option in either vscode-clangd or clangd.

arekzaluski avatar May 03 '21 17:05 arekzaluski

Hi @arekzaluski ,

to help us discuss the options: What's your use case for this feature?

ChristianKuehnel avatar May 04 '21 12:05 ChristianKuehnel

Thank you for an answer. Use case:

  • User has multiple programs in a workspace. User is often opening files from different programs that are located in the same workspace. At the moment C/C++ intellisense starts as soon as the file for the program is opened. It takes a lot of resources as clangd is very memory hungry (especially the indexing part). As a user I want to be able to specify what programs/folders I want to have C/C++ intellisense enabled for without the worry that all my memory will be consumed. This use-case is especially important when an IDE is running in the web environment. The memory restriction is more strict there.

arekzaluski avatar May 04 '21 13:05 arekzaluski

I would personally expect an option for it in https://clangd.llvm.org/config.html. Unfortunately, I do not see any.

arekzaluski avatar May 04 '21 13:05 arekzaluski

As you've noted in clangd/clangd#342, currently clangd only supports disabling background indexing.

I suppose we can work on an option to ignore certain files, this would be especially useful for files making clang(d) crash-loop (thinking out loud, should we also ignore files depending on an ignored file?).

I'd like to learn more about your problem though, resource usage of clangd is something we care and would like to reduce when possible. Currently there are 3 main components consuming resources in clangd:

  • BackgroundIndex:
    • consumes both cpu and memory on startup
    • incremental, so only for files changed since last indexing.
    • can already be disabled, looks like not enough for your case.
  • DynamicIndex:
    • consumes cpu and increasing amount of cpu for every new file you open.
    • no good way to disable.
    • we expect memory usage of this component to be reasonable (unless you open most of the files in your codebase)
    • cpu usage only comes into play when you open/edit the file. so shouldn't be a problem unless you are editing more files than your machine's # of cores at once.
  • AST/Preamble Caches:
    • AST cache only consumes memory and we only retain last 3 files. So again this shouldn't cause much problems.
    • Preamble cache can consume both memory and disk, and we retain those for all open files (because they are usually on disk).

That being said, since you are on vscode, can you provide the output for memory usage (i think can be triggered through command palette by searching for clangd Memory Usage). Also verbose logs from one of the problematic sessions would again be helpful. See http://clangd.llvm.org/troubleshooting.html#gathering-logs for details.

kadircet avatar May 04 '21 14:05 kadircet

@kadircet My use-case is primary about running VSCode and Theia in the cloud. In that case you usually do not have much resources available. Especially RAM. I'm interested in a feature where I can specify for what paths (projects) C/C++ intellisense will be enabled.

For example: I have 5 projects in the workspace:

  • Proj1
  • Proj2
  • Proj3
  • Proj4
  • Proj5

I expect to have a config option that allows to trigger C/C++ intellisense only for Proj1. After opening any file from Proj2-5 it should not trigger C/C++ intellisense features (background and dynamic indexing, AST). It should behave as if vscode-clangd and clangd is not even enabled.

Without this feature after opening any file from Proj2 it runs intellisense for Proj2 which increases memory used by clangd. Which may lead for example to a crash of container as clangd takes all available memory.

arekzaluski avatar Nov 23 '22 17:11 arekzaluski

After opening any file from Proj2-5 it should not trigger C/C++ intellisense features (background and dynamic indexing, AST). It should behave as if vscode-clangd and clangd is not even enabled.

This is a hack, but it does what you want:

If:
  PathMatch: Proj[2-5]
CompileFlags:
  Add:
  - --nonexistent

As a side effect every opened file from Proj2-5 will give you "Unsupported option '--nonexistent'" in Problems, but maybe it's the price you are willing to pay.

i-ky avatar Nov 24 '22 08:11 i-ky

Hi @i-ky, I've just tried it. Unfortuantely even with this hack it still runs C/C++ intellisense and clangd. The only difference is that indeed I see now: Screenshot 2022-11-24 at 12 12 47

arekzaluski avatar Nov 24 '22 11:11 arekzaluski

Any updates on this? It has been two years and still no activity.

RichardLuo0 avatar May 05 '24 04:05 RichardLuo0