diff --git a/src/plugins/python/pythoneditor.cpp b/src/plugins/python/pythoneditor.cpp index c3e9ec0c51c..264ef809e56 100644 --- a/src/plugins/python/pythoneditor.cpp +++ b/src/plugins/python/pythoneditor.cpp @@ -24,9 +24,11 @@ ****************************************************************************/ #include "pythoneditor.h" + #include "pythonconstants.h" #include "pythonhighlighter.h" #include "pythonindenter.h" +#include "pythonlanguageclient.h" #include "pythonsettings.h" #include "pythonutils.h" @@ -102,6 +104,23 @@ static QWidget *createEditorWidget() return widget; } +class PythonDocument : public TextEditor::TextDocument +{ +public: + PythonDocument() : TextEditor::TextDocument(Constants::C_PYTHONEDITOR_ID) {} + + void setFilePath(const Utils::FilePath &filePath) override + { + TextEditor::TextDocument::setFilePath(filePath); + + const Utils::FilePath &python = detectPython(filePath); + if (!python.exists()) + return; + + PyLSConfigureAssistant::instance()->openDocumentWithPython(python, this); + } +}; + PythonEditorFactory::PythonEditorFactory() { registerReplAction(this); @@ -116,7 +135,7 @@ PythonEditorFactory::PythonEditorFactory() | TextEditor::TextEditorActionHandler::UnCollapseAll | TextEditor::TextEditorActionHandler::FollowSymbolUnderCursor); - setDocumentCreator([] { return new TextEditor::TextDocument(Constants::C_PYTHONEDITOR_ID); }); + setDocumentCreator([]() { return new PythonDocument; }); setEditorWidgetCreator(createEditorWidget); setIndenterCreator([](QTextDocument *doc) { return new PythonIndenter(doc); }); setSyntaxHighlighterCreator([] { return new PythonHighlighter; }); diff --git a/src/plugins/python/pythonlanguageclient.cpp b/src/plugins/python/pythonlanguageclient.cpp index 2bd89dfecb9..fcf1d86b9e0 100644 --- a/src/plugins/python/pythonlanguageclient.cpp +++ b/src/plugins/python/pythonlanguageclient.cpp @@ -635,19 +635,6 @@ static void enablePythonLanguageServer(const FilePath &python, } } -void PyLSConfigureAssistant::documentOpened(Core::IDocument *document) -{ - auto textDocument = qobject_cast(document); - if (!textDocument || textDocument->mimeType() != Constants::C_PY_MIMETYPE) - return; - - const FilePath &python = detectPython(textDocument->filePath()); - if (!python.exists()) - return; - - instance()->openDocumentWithPython(python, textDocument); -} - void PyLSConfigureAssistant::openDocumentWithPython(const FilePath &python, TextEditor::TextDocument *document) { diff --git a/src/plugins/python/pythonlanguageclient.h b/src/plugins/python/pythonlanguageclient.h index 97cb00c311d..13983d60eca 100644 --- a/src/plugins/python/pythonlanguageclient.h +++ b/src/plugins/python/pythonlanguageclient.h @@ -72,7 +72,6 @@ public: static const LanguageClient::StdIOSettings *languageServerForPython( const Utils::FilePath &python); - static void documentOpened(Core::IDocument *document); static void updateEditorInfoBars(const Utils::FilePath &python, LanguageClient::Client *client); void openDocumentWithPython(const Utils::FilePath &python, TextEditor::TextDocument *document); diff --git a/src/plugins/python/pythonplugin.cpp b/src/plugins/python/pythonplugin.cpp index 15b656b2e43..e0029b64a2d 100644 --- a/src/plugins/python/pythonplugin.cpp +++ b/src/plugins/python/pythonplugin.cpp @@ -111,9 +111,6 @@ void PythonPlugin::extensionsInitialized() Core::FileIconProvider::registerIconOverlayForSuffix(imageFile, "py"); TaskHub::addCategory(PythonErrorTaskCategory, "Python", true); - - connect(Core::EditorManager::instance(), &Core::EditorManager::documentOpened, - this, &PyLSConfigureAssistant::documentOpened); } } // namespace Internal