80 Commits

Author SHA1 Message Date
tcottin
51994891e3
[clangd] Improve Markup Rendering (#140498)
This is a preparation for fixing clangd/clangd#529.

It changes the Markup rendering to markdown and plaintext.

- Properly separate paragraphs using an empty line between
- Dont escape markdown syntax for markdown output except for HTML
- Dont do any formatting for markdown because the client is handling the
actual markdown rendering
2025-07-25 02:45:56 +02:00
Noustaa
bfd2ef7659
[clangd] Add CodePatterns config option under Completion (#137613)
Allows enabling/disabling code pattern & snippet suggestions
during code completion.

Resolves https://github.com/clangd/clangd/discussions/1867
2025-05-12 14:22:27 -04:00
Zahira Ammarguellat
babbc6f842
[NFC] Fixes proposed by code sanitizer. (#134138) 2025-04-04 08:04:16 -04:00
Kazu Hirata
884b19ab40
[clang-tools-extra] Use *Set::insert_range (NFC) (#133589) 2025-03-29 12:22:13 -07:00
Mythreya
9cdbc47144
[clangd] Add HeaderInsertion config option (#128503)
This is the config file equivalent of the `--header-insertion` command line option

Fixes https://github.com/clangd/clangd/issues/2032
2025-03-20 02:22:29 -04:00
Khalil Estell
85d60a441a
[clangd] Add BuiltinHeaders config option (#129459)
This option, under `CompileFlags`, governs whether clangd uses its own
built-in headers (`Clangd` option value) or the built-in headers of the driver
in the file's compile command (`QueryDriver` option value, applicable to
cases where `--query-driver` is used to instruct clangd to ask the driver
for its system include paths).

The default value is `Clangd`, preserving clangd's current defaut behaviour.

Fixes clangd/clangd#2074
2025-03-08 19:16:37 -05:00
kleines Filmröllchen
1f90797f6a
[clangd] Allow specifying what headers are always included via "" or <> (#67749)
Projects can now add config fragments like this to their .clangd:

```yaml
Style:
  QuotedHeaders: "src/.*"
  AngledHeaders: ["path/sdk/.*", "third-party/.*"]
```

to force headers inserted via the --header-insertion=iwyu mode matching
at least one of the regexes to have <> (AngledHeaders) or ""
(QuotedHeaders) around them, respectively. For other headers (and in
conflicting cases where both styles have a matching regex), the current
system header detection remains.

Fixes https://github.com/clangd/clangd/issues/1247
2024-12-27 14:14:29 -05:00
Tor Shepherd
2eb1699184
[clangd] Add inlay hints for default function arguments (#95712)
The new inlay hints have the `DefaultArguments` kind and can be enabled in config similar to other inlay kint kinds.
2024-10-19 18:19:01 -04:00
Nathan Ridge
18ca7ad339
[clangd] Add ArgumentLists config option under Completion (#111322)
The new config option is a more flexible version of
--function-arg-placeholders, allowing users more detailed control of
what is inserted in argument list position when clangd completes the
name of a function in a function call context.

Fixes https://github.com/llvm/llvm-project/issues/63565

Co-authored-by: MK-Alias <ImNotReadingThis@maininator.com>
2024-10-06 20:32:54 -04:00
Vadim D
8c5a7a1fc4
[clangd] Add config option to allow detection of unused angled includes (#87208)
This PR adds a new `AnalyzeAngledIncludes` option to `Includes` section
of clangd config. This option enables unused include checks for all includes
that use the `<>` syntax, not just standard library includes.
2024-05-29 13:29:57 -04:00
Kazu Hirata
d5953e3e30 [clangd] Use StringRef::{starts,ends}_with (NFC)
This patch replaces uses of StringRef::{starts,ends}with with
StringRef::{starts,ends}_with for consistency with
std::{string,string_view}::{starts,ends}_with in C++20.

I'm planning to deprecate and eventually remove
StringRef::{starts,ends}with.
2023-12-13 23:26:09 -08:00
Sam McCall
b99f7e6954 [clangd] Don't run slow clang-tidy checks by default
This uses the fast-check allowlist added in the previous commit.
This is behind a config option to allow users/developers to enable checks
we haven't timed yet, and to allow the --check-tidy-time flag to work.

Fixes https://github.com/clangd/clangd/issues/1337

Differential Revision: https://reviews.llvm.org/D138505
2023-10-20 11:47:29 +02:00
daiyousei-qz
9e6a342fda [clangd] Implement end-definition-comment inlay hints
This patch implements a new inlay hint feature proposed in https://github.com/clangd/clangd/issues/1634. It introduces a new inlay hint kind BlockEnd which shows a comment-like hint after a definition brace pair, including function/type/namespace. For example,
```
void foo() {
} ^
```
In the code shown above, a hint should be displayed at ^ labelling `// foo`. Such hint only shows when there's no trailing character after the position except whitespaces and optionally ';'.

Also, new configurations are introduced in the inlay hints block
```
InlayHints:
    BlockEnd: Yes # toggling the feature
```

Reviewed By: sammccall

Differential Revision: https://reviews.llvm.org/D150635
2023-07-16 01:19:02 +02:00
Kadir Cetinkaya
bd89f9ec29
[clangd] Always allow diagnostics from stale preambles
We've been running this internally for months now, without any
stability or correctness concerns. It has ~40% speed up on incremental
diagnostics latencies (as preamble can get invalidated through code completion
etc.).

Differential Revision: https://reviews.llvm.org/D153882
2023-06-28 10:41:45 +02:00
Elliot Goodrich
b0abd4893f [llvm] Add missing StringExtras.h includes
In preparation for removing the `#include "llvm/ADT/StringExtras.h"`
from the header to source file of `llvm/Support/Error.h`, first add in
all the missing includes that were previously included transitively
through this header.
2023-06-25 15:42:22 +01:00
Qingyuan Zheng
6feaa5416b [clangd] Implement configs to stop clangd produce a certain semantic tokens
This patch introduces the following configurations to .clangd:

```
SemanticTokens:
    DisabledKinds: [ ... ]
    DisabledModifiers: [ ... ]
```

Based on the config, clangd would stop producing a certain type of semantic tokens from the source file.

Fixes https://github.com/clangd/clangd/discussions/1598

Reviewed By: nridge

Differential Revision: https://reviews.llvm.org/D148489
2023-05-26 03:25:35 -04:00
zhangyi1357
2ae1aa9da7 [Clangd] Make the type hint length limit configurable
This commit is about clangd's type name hint length limit. The past behavior was 32 characters fixed limit. It is now configurable.

Projects can now add the following config fragment to their .clangd:

```
InlayHints:
  TypeNameLimit: 34
```

Ref: [[ https://github.com/clangd/clangd/issues/1357  | Make the type hint length limit configurable ]]

Reviewed By: hokein

Differential Revision: https://reviews.llvm.org/D147395
2023-04-20 15:21:48 +02:00
Haojian Wu
7ab16be4c0 [clangd] UnusedIncludes: Strict config now uses the include-cleaner-library implementation.
And remove the classical clangd-own unused-include implementation.

Differential Revision: https://reviews.llvm.org/D145773
2023-03-10 11:56:11 +01:00
Viktoriia Bakalova
2e82eb1f74 Re-land [clangd] Add support for missing includes analysis.
This reverts commit fd8c9ef20a9519dccd5b8178b29ed4574285d36f.

Differential Revision: https://reviews.llvm.org/D145577
2023-03-08 13:29:52 +00:00
Viktoriia Bakalova
fd8c9ef20a Revert "Re-land [clangd] Add support for missing includes analysis."
This reverts commit 85a5c17b66768353b7fff717904e42805bb6a547.
2023-03-08 12:34:15 +00:00
Viktoriia Bakalova
46447e0ba2 Revert "Revert "Re-land [clangd] Add support for missing includes analysis.""
This reverts commit 9814b4d07f614e83e7a244f74fc562f2b5cc9b15.
2023-03-08 12:27:17 +00:00
Viktoriia Bakalova
9814b4d07f Revert "Re-land [clangd] Add support for missing includes analysis."
This reverts commit 85a5c17b66768353b7fff717904e42805bb6a547.
2023-03-08 12:24:51 +00:00
Viktoriia Bakalova
85a5c17b66 Re-land [clangd] Add support for missing includes analysis.
This reverts commit 2eb5ac99a76dbbf8ac68c538211fabeaa5ac0bfd.
2023-03-08 11:02:12 +00:00
Nico Weber
2eb5ac99a7 Revert "[clangd] Add support for missing includes analysis."
This reverts commit 38b9fb5a129db3e086610d53b534833273c5b4d0.
Breaks tests on Windows, see comments on https://reviews.llvm.org/D143496
2023-03-07 22:14:11 -05:00
Viktoriia Bakalova
38b9fb5a12 [clangd] Add support for missing includes analysis.
Differential Revision: https://reviews.llvm.org/D143496
2023-03-07 16:07:19 +00:00
Kadir Cetinkaya
7177a237b6
[clangd] Add config option for fast diagnostics mode
Also wire it up for use with patched preambles and introduce test cases
for behaviour we'd like to improve.

Differential Revision: https://reviews.llvm.org/D142890
2023-02-22 15:54:14 +01:00
Haojian Wu
939dce12f9 [clangd] Implement unused include warnings with include-cleaner library.
A prototype of using include-cleaner library in clangd:

- (re)implement clangd's "unused include" warnings with the library
- the new implementation is hidden under a flag `Config::UnusedIncludesPolicy::Experiment`

Differential Revision: https://reviews.llvm.org/D140875
2023-01-19 14:31:40 +01:00
Kazu Hirata
29ffafb575 [clang-tools-extra] Remove remaining uses of llvm::Optional (NFC)
This patch removes the unused "using" declaration and removes #include
"llvm/ADT/Optional.h".

This is part of an effort to migrate from llvm::Optional to
std::optional:

https://discourse.llvm.org/t/deprecating-llvm-optional-x-hasvalue-getvalue-getvalueor/63716
2023-01-07 20:34:53 -08:00
Kazu Hirata
f71ffd3b73 [clang-tools-extra] Use std::optional instead of llvm::Optional (NFC)
This patch replaces (llvm::|)Optional< with std::optional<.  I'll post
a separate patch to clean up the "using" declarations, #include
"llvm/ADT/Optional.h", etc.

This is part of an effort to migrate from llvm::Optional to
std::optional:

https://discourse.llvm.org/t/deprecating-llvm-optional-x-hasvalue-getvalue-getvalueor/63716
2023-01-07 20:19:42 -08:00
Kazu Hirata
71f557355d [clang-tools-extra] Add #include <optional> (NFC)
This patch adds #include <optional> to those files containing
llvm::Optional<...> or Optional<...>.

I'll post a separate patch to actually replace llvm::Optional with
std::optional.

This is part of an effort to migrate from llvm::Optional to
std::optional:

https://discourse.llvm.org/t/deprecating-llvm-optional-x-hasvalue-getvalue-getvalueor/63716
2023-01-07 20:02:20 -08:00
Benjamin Kramer
854c10f8d1 [Clang] Prepare for llvm::Optional becoming std::optional.
The needed tweaks are mostly trivial, the one nasty bit is Clang's usage
of OptionalStorage. To keep this working old Optional stays around as
clang::CustomizableOptional, with the default Storage removed.
Optional<File/DirectoryEntryRef> is replaced with a typedef.

I tested this with GCC 7.5, the oldest supported GCC I had around.

Differential Revision: https://reviews.llvm.org/D140332
2022-12-20 00:41:40 +01:00
Fangrui Song
1da3a795fc JSON: llvm::Optional => std::optional
Many files are from language servers.

https://discourse.llvm.org/t/deprecating-llvm-optional-x-hasvalue-getvalue-getvalueor/63716
2022-12-16 07:56:52 +00:00
Kazu Hirata
f7dffc28b3 Don't include None.h (NFC)
I've converted all known uses of None to std::nullopt, so we no longer
need to include None.h.

This is part of an effort to migrate from llvm::Optional to
std::optional:

https://discourse.llvm.org/t/deprecating-llvm-optional-x-hasvalue-getvalue-getvalueor/63716
2022-12-10 11:24:26 -08:00
Kazu Hirata
2402c46b71 [clang-tools-extra] Use std::nullopt instead of llvm::None (NFC)
This is part of an effort to migrate from llvm::Optional to
std::optional:

https://discourse.llvm.org/t/deprecating-llvm-optional-x-hasvalue-getvalue-getvalueor/63716
2022-12-05 23:55:23 -08:00
Kazu Hirata
059a23c0f0 [clang-tools-extra] Use std::nullopt instead of None (NFC)
This patch mechanically replaces None with std::nullopt where the
compiler would warn if None were deprecated.  The intent is to reduce
the amount of manual work required in migrating from Optional to
std::optional.

This is part of an effort to migrate from llvm::Optional to
std::optional:

https://discourse.llvm.org/t/deprecating-llvm-optional-x-hasvalue-getvalue-getvalueor/63716
2022-12-03 11:54:50 -08:00
Kazu Hirata
53daa177f8 [clang, clang-tools-extra] Use has_value instead of hasValue (NFC) 2022-07-12 22:47:41 -07:00
Kazu Hirata
3b7c3a654c Revert "Don't use Optional::hasValue (NFC)"
This reverts commit aa8feeefd3ac6c78ee8f67bf033976fc7d68bc6d.
2022-06-25 11:56:50 -07:00
Kazu Hirata
aa8feeefd3 Don't use Optional::hasValue (NFC) 2022-06-25 11:55:57 -07:00
Kadir Cetinkaya
3ecfeb4c2f
[clangd] Wire up compilation for style blocks
Differential Revision: https://reviews.llvm.org/D127749
2022-06-15 08:15:32 +02:00
Sam McCall
03ea140b3a Reland(3) "[clangd] Indexing of standard library"
Tracked down the crash, which was argument-evaluation-order UB
in the wrapping indexStandardLibrary().
Sorry for the churn!

This reverts commit 77533ea443aca6e9978d7c8a6822420f8345f6af.
2022-05-19 08:13:23 +02:00
Sam McCall
77533ea443 Revert "Reland(2) "[clangd] Indexing of standard library""
This reverts commit ca875539f788c8063e243ce9ceb877a0d2ad9115.
2022-05-18 17:38:45 +02:00
Sam McCall
ca875539f7 Reland(2) "[clangd] Indexing of standard library"
This reverts commit 6aabf60f2fb7589430c0ecc8fe95913c973fa248.
2022-05-18 15:30:37 +02:00
Sam McCall
6aabf60f2f Revert "Reland "[clangd] Indexing of standard library""
This reverts commit ccdb56ac10eef3048135169a67d239328c2b1de6.

Still seeing windows failures on GN bots: http://45.33.8.238/win/58316/step_9.txt

Unfortunately I can't debug these at all - it's a bare unsymbolized
stacktrace, and I can't reproduce the failure.
2022-05-17 21:33:48 +02:00
Sam McCall
ccdb56ac10 Reland "[clangd] Indexing of standard library"
This reverts commit 76ddbb1ca747366417be64fdf79218df099a5973.
2022-05-17 21:02:23 +02:00
Sam McCall
76ddbb1ca7 Revert "[clangd] Indexing of standard library"
This reverts commit ecaa4d9662c9a6ac013ac40a8ad72a2c75e3fd3b.
2022-05-17 17:17:27 +02:00
Sam McCall
ecaa4d9662 [clangd] Indexing of standard library
This provides a nice "warm start" with all headers indexed, not just
those included so far.

The standard library is indexed after a preamble is parsed, using that
file's configuration. The result is pushed into the dynamic index.
If we later see a higher language version, we reindex it.

It's configurable as Index.StandardLibrary, off by default for now.

Based on D105177 by @kuhnel

Fixes https://github.com/clangd/clangd/issues/618

Differential Revision: https://reviews.llvm.org/D115232
2022-05-17 16:50:41 +02:00
Kirill Bobyrev
bdf0b757d5
[clangd] IncludeCleaner: Add filtering mechanism
This introduces filtering out inclusions based on the resolved path. This
mechanism will be important for disabling warnings for headers that we can not
diagnose correctly yet.

Reviewed By: sammccall

Differential Revision: https://reviews.llvm.org/D123488
2022-04-19 14:56:27 +02:00
Sam McCall
4d006520b8 [clangd] Clean up unused includes. NFCI
Add includes where needed to fix build.
Haven't systematically added used headers, so there is still accidental
dependency on transitive includes.
2022-02-26 12:00:16 +01:00
Sam McCall
ce94432702 [clangd] Add designator inlay hints for initializer lists.
These make the init lists appear as if designated initialization was used.

Example:
  ExpectedHint{"param: ", "arg"}
becomes
  ExpectedHint{.Label="param: ", .RangeName="arg"}

Differential Revision: https://reviews.llvm.org/D116786
2022-01-26 00:35:29 +01:00
Sam McCall
16fd5c2784 [clangd] Support configuration of inlay hints.
The idea is that the feature will always be advertised at the LSP level, but
depending on config we'll return partial or no responses.

We try to avoid doing the analysis for hints we're not going to return.

Examples of syntax:
```
InlayHints:
  Enabled: No
---
InlayHints:
  ParameterNames: No
---
InlayHints:
  ParameterNames: Yes
  DeducedTypes: Yes
```

Differential Revision: https://reviews.llvm.org/D116713
2022-01-10 10:49:35 +01:00