Bump version to 19.1.0git
[llvm-project.git] / clang-tools-extra / clangd / CodeCompletionStrings.h
blobfa81ad64d406c3bf135c243f20caa746bc4f29ec
1 //===--- CodeCompletionStrings.h ---------------------------------*- C++-*-===//
2 //
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
6 //
7 //===----------------------------------------------------------------------===//
8 //
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"
19 namespace clang {
20 class ASTContext;
22 namespace clangd {
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.
44 ///
45 /// If \p IncludeFunctionArguments is disabled, the \p Snippet will only
46 /// contain function name and template arguments, if any.
47 ///
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,
53 std::string *Snippet,
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.
60 ///
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);
70 } // namespace clangd
71 } // namespace clang
73 #endif // LLVM_CLANG_TOOLS_EXTRA_CLANGD_CODECOMPLETIONSTRINGS_H