2015-07-06 12:05:02 +02:00
|
|
|
/****************************************************************************
|
|
|
|
|
**
|
2016-01-15 14:57:40 +01:00
|
|
|
** Copyright (C) 2016 The Qt Company Ltd.
|
|
|
|
|
** Contact: https://www.qt.io/licensing/
|
2015-07-06 12:05:02 +02:00
|
|
|
**
|
|
|
|
|
** This file is part of Qt Creator.
|
|
|
|
|
**
|
|
|
|
|
** Commercial License Usage
|
|
|
|
|
** Licensees holding valid commercial Qt licenses may use this file in
|
|
|
|
|
** accordance with the commercial license agreement provided with the
|
|
|
|
|
** Software or, alternatively, in accordance with the terms contained in
|
2016-01-15 14:57:40 +01:00
|
|
|
** a written agreement between you and The Qt Company. For licensing terms
|
|
|
|
|
** and conditions see https://www.qt.io/terms-conditions. For further
|
|
|
|
|
** information use the contact form at https://www.qt.io/contact-us.
|
2015-07-06 12:05:02 +02:00
|
|
|
**
|
2016-01-15 14:57:40 +01:00
|
|
|
** GNU General Public License Usage
|
|
|
|
|
** Alternatively, this file may be used under the terms of the GNU
|
|
|
|
|
** General Public License version 3 as published by the Free Software
|
|
|
|
|
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
|
|
|
|
|
** included in the packaging of this file. Please review the following
|
|
|
|
|
** information to ensure the GNU General Public License requirements will
|
|
|
|
|
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
|
2015-07-06 12:05:02 +02:00
|
|
|
**
|
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
2016-03-18 07:55:01 +01:00
|
|
|
#pragma once
|
2015-07-06 12:05:02 +02:00
|
|
|
|
|
|
|
|
#include "clangcompletionassistinterface.h"
|
|
|
|
|
|
|
|
|
|
#include <cpptools/cppcompletionassistprocessor.h>
|
|
|
|
|
|
2017-08-24 12:28:01 +02:00
|
|
|
#include <clangsupport/codecompletion.h>
|
2015-07-06 12:05:02 +02:00
|
|
|
|
2016-12-05 16:08:01 +01:00
|
|
|
#include <QCoreApplication>
|
2015-12-15 11:59:48 +01:00
|
|
|
#include <QTextCursor>
|
2015-07-06 12:05:02 +02:00
|
|
|
|
|
|
|
|
namespace ClangCodeModel {
|
|
|
|
|
namespace Internal {
|
|
|
|
|
|
2015-07-22 17:33:27 +02:00
|
|
|
using ClangBackEnd::CodeCompletions;
|
2016-01-11 15:20:04 +01:00
|
|
|
using ClangBackEnd::CompletionCorrection;
|
2015-07-06 12:05:02 +02:00
|
|
|
|
|
|
|
|
class ClangCompletionAssistProcessor : public CppTools::CppCompletionAssistProcessor
|
|
|
|
|
{
|
|
|
|
|
Q_DECLARE_TR_FUNCTIONS(ClangCodeModel::Internal::ClangCompletionAssistProcessor)
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
ClangCompletionAssistProcessor();
|
2018-01-19 14:11:01 +01:00
|
|
|
~ClangCompletionAssistProcessor() override;
|
2015-07-06 12:05:02 +02:00
|
|
|
|
|
|
|
|
TextEditor::IAssistProposal *perform(const TextEditor::AssistInterface *interface) override;
|
|
|
|
|
|
2017-04-28 17:46:40 +02:00
|
|
|
void handleAvailableCompletions(const CodeCompletions &completions,
|
|
|
|
|
CompletionCorrection neededCorrection);
|
2015-07-06 12:05:02 +02:00
|
|
|
|
|
|
|
|
const TextEditor::TextEditorWidget *textEditorWidget() const;
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
TextEditor::IAssistProposal *startCompletionHelper();
|
|
|
|
|
int startOfOperator(int pos, unsigned *kind, bool wantFunctionCall) const;
|
|
|
|
|
int findStartOfName(int pos = -1) const;
|
|
|
|
|
bool accepts() const;
|
|
|
|
|
|
2016-01-11 15:20:04 +01:00
|
|
|
TextEditor::IAssistProposal *createProposal(
|
|
|
|
|
CompletionCorrection neededCorrection = CompletionCorrection::NoCorrection) const;
|
2017-04-28 17:46:40 +02:00
|
|
|
TextEditor::IAssistProposal *createFunctionHintProposal(
|
|
|
|
|
const CodeCompletions &completions) const;
|
2015-07-06 12:05:02 +02:00
|
|
|
|
|
|
|
|
bool completeInclude(const QTextCursor &cursor);
|
|
|
|
|
bool completeInclude(int position);
|
|
|
|
|
void completeIncludePath(const QString &realPath, const QStringList &suffixes);
|
|
|
|
|
bool completePreprocessorDirectives();
|
|
|
|
|
bool completeDoxygenKeywords();
|
|
|
|
|
void addCompletionItem(const QString &text,
|
|
|
|
|
const QIcon &icon = QIcon(),
|
2016-01-28 15:35:18 +01:00
|
|
|
int order = 0);
|
2015-07-06 12:05:02 +02:00
|
|
|
|
2015-07-20 13:24:06 +02:00
|
|
|
struct UnsavedFileContentInfo {
|
|
|
|
|
QByteArray unsavedContent;
|
|
|
|
|
bool isDocumentModified = false;
|
|
|
|
|
};
|
|
|
|
|
UnsavedFileContentInfo unsavedFileContent(const QByteArray &customFileContent) const;
|
|
|
|
|
|
2015-10-13 15:56:41 +02:00
|
|
|
void sendFileContent(const QByteArray &customFileContent);
|
2017-08-10 10:24:54 +02:00
|
|
|
bool sendCompletionRequest(int position,
|
|
|
|
|
const QByteArray &customFileContent,
|
|
|
|
|
int functionNameStartPosition = -1);
|
2015-07-06 12:05:02 +02:00
|
|
|
|
|
|
|
|
private:
|
2017-08-10 10:24:54 +02:00
|
|
|
struct Position { int line; int column; };
|
|
|
|
|
Position extractLineColumn(int position);
|
|
|
|
|
|
2015-07-06 12:05:02 +02:00
|
|
|
QScopedPointer<const ClangCompletionAssistInterface> m_interface;
|
|
|
|
|
unsigned m_completionOperator;
|
|
|
|
|
enum CompletionRequestType { NormalCompletion, FunctionHintCompletion } m_sentRequestType;
|
|
|
|
|
bool m_addSnippets = false; // For type == Type::NormalCompletion
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
} // namespace Internal
|
|
|
|
|
} // namespace ClangCodeModel
|