clang-tools  7.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 #ifndef LLVM_CLANG_TOOLS_EXTRA_CLANGD_CODECOMPLETIONSTRINGS_H
15 #define LLVM_CLANG_TOOLS_EXTRA_CLANGD_CODECOMPLETIONSTRINGS_H
16 
17 #include "clang/Sema/CodeCompleteConsumer.h"
18 
19 namespace clang {
20 class ASTContext;
21 
22 namespace clangd {
23 
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);
34 
35 /// Gets a minimally formatted documentation for parameter of \p Result,
36 /// corresponding to argument number \p ArgIndex.
37 /// This currently looks for comments attached to the parameter itself, and
38 /// doesn't extract them from function documentation.
39 /// Returns empty string when no comment is available.
40 /// If \p CommentsFromHeaders parameter is set, only comments from the main
41 /// file will be returned. It is used to workaround crashes when parsing
42 /// comments in the stale headers, coming from completion preamble.
43 std::string
44 getParameterDocComment(const ASTContext &Ctx,
45  const CodeCompleteConsumer::OverloadCandidate &Result,
46  unsigned ArgIndex, bool CommentsFromHeaders);
47 
48 /// Formats the signature for an item, as a display string and snippet.
49 /// e.g. for const_reference std::vector<T>::at(size_type) const, this returns:
50 /// *Signature = "(size_type) const"
51 /// *Snippet = "(${0:size_type})"
52 /// If set, RequiredQualifiers is the text that must be typed before the name.
53 /// e.g "Base::" when calling a base class member function that's hidden.
54 void getSignature(const CodeCompletionString &CCS, std::string *Signature,
55  std::string *Snippet,
56  std::string *RequiredQualifiers = nullptr);
57 
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);
65 
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);
69 
70 } // namespace clangd
71 } // namespace clang
72 
73 #endif
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.
std::string formatDocumentation(const CodeCompletionString &CCS, llvm::StringRef DocComment)
Assembles formatted documentation for a completion result.
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++ -*-===//
tooling::ExecutionContext * Ctx
std::string getParameterDocComment(const ASTContext &Ctx, const CodeCompleteConsumer::OverloadCandidate &Result, unsigned ArgIndex, bool CommentsFromHeaders)
Gets a minimally formatted documentation for parameter of Result, corresponding to argument number Ar...
std::string Signature