brintos

brintos / llvm-project-archived public Read only

0
0
Text · 2.0 KiB · b048f8b Raw
56 lines · c
1//===--- Format.h - automatic code formatting ---------------*- 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// Clangd uses clang-format for formatting operations.10// This file adapts it to support new scenarios like format-on-type.11//12//===----------------------------------------------------------------------===//13#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANGD_FORMAT_H14#define LLVM_CLANG_TOOLS_EXTRA_CLANGD_FORMAT_H15 16#include "clang/Format/Format.h"17#include "clang/Tooling/Core/Replacement.h"18#include "llvm/ADT/StringRef.h"19 20namespace clang {21namespace clangd {22 23/// Applies limited formatting around new \p InsertedText.24/// The \p Code already contains the updated text before \p Cursor, and may have25/// had additional / characters (such as indentation) inserted by the editor.26///27/// Example breaking a line (^ is the cursor):28/// === before newline is typed ===29/// if(1){^}30/// === after newline is typed and editor indents ===31/// if(1){32///   ^}33/// === after formatIncremental(InsertedText="\n") ===34/// if (1) {35///   ^36/// }37///38/// We return sorted vector<tooling::Replacement>, not tooling::Replacements!39/// We may insert text both before and after the cursor. tooling::Replacements40/// would merge these, and thus lose information about cursor position.41std::vector<tooling::Replacement>42formatIncremental(llvm::StringRef Code, unsigned Cursor,43                  llvm::StringRef InsertedText, format::FormatStyle Style);44 45/// Determine the new cursor position after applying \p Replacements.46/// Analogue of tooling::Replacements::getShiftedCodePosition().47unsigned48transformCursorPosition(unsigned Offset,49                        const std::vector<tooling::Replacement> &Replacements);50 51} // namespace clangd52} // namespace clang53 54#endif55 56