- 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.
This commit is contained in:
Roy Qu 2022-10-23 10:40:00 +08:00
parent d38d986aef
commit 012628aef3
6 changed files with 53 additions and 28 deletions

View File

@ -3,6 +3,8 @@ Red Panda C++ Version 2.0
- redesign the project parser, more efficient and correct - redesign the project parser, more efficient and correct
- enhancement: todo parser for project - enhancement: todo parser for project
- fix: save/load bookmark doesn't work - 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 Red Panda C++ Version 1.5

View File

@ -100,10 +100,15 @@ QString Compiler::getFileNameFromOutputLine(QString &line) {
break; 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; continue;
} else if (QFileInfo(temp).suffix()=="o") { // skip obj file
continue;
} else { } else {
break; break;
} }

View File

@ -33,7 +33,7 @@ ProjectCompiler::ProjectCompiler(std::shared_ptr<Project> project, bool silent,
void ProjectCompiler::buildMakeFile() void ProjectCompiler::buildMakeFile()
{ {
//we are using custom make file, don't overwrite it //we are using custom make file, don't overwrite it
if (!mProject->options().customMakefile.isEmpty()) if (mProject->options().useCustomMakefile && !mProject->options().customMakefile.isEmpty())
return; return;
switch(mProject->options().type) { switch(mProject->options().type) {
@ -512,6 +512,12 @@ bool ProjectCompiler::prepareForRebuild()
return true; return true;
} }
QString ProjectCompiler::getFileNameFromOutputLine(QString &line)
{
QString temp=Compiler::getFileNameFromOutputLine(line);
return QDir(mDirectory).absoluteFilePath(temp);
}
bool ProjectCompiler::prepareForCompile() bool ProjectCompiler::prepareForCompile()
{ {
if (!mProject) if (!mProject)

View File

@ -50,6 +50,10 @@ private:
protected: protected:
bool prepareForCompile() override; bool prepareForCompile() override;
bool prepareForRebuild() override; bool prepareForRebuild() override;
// Compiler interface
protected:
QString getFileNameFromOutputLine(QString &line) override;
}; };
#endif // PROJECTCOMPILER_H #endif // PROJECTCOMPILER_H

View File

@ -535,21 +535,12 @@ void Editor::wheelEvent(QWheelEvent *event) {
void Editor::focusInEvent(QFocusEvent *event) void Editor::focusInEvent(QFocusEvent *event)
{ {
SynEdit::focusInEvent(event); SynEdit::focusInEvent(event);
pMainWindow->updateAppTitle();
pMainWindow->updateEditorActions();
pMainWindow->updateForEncodingInfo();
pMainWindow->updateStatusbarForLineCol();
pMainWindow->updateForStatusbarModeInfo();
pMainWindow->updateClassBrowserForEditor(this);
} }
void Editor::focusOutEvent(QFocusEvent *event) void Editor::focusOutEvent(QFocusEvent *event)
{ {
SynEdit::focusOutEvent(event); SynEdit::focusOutEvent(event);
//pMainWindow->updateClassBrowserForEditor(nullptr); //pMainWindow->updateClassBrowserForEditor(nullptr);
pMainWindow->updateForEncodingInfo();
pMainWindow->updateStatusbarForLineCol();
pMainWindow->updateForStatusbarModeInfo();
pMainWindow->functionTip()->hide(); pMainWindow->functionTip()->hide();
} }
@ -1301,7 +1292,14 @@ void Editor::showEvent(QShowEvent */*event*/)
checkSyntaxInBack(); checkSyntaxInBack();
reparseTodo(); reparseTodo();
} }
setHideTime(QDateTime()); pMainWindow->updateClassBrowserForEditor(this);
pMainWindow->updateAppTitle();
pMainWindow->updateEditorActions();
pMainWindow->updateForEncodingInfo();
pMainWindow->updateStatusbarForLineCol();
pMainWindow->updateForStatusbarModeInfo();
setHideTime(QDateTime::currentDateTime());
} }
void Editor::hideEvent(QHideEvent */*event*/) void Editor::hideEvent(QHideEvent */*event*/)
@ -1318,6 +1316,10 @@ void Editor::hideEvent(QHideEvent */*event*/)
this, this,
&QSynedit::SynEdit::invalidate); &QSynedit::SynEdit::invalidate);
} }
pMainWindow->updateForEncodingInfo();
pMainWindow->updateStatusbarForLineCol();
pMainWindow->updateForStatusbarModeInfo();
setHideTime(QDateTime::currentDateTime()); setHideTime(QDateTime::currentDateTime());
} }

View File

@ -4269,14 +4269,31 @@ void CppParser::internalInvalidateFile(const QString &fileName)
if (fileName.isEmpty()) if (fileName.isEmpty())
return; 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<QString>& keys=mNamespaces.keys(); const QList<QString>& keys=mNamespaces.keys();
for (const QString& key:keys) { for (const QString& key:keys) {
PStatementList statements = mNamespaces.value(key); PStatementList statements = mNamespaces.value(key);
for (int i=statements->size()-1;i>=0;i--) { for (int i=statements->size()-1;i>=0;i--) {
PStatement statement = statements->at(i); PStatement statement = statements->at(i);
if (statement->fileName == fileName if (statement->fileName == fileName) {
|| statement->definitionFileName == fileName) {
statements->removeAt(i); 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 // delete it from scannedfiles
mPreprocessor.removeScannedFile(fileName); mPreprocessor.removeScannedFile(fileName);
} }