QMLLS: fix crash on opening non existing qml files

The automatic handling of the document inside the language client
manager is normally done after a document was opened successfully. Since
the QML document registers the document manually on construction before
the file was tried to be opened the automatic cleanup inside the manager
does not work. Postpone the document registration like in the
PythonDocument after the document was opened successfully.

Fixes: QTCREATORBUG-29021
Change-Id: I2dd9e2da9c9ed6d38414ad991df3c03b62e9d611
Reviewed-by: Eike Ziller <eike.ziller@qt.io>
This commit is contained in:
David Schulz
2023-04-24 07:37:49 +02:00
parent 646f95811d
commit b794e98233

View File

@@ -505,7 +505,6 @@ QmlJSEditorDocumentPrivate::QmlJSEditorDocumentPrivate(QmlJSEditorDocument *pare
this, &QmlJSEditorDocumentPrivate::updateOutlineModel); this, &QmlJSEditorDocumentPrivate::updateOutlineModel);
modelManager->updateSourceFiles(Utils::FilePaths({parent->filePath()}), false); modelManager->updateSourceFiles(Utils::FilePaths({parent->filePath()}), false);
settingsChanged();
} }
QmlJSEditorDocumentPrivate::~QmlJSEditorDocumentPrivate() QmlJSEditorDocumentPrivate::~QmlJSEditorDocumentPrivate()
@@ -818,6 +817,8 @@ QmlJSEditorDocument::QmlJSEditorDocument(Utils::Id id)
setId(id); setId(id);
connect(this, &TextEditor::TextDocument::tabSettingsChanged, connect(this, &TextEditor::TextDocument::tabSettingsChanged,
d, &Internal::QmlJSEditorDocumentPrivate::invalidateFormatterCache); d, &Internal::QmlJSEditorDocumentPrivate::invalidateFormatterCache);
connect(this, &TextEditor::TextDocument::openFinishedSuccessfully,
d, &Internal::QmlJSEditorDocumentPrivate::settingsChanged);
setSyntaxHighlighter(new QmlJSHighlighter(document())); setSyntaxHighlighter(new QmlJSHighlighter(document()));
setCodec(QTextCodec::codecForName("UTF-8")); // qml files are defined to be utf-8 setCodec(QTextCodec::codecForName("UTF-8")); // qml files are defined to be utf-8
setIndenter(new Internal::Indenter(document())); setIndenter(new Internal::Indenter(document()));