From 012628aef35ab0a913466ed7fa8a8b2ee3bd52f6 Mon Sep 17 00:00:00 2001 From: Roy Qu Date: Sun, 23 Oct 2022 10:40:00 +0800 Subject: [PATCH] - fix: editor & class browser not correct updated when editor is switched but not focused - fix: when invalidating a c/c++ source file, statements that not declared in it are wrongly removed. --- NEWS.md | 2 ++ RedPandaIDE/compiler/compiler.cpp | 11 +++++--- RedPandaIDE/compiler/projectcompiler.cpp | 8 +++++- RedPandaIDE/compiler/projectcompiler.h | 4 +++ RedPandaIDE/editor.cpp | 22 ++++++++------- RedPandaIDE/parser/cppparser.cpp | 34 ++++++++++++++---------- 6 files changed, 53 insertions(+), 28 deletions(-) diff --git a/NEWS.md b/NEWS.md index 4751a081..71437e1d 100644 --- a/NEWS.md +++ b/NEWS.md @@ -3,6 +3,8 @@ Red Panda C++ Version 2.0 - redesign the project parser, more efficient and correct - enhancement: todo parser for project - fix: save/load bookmark doesn't work + - fix: if project has custom makefile but not enabled, project won't auto generate makefile. + - fix: File path of Issues in project compilation is relative, and can't be correctly marked in the editors. Red Panda C++ Version 1.5 diff --git a/RedPandaIDE/compiler/compiler.cpp b/RedPandaIDE/compiler/compiler.cpp index 85c191ea..406483ea 100644 --- a/RedPandaIDE/compiler/compiler.cpp +++ b/RedPandaIDE/compiler/compiler.cpp @@ -100,10 +100,15 @@ QString Compiler::getFileNameFromOutputLine(QString &line) { break; } - if (QFileInfo(temp).fileName() == QLatin1String("ld.exe")) { // skip ld.exe + QFileInfo fileInfo(temp); + if (fileInfo.fileName() == QLatin1String("ld.exe")) { // skip ld.exe + continue; + } else if (fileInfo.fileName() == QLatin1String("make")) { // skip make.exe + continue; + } else if (fileInfo.fileName() == QLatin1String("mingw32-make")) { // skip mingw32-make.exe + continue; + } else if (fileInfo.suffix()=="o") { // skip obj file continue; - } else if (QFileInfo(temp).suffix()=="o") { // skip obj file - continue; } else { break; } diff --git a/RedPandaIDE/compiler/projectcompiler.cpp b/RedPandaIDE/compiler/projectcompiler.cpp index 42384314..c4875fc9 100644 --- a/RedPandaIDE/compiler/projectcompiler.cpp +++ b/RedPandaIDE/compiler/projectcompiler.cpp @@ -33,7 +33,7 @@ ProjectCompiler::ProjectCompiler(std::shared_ptr project, bool silent, void ProjectCompiler::buildMakeFile() { //we are using custom make file, don't overwrite it - if (!mProject->options().customMakefile.isEmpty()) + if (mProject->options().useCustomMakefile && !mProject->options().customMakefile.isEmpty()) return; switch(mProject->options().type) { @@ -512,6 +512,12 @@ bool ProjectCompiler::prepareForRebuild() return true; } +QString ProjectCompiler::getFileNameFromOutputLine(QString &line) +{ + QString temp=Compiler::getFileNameFromOutputLine(line); + return QDir(mDirectory).absoluteFilePath(temp); +} + bool ProjectCompiler::prepareForCompile() { if (!mProject) diff --git a/RedPandaIDE/compiler/projectcompiler.h b/RedPandaIDE/compiler/projectcompiler.h index 1a829c63..d5f94077 100644 --- a/RedPandaIDE/compiler/projectcompiler.h +++ b/RedPandaIDE/compiler/projectcompiler.h @@ -50,6 +50,10 @@ private: protected: bool prepareForCompile() override; bool prepareForRebuild() override; + + // Compiler interface +protected: + QString getFileNameFromOutputLine(QString &line) override; }; #endif // PROJECTCOMPILER_H diff --git a/RedPandaIDE/editor.cpp b/RedPandaIDE/editor.cpp index 8a18cecc..69f721c3 100644 --- a/RedPandaIDE/editor.cpp +++ b/RedPandaIDE/editor.cpp @@ -535,21 +535,12 @@ void Editor::wheelEvent(QWheelEvent *event) { void Editor::focusInEvent(QFocusEvent *event) { SynEdit::focusInEvent(event); - pMainWindow->updateAppTitle(); - pMainWindow->updateEditorActions(); - pMainWindow->updateForEncodingInfo(); - pMainWindow->updateStatusbarForLineCol(); - pMainWindow->updateForStatusbarModeInfo(); - pMainWindow->updateClassBrowserForEditor(this); } void Editor::focusOutEvent(QFocusEvent *event) { SynEdit::focusOutEvent(event); //pMainWindow->updateClassBrowserForEditor(nullptr); - pMainWindow->updateForEncodingInfo(); - pMainWindow->updateStatusbarForLineCol(); - pMainWindow->updateForStatusbarModeInfo(); pMainWindow->functionTip()->hide(); } @@ -1301,7 +1292,14 @@ void Editor::showEvent(QShowEvent */*event*/) checkSyntaxInBack(); reparseTodo(); } - setHideTime(QDateTime()); + pMainWindow->updateClassBrowserForEditor(this); + pMainWindow->updateAppTitle(); + pMainWindow->updateEditorActions(); + pMainWindow->updateForEncodingInfo(); + pMainWindow->updateStatusbarForLineCol(); + pMainWindow->updateForStatusbarModeInfo(); + + setHideTime(QDateTime::currentDateTime()); } void Editor::hideEvent(QHideEvent */*event*/) @@ -1318,6 +1316,10 @@ void Editor::hideEvent(QHideEvent */*event*/) this, &QSynedit::SynEdit::invalidate); } + pMainWindow->updateForEncodingInfo(); + pMainWindow->updateStatusbarForLineCol(); + pMainWindow->updateForStatusbarModeInfo(); + setHideTime(QDateTime::currentDateTime()); } diff --git a/RedPandaIDE/parser/cppparser.cpp b/RedPandaIDE/parser/cppparser.cpp index f0c498f2..db272acf 100644 --- a/RedPandaIDE/parser/cppparser.cpp +++ b/RedPandaIDE/parser/cppparser.cpp @@ -4269,14 +4269,31 @@ void CppParser::internalInvalidateFile(const QString &fileName) if (fileName.isEmpty()) return; - //remove all statements in the file + // remove its include files list + PFileIncludes p = findFileIncludes(fileName, true); + if (p) { + //fPreprocessor.InvalidDefinesInFile(FileName); //we don't need this, since we reset defines after each parse + //p->includeFiles.clear(); + //p->usings.clear(); + for (PStatement& statement:p->statements) { + if (statement->fileName==fileName) { + mStatementList.deleteStatement(statement); + } else { + statement->hasDefinition=false; + statement->definitionFileName = statement->fileName; + statement->definitionLine = statement->line; + } + } + p->statements.clear(); + } + + //remove all statements from namespace cache const QList& keys=mNamespaces.keys(); for (const QString& key:keys) { PStatementList statements = mNamespaces.value(key); for (int i=statements->size()-1;i>=0;i--) { PStatement statement = statements->at(i); - if (statement->fileName == fileName - || statement->definitionFileName == fileName) { + if (statement->fileName == fileName) { statements->removeAt(i); } } @@ -4285,17 +4302,6 @@ void CppParser::internalInvalidateFile(const QString &fileName) } } - // remove its include files list - PFileIncludes p = findFileIncludes(fileName, true); - if (p) { - //fPreprocessor.InvalidDefinesInFile(FileName); //we don't need this, since we reset defines after each parse - //p->includeFiles.clear(); - //p->usings.clear(); - for (PStatement& statement:p->statements) { - mStatementList.deleteStatement(statement); - } - p->statements.clear(); - } // delete it from scannedfiles mPreprocessor.removeScannedFile(fileName); }