forked from qt-creator/qt-creator
Python: Switch pyls on interpreter change
Change-Id: I458b635986a55003a1e7254e27e2df9667704273 Reviewed-by: Christian Stenger <christian.stenger@qt.io>
This commit is contained in:
@@ -23,20 +23,26 @@
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#include "pythonrunconfiguration.h"
|
||||
|
||||
#include "pythonconstants.h"
|
||||
#include "pythonproject.h"
|
||||
#include "pythonrunconfiguration.h"
|
||||
#include "pythonsettings.h"
|
||||
#include "pythonutils.h"
|
||||
|
||||
#include <coreplugin/icore.h>
|
||||
#include <coreplugin/editormanager/editormanager.h>
|
||||
|
||||
#include <languageclient/languageclientmanager.h>
|
||||
|
||||
#include <projectexplorer/localenvironmentaspect.h>
|
||||
#include <projectexplorer/projectconfigurationaspects.h>
|
||||
#include <projectexplorer/runconfigurationaspects.h>
|
||||
#include <projectexplorer/target.h>
|
||||
#include <projectexplorer/taskhub.h>
|
||||
|
||||
#include <texteditor/textdocument.h>
|
||||
|
||||
#include <utils/fileutils.h>
|
||||
#include <utils/outputformatter.h>
|
||||
#include <utils/theme/theme.h>
|
||||
@@ -248,6 +254,8 @@ PythonRunConfiguration::PythonRunConfiguration(Target *target, Core::Id id)
|
||||
{
|
||||
auto interpreterAspect = addAspect<InterpreterAspect>();
|
||||
interpreterAspect->setSettingsKey("PythonEditor.RunConfiguation.Interpreter");
|
||||
connect(interpreterAspect, &InterpreterAspect::changed,
|
||||
this, &PythonRunConfiguration::updateLanguageServer);
|
||||
|
||||
connect(PythonSettings::instance(), &PythonSettings::interpretersChanged,
|
||||
interpreterAspect, &InterpreterAspect::updateInterpreters);
|
||||
@@ -283,6 +291,33 @@ void PythonRunConfiguration::doAdditionalSetup(const RunConfigurationCreationInf
|
||||
updateTargetInformation();
|
||||
}
|
||||
|
||||
void PythonRunConfiguration::updateLanguageServer()
|
||||
{
|
||||
using namespace LanguageClient;
|
||||
|
||||
const FilePath python(FilePath::fromUserInput(interpreter()));
|
||||
|
||||
if (const StdIOSettings *lsSetting = languageServerForPython(python)) {
|
||||
if (Client *client = LanguageClientManager::clientForSetting(lsSetting).value(0)) {
|
||||
for (FilePath &file : project()->files(Project::AllFiles)) {
|
||||
if (auto document = TextEditor::TextDocument::textDocumentForFilePath(file)) {
|
||||
if (document->mimeType() == Constants::C_PY_MIMETYPE) {
|
||||
resetEditorInfoBar(document);
|
||||
LanguageClientManager::reOpenDocumentWithClient(document, client);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (FilePath &file : project()->files(Project::AllFiles)) {
|
||||
if (auto document = TextEditor::TextDocument::textDocumentForFilePath(file)) {
|
||||
if (document->mimeType() == Constants::C_PY_MIMETYPE)
|
||||
updateEditorInfoBar(python, document);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool PythonRunConfiguration::supportsDebugger() const
|
||||
{
|
||||
return true;
|
||||
|
||||
Reference in New Issue
Block a user