1 //===--- CodeCompletionStrings.h ---------------------------------*- C++-*-===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 // Functions for retrieving code completion information from
10 // `CodeCompletionString`.
12 //===----------------------------------------------------------------------===//
14 #ifndef LLVM_CLANG_TOOLS_EXTRA_CLANGD_CODECOMPLETIONSTRINGS_H
15 #define LLVM_CLANG_TOOLS_EXTRA_CLANGD_CODECOMPLETIONSTRINGS_H
17 #include "clang/Sema/CodeCompleteConsumer.h"
24 /// Gets a minimally formatted documentation comment of \p Result, with comment
25 /// markers stripped. See clang::RawComment::getFormattedText() for the detailed
26 /// explanation of how the comment text is transformed.
27 /// Returns empty string when no comment is available.
28 /// If \p CommentsFromHeaders parameter is set, only comments from the main
29 /// file will be returned. It is used to workaround crashes when parsing
30 /// comments in the stale headers, coming from completion preamble.
31 std::string
getDocComment(const ASTContext
&Ctx
,
32 const CodeCompletionResult
&Result
,
33 bool CommentsFromHeaders
);
35 /// Similar to getDocComment, but returns the comment for a NamedDecl.
36 std::string
getDeclComment(const ASTContext
&Ctx
, const NamedDecl
&D
);
38 /// Formats the signature for an item, as a display string and snippet.
39 /// e.g. for const_reference std::vector<T>::at(size_type) const, this returns:
40 /// *Signature = "(size_type) const"
41 /// *Snippet = "(${1:size_type})"
42 /// If set, RequiredQualifiers is the text that must be typed before the name.
43 /// e.g "Base::" when calling a base class member function that's hidden.
45 /// If \p IncludeFunctionArguments is disabled, the \p Snippet will only
46 /// contain function name and template arguments, if any.
48 /// When \p ResultKind is RK_Pattern, the last placeholder will be $0,
49 /// indicating the cursor should stay there.
50 /// Note that for certain \p CursorKind like \p CXCursor_Constructor, $0 won't
51 /// be emitted in order to avoid overlapping normal parameters.
52 void getSignature(const CodeCompletionString
&CCS
, std::string
*Signature
,
54 CodeCompletionResult::ResultKind ResultKind
,
55 CXCursorKind CursorKind
, bool IncludeFunctionArguments
= true,
56 std::string
*RequiredQualifiers
= nullptr);
58 /// Assembles formatted documentation for a completion result. This includes
59 /// documentation comments and other relevant information like annotations.
61 /// \param DocComment is a documentation comment for the original declaration,
62 /// it should be obtained via getDocComment or getParameterDocComment.
63 std::string
formatDocumentation(const CodeCompletionString
&CCS
,
64 llvm::StringRef DocComment
);
66 /// Gets detail to be used as the detail field in an LSP completion item. This
67 /// is usually the return type of a function.
68 std::string
getReturnType(const CodeCompletionString
&CCS
);
73 #endif // LLVM_CLANG_TOOLS_EXTRA_CLANGD_CODECOMPLETIONSTRINGS_H