-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrustlanguagesupport.cpp
More file actions
154 lines (124 loc) · 5.54 KB
/
rustlanguagesupport.cpp
File metadata and controls
154 lines (124 loc) · 5.54 KB
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
/*****************************************************************************
* This file is based on file from kdev-php, original authors: *
* Copyright (c) 2007 Piyush verma <piyush.verma@gmail.com> *
* Copyright (c) 2009 Niko Sams <niko.sams@gmail.com> *
* Copyright (c) 2010 Milian Wolff <mail@milianw.de> *
* *
* This file is part of kdev-rust *
* Copyright (c) 2016 Michal Srb <michalsrb@gmail.com> *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
*****************************************************************************/
#include "rustlanguagesupport.h"
#include <QAction>
#include <QMutexLocker>
#include <QReadWriteLock>
#include <kpluginfactory.h>
#include <kpluginloader.h>
#include <KTextEditor/Document>
#include <KActionCollection>
#include <interfaces/icore.h>
#include <interfaces/ilanguagecontroller.h>
#include <interfaces/iplugincontroller.h>
#include <interfaces/idocument.h>
#include <interfaces/iproject.h>
#include <language/backgroundparser/backgroundparser.h>
#include <language/duchain/duchain.h>
#include <language/duchain/duchaindumper.h>
#include <language/duchain/duchainlock.h>
#include <language/duchain/duchainutils.h>
#include <interfaces/idocumentcontroller.h>
#include <interfaces/contextmenuextension.h>
#include <language/interfaces/editorcontext.h>
#include "rustparsejob.h"
#include "rusthighlighting.h"
#include "codegen/refactoring.h"
#include "settings/rustsettings/rustsettings.h"
#include <language/codecompletion/codecompletion.h>
#include <language/codecompletion/codecompletionmodel.h>
#include <language/duchain/parsingenvironment.h>
using namespace KTextEditor;
using namespace KDevelop;
K_PLUGIN_FACTORY_WITH_JSON(KDevRustSupportFactory, "kdevrustsupport.json", registerPlugin<Rust::LanguageSupport>(); )
namespace Rust
{
LanguageSupport::LanguageSupport(QObject* parent, const QVariantList& /*args*/)
: KDevelop::IPlugin(QStringLiteral("kdevrustsupport"), parent),
KDevelop::ILanguageSupport()
{
KDEV_USE_EXTENSION_INTERFACE(KDevelop::ILanguageSupport)
setXMLFile(QStringLiteral("kdevrustsupport.rc"));
m_highlighting = new Rust::Highlighting(this);
m_refactoring = new Rust::Refactoring(this);
}
LanguageSupport::~LanguageSupport()
{
parseLock()->lockForWrite();
//By locking the parse-mutexes, we make sure that parse- and preprocess-jobs
//get a chance to finish in a good state
parseLock()->unlock();
}
KDevelop::ParseJob *LanguageSupport::createParseJob(const IndexedString &url)
{
return new ParseJob(url, this);
}
QString LanguageSupport::name() const
{
return QStringLiteral("Rust");
}
KDevelop::ICodeHighlighting* LanguageSupport::codeHighlighting() const
{
return m_highlighting;
}
KDevelop::ContextMenuExtension LanguageSupport::contextMenuExtension(Context* context)
{
ContextMenuExtension cm;
EditorContext *ed = dynamic_cast<KDevelop::EditorContext *>(context);
if (ed && ICore::self()->languageController()->languagesForUrl(ed->url()).contains(this)) {
// It's safe to add our own ContextMenuExtension.
m_refactoring->fillContextMenu(cm, context);
}
return cm;
}
void LanguageSupport::createActionsForMainWindow (Sublime::MainWindow* /*window*/, QString& _xmlFile, KActionCollection& actions)
{
_xmlFile = xmlFile();
QAction* renameDeclarationAction = actions.addAction(QStringLiteral("dump_duchain"));
renameDeclarationAction->setText( i18n("Dump Duchain") );
renameDeclarationAction->setIcon(QIcon::fromTheme(QStringLiteral("edit-rename")));
actions.setDefaultShortcut(renameDeclarationAction, Qt::CTRL | Qt::SHIFT | Qt::Key_D);
connect(renameDeclarationAction, &QAction::triggered, this, &LanguageSupport::dumpDuchainAction);
}
void LanguageSupport::dumpDuchainAction()
{
KDevelop::DUChainReadLocker readLock(KDevelop::DUChain::lock());
auto url = ICore::self()->documentController()->activeDocument()->url();
KDevelop::TopDUContext *topContext = KDevelop::DUChainUtils::standardContextForUrl(url);
if(!topContext) {
qWarning() << "No valid top context";
return;
}
DUChainDumper dumper(DUChainDumper::Feature::DumpContext);
dumper.dump(topContext, 100);
}
KDevelop::ConfigPage* LanguageSupport::configPage(int number, QWidget* parent)
{
return number == 0 ? new RustSettings(parent) : nullptr;
}
int LanguageSupport::configPages() const
{
return 1;
}
}
#include "rustlanguagesupport.moc"