llvm / llvm-project

The LLVM Project is a collection of modular and reusable compiler and toolchain technologies.
http://llvm.org
Other
29.05k stars 11.98k forks source link

[clangd] Clangd's #include CodeCompletion could use a fuzzier finder across '/' #109735

Open torshepherd opened 1 month ago

torshepherd commented 1 month ago

Clangd's CodeCompletion for #includes currently does a fuzzy match but not across /. For example,


#include "cl // at the end here within llvm codebase, clangd will suggest "clang/"
#include "Expr.h // clangd can't figure this one out
#include "clASExpr.h // clangd can't figure this one out

There are two issues with this: 1) folders don't make sense for includes, and 2) you have to find which folder you want to include from before moving on to the next fuzzy part of the path.

In contrast, the vscode native file picker ctrl-p with clASExpr or with Expr finds clang/AST/Expr.h as expected.

There are two ways we could improve the clangd file completion experience:

  1. Allow autocompletes to skip directory levels, so that Expr.h finds clang/AST/Expr.h
  2. Allow fuzziness across /, so clASExpr.h finds clang/AST/Expr.h
llvmbot commented 1 month ago

@llvm/issue-subscribers-clangd

Author: Tor Shepherd (torshepherd)

Clangd's CodeCompletion for `#include`s currently does a fuzzy match but not across `/`. For example, ```cpp #include "cl // at the end here within llvm codebase, clangd will suggest "clang/" #include "Expr.h // clangd can't figure this one out #include "clASExpr.h // clangd can't figure this one out ``` There are two issues with this: 1) folders don't make sense for includes, and 2) you have to find which folder you want to include from before moving on to the next fuzzy part of the path. In contrast, the vscode native file picker `ctrl-p` with `clASExpr` or with `Expr` finds `clang/AST/Expr.h` as expected. There are two ways we could improve the clangd file completion experience: 1. Allow autocompletes to skip directory levels, so that `Expr.h` finds `clang/AST/Expr.h` 2. Allow fuzziness across `/`, so `clASExpr.h` finds `clang/AST/Expr.h`
torshepherd commented 1 month ago

It could also be case insensitive I just realized

torshepherd commented 1 month ago

Ah, one problem with this will be that headers are representable in multiple ways (absolute, root-relative, and relative). Should all of them be listed in this case? Or just do what IncludeCleaner does and use the preferred way inferred from context?

cw5880 commented 1 month ago

通過優化文件路勁匹配算法,使Clangd 能夠跨越目錄級別進行模糊匹配,從而提升代碼補全體驗。