forked from qt-creator/qt-creator
Python: extract pythonProjectForFile function to utils
Change-Id: I4055527302cab09f55cd4b06bfd3896accb4832a Reviewed-by: Christian Stenger <christian.stenger@qt.io>
This commit is contained in:
@@ -452,17 +452,6 @@ void PyLSSettings::setInterpreter(const QString &interpreterId)
|
|||||||
m_executable = interpreter.command;
|
m_executable = interpreter.command;
|
||||||
}
|
}
|
||||||
|
|
||||||
static PythonProject *projectForFile(const FilePath &pythonFile)
|
|
||||||
{
|
|
||||||
for (ProjectExplorer::Project *project : ProjectExplorer::SessionManager::projects()) {
|
|
||||||
if (auto pythonProject = qobject_cast<PythonProject *>(project)) {
|
|
||||||
if (pythonProject->isKnownFile(pythonFile))
|
|
||||||
return pythonProject;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
class PyLSClient : public Client
|
class PyLSClient : public Client
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
@@ -472,7 +461,7 @@ public:
|
|||||||
using namespace LanguageServerProtocol;
|
using namespace LanguageServerProtocol;
|
||||||
if (reachable()) {
|
if (reachable()) {
|
||||||
const FilePath documentPath = document->filePath();
|
const FilePath documentPath = document->filePath();
|
||||||
if (isSupportedDocument(document) && !projectForFile(documentPath)) {
|
if (isSupportedDocument(document) && !pythonProjectForFile(documentPath)) {
|
||||||
const FilePath workspacePath = documentPath.parentDir();
|
const FilePath workspacePath = documentPath.parentDir();
|
||||||
if (!extraWorkspaceDirs.contains(workspacePath)) {
|
if (!extraWorkspaceDirs.contains(workspacePath)) {
|
||||||
WorkspaceFoldersChangeEvent event;
|
WorkspaceFoldersChangeEvent event;
|
||||||
|
@@ -146,5 +146,16 @@ QString pythonName(const FilePath &pythonPath)
|
|||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
PythonProject *pythonProjectForFile(const FilePath &pythonFile)
|
||||||
|
{
|
||||||
|
for (ProjectExplorer::Project *project : ProjectExplorer::SessionManager::projects()) {
|
||||||
|
if (auto pythonProject = qobject_cast<PythonProject *>(project)) {
|
||||||
|
if (pythonProject->isKnownFile(pythonFile))
|
||||||
|
return pythonProject;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace Internal
|
} // namespace Internal
|
||||||
} // namespace Python
|
} // namespace Python
|
||||||
|
@@ -35,5 +35,8 @@ void openPythonRepl(QObject *parent, const Utils::FilePath &file, ReplType type)
|
|||||||
Utils::FilePath detectPython(const Utils::FilePath &documentPath);
|
Utils::FilePath detectPython(const Utils::FilePath &documentPath);
|
||||||
QString pythonName(const Utils::FilePath &pythonPath);
|
QString pythonName(const Utils::FilePath &pythonPath);
|
||||||
|
|
||||||
|
class PythonProject;
|
||||||
|
PythonProject *pythonProjectForFile(const Utils::FilePath &pythonFile);
|
||||||
|
|
||||||
} // namespace Internal
|
} // namespace Internal
|
||||||
} // namespace Python
|
} // namespace Python
|
||||||
|
Reference in New Issue
Block a user