forked from qt-creator/qt-creator
Introduce JSON validation
Support basic validation for JSON files according to the draft http://tools.ietf.org/html/draft-zyp-json-schema-03. This is not a complete implementation yet, but it should already be useful, since "type" verification along with many of the attributes is done. Change-Id: I364bc98dd92937c5e2ea9cba7e15ed8e03eb9beb Reviewed-by: Erik Verbruggen <erik.verbruggen@nokia.com>
This commit is contained in:
@@ -70,6 +70,7 @@
|
||||
#include <texteditor/textfilewizard.h>
|
||||
#include <texteditor/texteditoractionhandler.h>
|
||||
#include <utils/qtcassert.h>
|
||||
#include <utils/json.h>
|
||||
|
||||
#include <QtCore/QtPlugin>
|
||||
#include <QtCore/QDebug>
|
||||
@@ -98,7 +99,10 @@ QmlJSEditorPlugin::QmlJSEditorPlugin() :
|
||||
m_actionHandler(0),
|
||||
m_quickFixAssistProvider(0),
|
||||
m_reformatFileAction(0),
|
||||
m_currentEditor(0)
|
||||
m_currentEditor(0),
|
||||
m_jsonManager(new Utils::JsonSchemaManager(
|
||||
QStringList() << Core::ICore::instance()->userResourcePath() + QLatin1String("/json/")
|
||||
<< Core::ICore::instance()->resourcePath() + QLatin1String("/json/")))
|
||||
{
|
||||
m_instance = this;
|
||||
}
|
||||
@@ -285,6 +289,11 @@ void QmlJSEditorPlugin::initializeEditor(QmlJSEditor::QmlJSTextEditorWidget *edi
|
||||
TextEditor::TextEditorSettings::instance()->initializeEditor(editor);
|
||||
}
|
||||
|
||||
Utils::JsonSchemaManager *QmlJSEditorPlugin::jsonManager() const
|
||||
{
|
||||
return m_jsonManager.data();
|
||||
}
|
||||
|
||||
void QmlJSEditorPlugin::followSymbolUnderCursor()
|
||||
{
|
||||
Core::EditorManager *em = Core::EditorManager::instance();
|
||||
|
||||
@@ -36,10 +36,15 @@
|
||||
#include <extensionsystem/iplugin.h>
|
||||
#include <coreplugin/icontext.h>
|
||||
#include <coreplugin/id.h>
|
||||
|
||||
#include <QtCore/QPointer>
|
||||
|
||||
QT_FORWARD_DECLARE_CLASS(QAction)
|
||||
|
||||
namespace Utils {
|
||||
class JsonSchemaManager;
|
||||
}
|
||||
|
||||
namespace TextEditor {
|
||||
class TextEditorActionHandler;
|
||||
} // namespace TextEditor
|
||||
@@ -91,6 +96,8 @@ public:
|
||||
|
||||
void initializeEditor(QmlJSEditor::QmlJSTextEditorWidget *editor);
|
||||
|
||||
Utils::JsonSchemaManager *jsonManager() const;
|
||||
|
||||
public Q_SLOTS:
|
||||
void followSymbolUnderCursor();
|
||||
void findUsages();
|
||||
@@ -118,6 +125,7 @@ private:
|
||||
QAction *m_reformatFileAction;
|
||||
|
||||
QPointer<QmlJSTextEditorWidget> m_currentEditor;
|
||||
QScopedPointer<Utils::JsonSchemaManager> m_jsonManager;
|
||||
};
|
||||
|
||||
} // namespace Internal
|
||||
|
||||
@@ -31,14 +31,20 @@
|
||||
**************************************************************************/
|
||||
|
||||
#include "qmljssemanticinfoupdater.h"
|
||||
#include "qmljseditorplugin.h"
|
||||
|
||||
#include <qmljs/qmljsmodelmanagerinterface.h>
|
||||
#include <qmljs/qmljsdocument.h>
|
||||
#include <qmljs/qmljscheck.h>
|
||||
#include <qmljs/jsoncheck.h>
|
||||
#include <qmljs/qmljscontext.h>
|
||||
#include <qmljs/qmljslink.h>
|
||||
#include <qmljstools/qmljsmodelmanager.h>
|
||||
|
||||
#include <coreplugin/icore.h>
|
||||
|
||||
#include <utils/json.h>
|
||||
|
||||
namespace QmlJSEditor {
|
||||
namespace Internal {
|
||||
|
||||
@@ -125,7 +131,14 @@ SemanticInfo SemanticInfoUpdater::makeNewSemanticInfo(const QmlJS::Document::Ptr
|
||||
ScopeChain *scopeChain = new ScopeChain(doc, semanticInfo.context);
|
||||
semanticInfo.m_rootScopeChain = QSharedPointer<const ScopeChain>(scopeChain);
|
||||
|
||||
if (doc->language() != Document::JsonLanguage) {
|
||||
if (doc->language() == Document::JsonLanguage) {
|
||||
Utils::JsonSchema *schema =
|
||||
QmlJSEditorPlugin::instance()->jsonManager()->schemaForFile(doc->fileName());
|
||||
if (schema) {
|
||||
JsonCheck jsonChecker(doc);
|
||||
semanticInfo.staticAnalysisMessages = jsonChecker(schema);
|
||||
}
|
||||
} else {
|
||||
Check checker(doc, semanticInfo.context);
|
||||
semanticInfo.staticAnalysisMessages = checker();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user