clang-tools  8.0.0
CodeCompletionStrings.h
Go to the documentation of this file.
1 //===--- CodeCompletionStrings.h ---------------------------------*- C++-*-===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // Functions for retrieving code completion information from
11 // `CodeCompletionString`.
12 //
13 //===----------------------------------------------------------------------===//
14 
15 #ifndef LLVM_CLANG_TOOLS_EXTRA_CLANGD_CODECOMPLETIONSTRINGS_H
16 #define LLVM_CLANG_TOOLS_EXTRA_CLANGD_CODECOMPLETIONSTRINGS_H
17 
18 #include "clang/Sema/CodeCompleteConsumer.h"
19 
20 namespace clang {
21 class ASTContext;
22 
23 namespace clangd {
24 
25 /// Gets a minimally formatted documentation comment of \p Result, with comment
26 /// markers stripped. See clang::RawComment::getFormattedText() for the detailed
27 /// explanation of how the comment text is transformed.
28 /// Returns empty string when no comment is available.
29 /// If \p CommentsFromHeaders parameter is set, only comments from the main
30 /// file will be returned. It is used to workaround crashes when parsing
31 /// comments in the stale headers, coming from completion preamble.
32 std::string getDocComment(const ASTContext &Ctx,
33  const CodeCompletionResult &Result,
34  bool CommentsFromHeaders);
35 
36 /// Similar to getDocComment, but returns the comment for a NamedDecl.
37 std::string getDeclComment(const ASTContext &Ctx, const NamedDecl &D);
38 
39 /// Formats the signature for an item, as a display string and snippet.
40 /// e.g. for const_reference std::vector<T>::at(size_type) const, this returns:
41 /// *Signature = "(size_type) const"
42 /// *Snippet = "(${0:size_type})"
43 /// If set, RequiredQualifiers is the text that must be typed before the name.
44 /// e.g "Base::" when calling a base class member function that's hidden.
45 void getSignature(const CodeCompletionString &CCS, std::string *Signature,
46  std::string *Snippet,
47  std::string *RequiredQualifiers = nullptr);
48 
49 /// Assembles formatted documentation for a completion result. This includes
50 /// documentation comments and other relevant information like annotations.
51 ///
52 /// \param DocComment is a documentation comment for the original declaration,
53 /// it should be obtained via getDocComment or getParameterDocComment.
54 std::string formatDocumentation(const CodeCompletionString &CCS,
55  llvm::StringRef DocComment);
56 
57 /// Gets detail to be used as the detail field in an LSP completion item. This
58 /// is usually the return type of a function.
59 std::string getReturnType(const CodeCompletionString &CCS);
60 
61 } // namespace clangd
62 } // namespace clang
63 
64 #endif // LLVM_CLANG_TOOLS_EXTRA_CLANGD_CODECOMPLETIONSTRINGS_H
std::string getDocComment(const ASTContext &Ctx, const CodeCompletionResult &Result, bool CommentsFromHeaders)
Gets a minimally formatted documentation comment of Result, with comment markers stripped.
std::string getReturnType(const CodeCompletionString &CCS)
Gets detail to be used as the detail field in an LSP completion item.
Context Ctx
std::string Signature
const Decl * D
Definition: XRefs.cpp:79
llvm::Optional< llvm::Expected< tooling::AtomicChanges > > Result
std::string formatDocumentation(const CodeCompletionString &CCS, llvm::StringRef DocComment)
Assembles formatted documentation for a completion result.
std::string getDeclComment(const ASTContext &Ctx, const NamedDecl &Decl)
Similar to getDocComment, but returns the comment for a NamedDecl.
void getSignature(const CodeCompletionString &CCS, std::string *Signature, std::string *Snippet, std::string *RequiredQualifiers)
Formats the signature for an item, as a display string and snippet.
===– Representation.cpp - ClangDoc Representation --------—*- C++ -*-===//