1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
|
// Copyright (C) 2020 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0+ OR GPL-3.0 WITH Qt-GPL-exception-1.0
#pragma once
#include "languageclient_global.h"
#include <coreplugin/find/searchresultitem.h>
#include <texteditor/textdocument.h>
#include <languageserverprotocol/languagefeatures.h>
#include <functional>
namespace Core {
class SearchResult;
class SearchResultItem;
}
namespace LanguageServerProtocol { class MessageId; }
namespace LanguageClient {
class Client;
class LANGUAGECLIENT_EXPORT SymbolSupport
{
Q_DECLARE_TR_FUNCTIONS(SymbolSupport)
public:
explicit SymbolSupport(Client *client);
void findLinkAt(TextEditor::TextDocument *document,
const QTextCursor &cursor,
Utils::LinkHandler callback,
const bool resolveTarget);
bool supportsFindUsages(TextEditor::TextDocument *document) const;
using ResultHandler = std::function<void(const QList<LanguageServerProtocol::Location> &)>;
std::optional<LanguageServerProtocol::MessageId> findUsages(
TextEditor::TextDocument *document,
const QTextCursor &cursor,
const ResultHandler &handler = {});
bool supportsRename(TextEditor::TextDocument *document);
void renameSymbol(TextEditor::TextDocument *document, const QTextCursor &cursor,
const QString &newSymbolName = {}, bool preferLowerCaseFileNames = true);
static Core::Search::TextRange convertRange(const LanguageServerProtocol::Range &range);
static QStringList getFileContents(const Utils::FilePath &filePath);
using SymbolMapper = std::function<QString(const QString &)>;
void setDefaultRenamingSymbolMapper(const SymbolMapper &mapper);
void setLimitRenamingToProjects(bool limit) { m_limitRenamingToProjects = limit; }
private:
void handleFindReferencesResponse(
const LanguageServerProtocol::FindReferencesRequest::Response &response,
const QString &wordUnderCursor,
const ResultHandler &handler);
void requestPrepareRename(TextEditor::TextDocument *document,
const LanguageServerProtocol::TextDocumentPositionParams ¶ms,
const QString &placeholder,
const QString &oldSymbolName,
bool preferLowerCaseFileNames);
void requestRename(const LanguageServerProtocol::TextDocumentPositionParams &positionParams,
const QString &newName, Core::SearchResult *search);
Core::SearchResult *createSearch(const LanguageServerProtocol::TextDocumentPositionParams &positionParams,
const QString &placeholder, const QString &oldSymbolName,
bool preferLowerCaseFileNames);
void startRenameSymbol(const LanguageServerProtocol::TextDocumentPositionParams ¶ms,
const QString &placeholder, const QString &oldSymbolName,
bool preferLowerCaseFileNames);
void handleRenameResponse(Core::SearchResult *search,
const LanguageServerProtocol::RenameRequest::Response &response);
void applyRename(const QList<Core::SearchResultItem> &checkedItems, Core::SearchResult *search);
Client *m_client = nullptr;
SymbolMapper m_defaultSymbolMapper;
bool m_limitRenamingToProjects = false;
};
} // namespace LanguageClient
|