| 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`. |
| 11 |
// |
| 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 |
/// Similar to getDocComment, but returns the comment for a NamedDecl. |
| 36 |
std::string getDeclComment(const ASTContext &Ctx, const NamedDecl &D); |
| 37 |
|
| 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 |
/// When \p CompletingPattern is true, the last placeholder will be of the form |
| 46 |
/// ${0:…}, indicating the cursor should stay there. |
| 47 |
void getSignature(const CodeCompletionString &CCS, std::string *Signature, |
| 48 |
std::string *Snippet, |
| 49 |
std::string *RequiredQualifiers = nullptr, |
| 50 |
bool CompletingPattern = false); |
| 51 |
|
| 52 |
/// Assembles formatted documentation for a completion result. This includes |
| 53 |
/// documentation comments and other relevant information like annotations. |
| 54 |
/// |
| 55 |
/// \param DocComment is a documentation comment for the original declaration, |
| 56 |
/// it should be obtained via getDocComment or getParameterDocComment. |
| 57 |
std::string formatDocumentation(const CodeCompletionString &CCS, |
| 58 |
llvm::StringRef DocComment); |
| 59 |
|
| 60 |
/// Gets detail to be used as the detail field in an LSP completion item. This |
| 61 |
/// is usually the return type of a function. |
| 62 |
std::string getReturnType(const CodeCompletionString &CCS); |
| 63 |
|
| 64 |
} // namespace clangd |
| 65 |
} // namespace clang |
| 66 |
|
| 67 |
#endif // LLVM_CLANG_TOOLS_EXTRA_CLANGD_CODECOMPLETIONSTRINGS_H |