brintos

brintos / llvm-project-archived public Read only

0
0
Text · 3.3 KiB · fa81ad6 Raw
74 lines · c
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-exception6//7//===----------------------------------------------------------------------===//8//9// Functions for retrieving code completion information from10// `CodeCompletionString`.11//12//===----------------------------------------------------------------------===//13 14#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANGD_CODECOMPLETIONSTRINGS_H15#define LLVM_CLANG_TOOLS_EXTRA_CLANGD_CODECOMPLETIONSTRINGS_H16 17#include "clang/Sema/CodeCompleteConsumer.h"18 19namespace clang {20class ASTContext;21 22namespace clangd {23 24/// Gets a minimally formatted documentation comment of \p Result, with comment25/// markers stripped. See clang::RawComment::getFormattedText() for the detailed26/// 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 main29/// file will be returned. It is used to workaround crashes when parsing30/// comments in the stale headers, coming from completion preamble.31std::string getDocComment(const ASTContext &Ctx,32                          const CodeCompletionResult &Result,33                          bool CommentsFromHeaders);34 35/// Similar to getDocComment, but returns the comment for a NamedDecl.36std::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/// If \p IncludeFunctionArguments is disabled, the \p Snippet will only46/// 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't51/// be emitted in order to avoid overlapping normal parameters.52void 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);57 58/// Assembles formatted documentation for a completion result. This includes59/// 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.63std::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. This67/// is usually the return type of a function.68std::string getReturnType(const CodeCompletionString &CCS);69 70} // namespace clangd71} // namespace clang72 73#endif // LLVM_CLANG_TOOLS_EXTRA_CLANGD_CODECOMPLETIONSTRINGS_H74