8#include <QtQmlDom/private/qqmldomitem_p.h>
9#include <QtQmlDom/private/qqmldomindentinglinewriter_p.h>
10#include <QtQmlDom/private/qqmldomcodeformatter_p.h>
11#include <QtQmlDom/private/qqmldomoutwriter_p.h>
12#include <QtQmlDom/private/qqmldommock_p.h>
13#include <QtQmlDom/private/qqmldomcompare_p.h>
26 return u
"QQmlRangeFormatting"_s;
35 QLspSpecification::InitializeResult &serverCapabilities)
37 serverCapabilities.capabilities.documentRangeFormattingProvider =
true;
43 QList<QLspSpecification::TextEdit>
result{};
55 envPtr->clearReferenceCache();
58 auto code = qmlFile->code();
61 const auto selectedRange =
request->m_parameters.range;
62 const auto selectedRangeStartLine = selectedRange.start.line;
63 const auto selectedRangeEndLine = selectedRange.end.line;
64 Q_ASSERT(selectedRangeStartLine >= 0);
78 const auto line =
in.readLine();
79 partialStatus = formatCodeLine(
line, options.
formatOptions, partialStatus.currentStatus);
80 if (++lineNumber >= selectedRangeStartLine)
87 QString(), options, partialStatus.currentStatus);
89 ow.indentNextlines =
true;
96 bool previousIsSpace =
false;
102 if (
c ==
'\n'_L1 && newLineCount < 2) {
106 && newLineCount < 2) {
111 if (!previousIsSpace)
114 previousIsSpace =
true;
117 previousIsSpace =
false;
128 const auto &toFormat = code.
mid(startOffset, endOffset - startOffset);
129 ow.write(removeSpaces(toFormat));
134 code.
replace(startOffset, toFormat.length(), resultText);
136 QLspSpecification::TextEdit
add;
138 add.range = { { 0, 0 }, { documentLineCount + 1 } };
Implements a server for the language server protocol.
Represents a consistent set of types organized in modules, it is the top level of the DOM.
DomItem fileObject(GoTo option=GoTo::Strict) const
AttributesSequence attributesSequence
FormatOptions formatOptions
A QmlFile, when loaded in a DomEnvironment that has the DomCreationOption::WithSemanticAnalysis,...
static QByteArray lspUriToQmlUrl(const QByteArray &uri)
static qsizetype textOffsetFrom(const QString &code, int row, int character)
Convert a text position from (line, column) into an offset.
static QQmlLSUtilsTextPosition textRowAndColumnFrom(const QString &code, qsizetype offset)
Convert a text position from an offset into (line, column).
\macro QT_RESTRICTED_CAST_FROM_ASCII
QString & replace(qsizetype i, qsizetype len, QChar after)
QString mid(qsizetype position, qsizetype n=-1) const &
const QChar at(qsizetype i) const
Returns the character at the given index position in the string.
QByteArray toUtf8() const &
qsizetype length() const noexcept
Returns the number of characters in this string.
OpenDocumentSnapshot snapshot
OpenDocument openDocumentByUrl(const QByteArray &url)
Combined button and popup list for selecting options.
#define Q_DECLARE_LOGGING_CATEGORY(name)
static void add(QPainterPath &path, const QWingedEdge &list, int edge, QPathEdge::Traversal traversal)
QTextStream out(stdout)
[7]
QNetworkRequest request(url)
decltype(auto) getRequestHandler()
QmlLsp::QQmlCodeModel * m_codeModel