Page MenuHomePhabricator

[clangd] Support iwyu pragma: no_include
Needs ReviewPublic

Authored by zyounan on Feb 4 2023, 4:23 AM.

Details

Summary

This patch is one of the steps trying to optimize experience
of header insertion in code completion.
IWYU supports no_include pragma that helps user to get rid
of specified headers in main file.
The patch consists of two parts: Code completion part that
prevent auto insertion if the header to be inserted is under
the guard of no_include pragma. The other part is for include
cleaner, which emits diagnostic message pointing out that user
is including no_include headers.

A possible workaround for clangd/clangd#1481.

Diff Detail

Event Timeline

zyounan created this revision.Feb 4 2023, 4:23 AM
Herald added a project: Restricted Project. · View Herald TranscriptFeb 4 2023, 4:23 AM
zyounan updated this revision to Diff 494815.Feb 4 2023, 4:27 AM

Remove extra headers

zyounan updated this revision to Diff 494816.Feb 4 2023, 4:54 AM

Update test

zyounan published this revision for review.Feb 4 2023, 5:29 AM
zyounan added reviewers: hokein, sammccall, kadircet, nridge.
zyounan updated this revision to Diff 494911.Feb 5 2023, 7:25 AM

Update tests && Use Preprocessor.LookupFile

zyounan updated this revision to Diff 494921.Feb 5 2023, 8:16 AM

Fix test on windows

thanks a lot for the patch!

we're migrating IWYU related functionality in clangd to make use of include-cleaner library nowadays. so can you actually move the IWYU no_include pragma handling logic into https://github.com/llvm/llvm-project/blob/main/clang-tools-extra/include-cleaner/lib/Record.cpp?
This won't have affect on clangd regarding the particular problem you're facing immediately, but we're going to merge the logic inside include-cleaner and clangd soon and such discrepancies should disappear then.

in the meanwhile regarding the particular problem you're facing for experimental symbols. sorry for shutting down D142836, but that actually made us re-evaluate the approach of hand-curated lists and we've decided to introduce such mappings. so if you can revamp D142836 and put TsStdSymbolMap.inc in https://github.com/llvm/llvm-project/tree/main/clang/lib/Tooling/Inclusions/Stdlib/StdTsSymbolMap.inc we can land it and make sure it work as intended inside clangd, even before we merge the IWYU pragma handling logic. Happy to do that myself if you don't feel like doing it, sorry for creating some confusion here :(

thanks a lot for the patch!

we're migrating IWYU related functionality in clangd to make use of include-cleaner library nowadays. so can you actually move the IWYU no_include pragma handling logic into https://github.com/llvm/llvm-project/blob/main/clang-tools-extra/include-cleaner/lib/Record.cpp?
This won't have affect on clangd regarding the particular problem you're facing immediately, but we're going to merge the logic inside include-cleaner and clangd soon and such discrepancies should disappear then.

in the meanwhile regarding the particular problem you're facing for experimental symbols. sorry for shutting down D142836, but that actually made us re-evaluate the approach of hand-curated lists and we've decided to introduce such mappings. so if you can revamp D142836 and put TsStdSymbolMap.inc in https://github.com/llvm/llvm-project/tree/main/clang/lib/Tooling/Inclusions/Stdlib/StdTsSymbolMap.inc we can land it and make sure it work as intended inside clangd, even before we merge the IWYU pragma handling logic. Happy to do that myself if you don't feel like doing it, sorry for creating some confusion here :(

Although I'm convinced that they're not stable enough to migrate into Stdlib directory, I'm still glad to hear that we're going to support TS symbols.
And certainly, I'd love to revamp D142836, while I believe that this IWYU no-include is a more general approach than that ad-hoc way.

zyounan updated this revision to Diff 499417.EditedFeb 22 2023, 1:54 AM

Sorry for the late update :)
Move parsing logic to Record.cpp now.