From 2f69373309cfe88084c5777baeff6bb46eecd071 Mon Sep 17 00:00:00 2001 From: Eike Ziller Date: Mon, 24 Apr 2017 16:42:24 +0200 Subject: Provide snippet group --- plugins/haskell/haskell.pro | 18 +++++++----- plugins/haskell/haskellcompletionassist.cpp | 44 ++++++++++++++++++++++++++++ plugins/haskell/haskellcompletionassist.h | 45 +++++++++++++++++++++++++++++ plugins/haskell/haskellconstants.h | 3 ++ plugins/haskell/haskelleditorfactory.cpp | 11 +++---- plugins/haskell/haskellplugin.cpp | 5 ++++ 6 files changed, 114 insertions(+), 12 deletions(-) create mode 100644 plugins/haskell/haskellcompletionassist.cpp create mode 100644 plugins/haskell/haskellcompletionassist.h diff --git a/plugins/haskell/haskell.pro b/plugins/haskell/haskell.pro index f6aabb2..9c557b1 100644 --- a/plugins/haskell/haskell.pro +++ b/plugins/haskell/haskell.pro @@ -2,13 +2,17 @@ DEFINES += HASKELL_LIBRARY # Haskell files -SOURCES += haskellplugin.cpp \ - haskelleditorfactory.cpp - -HEADERS += haskellplugin.h \ - haskell_global.h \ - haskellconstants.h \ - haskelleditorfactory.h +SOURCES += \ + haskellcompletionassist.cpp \ + haskelleditorfactory.cpp \ + haskellplugin.cpp + +HEADERS += \ + haskell_global.h \ + haskellcompletionassist.h \ + haskellconstants.h \ + haskelleditorfactory.h \ + haskellplugin.h ## uncomment to build plugin into user config directory ## /plugins/ diff --git a/plugins/haskell/haskellcompletionassist.cpp b/plugins/haskell/haskellcompletionassist.cpp new file mode 100644 index 0000000..aa053f5 --- /dev/null +++ b/plugins/haskell/haskellcompletionassist.cpp @@ -0,0 +1,44 @@ +/**************************************************************************** +** +** Copyright (C) 2017 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** 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 +** 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. +** +** 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. +** +****************************************************************************/ + +#include "haskellcompletionassist.h" + +#include "haskellconstants.h" + +#include +#include + +namespace Haskell { +namespace Internal { + +TextEditor::IAssistProcessor *HaskellCompletionAssistProvider::createProcessor() const +{ + auto processor = new TextEditor::KeywordsCompletionAssistProcessor(TextEditor::Keywords()); + processor->setSnippetGroup(Constants::C_HASKELLSNIPPETSGROUP_ID); + return processor; +} + +} // namespace Internal +} // namespace Haskell diff --git a/plugins/haskell/haskellcompletionassist.h b/plugins/haskell/haskellcompletionassist.h new file mode 100644 index 0000000..9b3f0ca --- /dev/null +++ b/plugins/haskell/haskellcompletionassist.h @@ -0,0 +1,45 @@ +/**************************************************************************** +** +** Copyright (C) 2017 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** 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 +** 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. +** +** 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. +** +****************************************************************************/ + +#ifndef HASKELLCOMPLETIONASSIST_H +#define HASKELLCOMPLETIONASSIST_H + +#include + +namespace Haskell { +namespace Internal { + +class HaskellCompletionAssistProvider : public TextEditor::CompletionAssistProvider +{ + Q_OBJECT + +public: + TextEditor::IAssistProcessor *createProcessor() const override; +}; + +} // namespace Internal +} // namespace Haskell + +#endif // HASKELLCOMPLETIONASSIST_H diff --git a/plugins/haskell/haskellconstants.h b/plugins/haskell/haskellconstants.h index 05b5c91..55be670 100644 --- a/plugins/haskell/haskellconstants.h +++ b/plugins/haskell/haskellconstants.h @@ -28,5 +28,8 @@ namespace Haskell { namespace Constants { +const char C_HASKELLEDITOR_ID[] = "Haskell.HaskellEditor"; +const char C_HASKELLSNIPPETSGROUP_ID[] = "Haskell"; + } // namespace Haskell } // namespace Constants diff --git a/plugins/haskell/haskelleditorfactory.cpp b/plugins/haskell/haskelleditorfactory.cpp index 704f7f4..220e52e 100644 --- a/plugins/haskell/haskelleditorfactory.cpp +++ b/plugins/haskell/haskelleditorfactory.cpp @@ -25,27 +25,28 @@ #include "haskelleditorfactory.h" +#include "haskellcompletionassist.h" +#include "haskellconstants.h" + #include #include #include -const char C_HASKELLEDITOR_ID[] = "Haskell.HaskellEditor"; - namespace Haskell { namespace Internal { HaskellEditorFactory::HaskellEditorFactory() { - setId(C_HASKELLEDITOR_ID); + setId(Constants::C_HASKELLEDITOR_ID); setDisplayName(QCoreApplication::translate("OpenWith::Editors", "Haskell Editor")); addMimeType("text/x-haskell"); setEditorActionHandlers(TextEditor::TextEditorActionHandler::UnCommentSelection); - - setDocumentCreator([] { return new TextEditor::TextDocument(C_HASKELLEDITOR_ID); }); + setDocumentCreator([] { return new TextEditor::TextDocument(Constants::C_HASKELLEDITOR_ID); }); setCommentDefinition(Utils::CommentDefinition("--", "{-", "-}")); setParenthesesMatchingEnabled(true); setMarksVisible(true); + setCompletionAssistProvider(new HaskellCompletionAssistProvider); } } // Internal diff --git a/plugins/haskell/haskellplugin.cpp b/plugins/haskell/haskellplugin.cpp index 8df9961..fd6827f 100644 --- a/plugins/haskell/haskellplugin.cpp +++ b/plugins/haskell/haskellplugin.cpp @@ -27,6 +27,8 @@ #include "haskellconstants.h" #include "haskelleditorfactory.h" +#include + namespace Haskell { namespace Internal { @@ -55,6 +57,9 @@ bool HaskellPlugin::initialize(const QStringList &arguments, QString *errorStrin addAutoReleasedObject(new HaskellEditorFactory); + TextEditor::SnippetProvider::registerGroup(Constants::C_HASKELLSNIPPETSGROUP_ID, + tr("Haskell", "SnippetProvider")); + return true; } -- cgit v1.2.3