forked from hugopl/RubyCreator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
RubyPlugin.cpp
151 lines (123 loc) · 4.71 KB
/
RubyPlugin.cpp
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
#include "RubyPlugin.h"
#include "RubyConstants.h"
#include "editor/RubyCodeModel.h"
#include "editor/RubyCodeStylePreferencesFactory.h"
#include "editor/RubyEditorFactory.h"
#include "editor/RubyHighlighter.h"
#include "editor/RubyQuickFixAssistProvider.h"
#include "editor/RubyQuickFixes.h"
#include "editor/RubySymbolFilter.h"
#include "editor/RubyCompletionAssist.h"
#include "editor/RubyRubocopHighlighter.h"
#include "projectmanager/RubyProject.h"
#include "projectmanager/RubyProjectWizard.h"
#include "projectmanager/RubyRunConfiguration.h"
#include <coreplugin/icore.h>
#include <projectexplorer/projectmanager.h>
#include <texteditor/codestylepool.h>
#include <texteditor/simplecodestylepreferences.h>
#include <texteditor/snippets/snippetprovider.h>
#include <texteditor/tabsettings.h>
#include <texteditor/texteditor.h>
#include <texteditor/texteditorsettings.h>
namespace Ruby {
class PluginPrivate
{
public:
EditorFactory editorFactory;
RunConfigurationFactory runConfigFactory;
SymbolFilter curDocumentMethodsSymbolFilter;
SymbolFilter methodsSymbolFilter;
SymbolFilter classesSymbolFilter;
ProjectWizard projectWizard;
CompletionAssistProvider completionAssistProvider;
QuickFixAssistProvider m_quickFixProvider;
RubocopHighlighter highlighter;
PluginPrivate() :
curDocumentMethodsSymbolFilter([](const QString &file) {
return CodeModel::instance()->methodsIn(file);
}, "Ruby Methods in Current Document", '.'),
methodsSymbolFilter([](const QString &) {
return CodeModel::instance()->allMethods();
}, "Ruby methods", 'm'),
classesSymbolFilter([](const QString &) {
return CodeModel::instance()->allClasses();
}, "Ruby classes", 'c')
{}
};
Plugin *Plugin::m_instance = nullptr;
Plugin::Plugin()
{
m_instance = this;
}
Plugin::~Plugin()
{
TextEditor::TextEditorSettings::unregisterCodeStyle(Constants::SettingsId);
TextEditor::TextEditorSettings::unregisterCodeStylePool(Constants::SettingsId);
TextEditor::TextEditorSettings::unregisterCodeStyleFactory(Constants::SettingsId);
m_instance = nullptr;
delete d;
}
Plugin *Plugin::instance()
{
return m_instance;
}
bool Plugin::initialize(const QStringList &, QString *errorString)
{
Q_UNUSED(errorString)
initializeToolsSettings();
d = new PluginPrivate;
ProjectExplorer::ProjectManager::registerProjectType<Project>(Constants::ProjectMimeType);
Core::IWizardFactory::registerFactoryCreator([]() {
return new ProjectWizard;
});
registerQuickFixes(this);
TextEditor::SnippetProvider::registerGroup(Constants::SnippetGroupId,
tr("Ruby", "SnippetProvider"),
&EditorFactory::decorateEditor);
return true;
}
void Plugin::extensionsInitialized()
{
}
QuickFixAssistProvider *Plugin::quickFixProvider()
{
return &d->m_quickFixProvider;
}
void Plugin::initializeToolsSettings()
{
// code style factory
auto factory = new CodeStylePreferencesFactory;
TextEditor::TextEditorSettings::registerCodeStyleFactory(factory);
// code style pool
auto pool = new TextEditor::CodeStylePool(factory, this);
TextEditor::TextEditorSettings::registerCodeStylePool(Constants::SettingsId, pool);
// global code style settings
auto globalCodeStyle = new TextEditor::SimpleCodeStylePreferences(this);
globalCodeStyle->setDelegatingPool(pool);
globalCodeStyle->setDisplayName(tr("Global", "Settings"));
globalCodeStyle->setId("RubyGlobal");
pool->addCodeStyle(globalCodeStyle);
TextEditor::TextEditorSettings::registerCodeStyle(Constants::SettingsId, globalCodeStyle);
// built-in settings
// Ruby style
auto rubyCodeStyle = new TextEditor::SimpleCodeStylePreferences;
rubyCodeStyle->setId("ruby");
rubyCodeStyle->setDisplayName(tr("RubyCreator"));
rubyCodeStyle->setReadOnly(true);
TextEditor::TabSettings tabSettings;
tabSettings.m_tabPolicy = TextEditor::TabSettings::SpacesOnlyTabPolicy;
tabSettings.m_tabSize = 2;
tabSettings.m_indentSize = 2;
tabSettings.m_continuationAlignBehavior = TextEditor::TabSettings::ContinuationAlignWithIndent;
rubyCodeStyle->setTabSettings(tabSettings);
pool->addCodeStyle(rubyCodeStyle);
// default delegate for global preferences
globalCodeStyle->setCurrentDelegate(rubyCodeStyle);
pool->loadCustomCodeStyles();
// load global settings (after built-in settings are added to the pool)
globalCodeStyle->fromSettings(Constants::SettingsId, Core::ICore::settings());
// mimetypes to be handled
TextEditor::TextEditorSettings::registerMimeTypeForLanguageId(Constants::MimeType, Constants::SettingsId);
}
}