From 12edcb22a5d2cca749aca19886a6cd60d83bd439 Mon Sep 17 00:00:00 2001 From: Roy Qu Date: Thu, 17 Mar 2022 20:28:03 +0800 Subject: [PATCH] - fix: correctly reparse modified project files when rename symbol --- NEWS.md | 1 + RedPandaIDE/mainwindow.cpp | 24 ++++++++++++++++++------ 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/NEWS.md b/NEWS.md index 26178002..ea0a57dd 100644 --- a/NEWS.md +++ b/NEWS.md @@ -36,6 +36,7 @@ Red Panda C++ Version 1.0.0 - enhancement: create file in files view - fix: hits in the search view not correctly displayed (overlapped with others) - enhancement: auto convert project icon to ico format + - fix: correctly reparse modified project files when rename symbol Red Panda C++ Version 0.14.5 - fix: the "gnu c++ 20" option in compiler set options is wrong diff --git a/RedPandaIDE/mainwindow.cpp b/RedPandaIDE/mainwindow.cpp index 12b37f87..7912b01e 100644 --- a/RedPandaIDE/mainwindow.cpp +++ b/RedPandaIDE/mainwindow.cpp @@ -5914,7 +5914,8 @@ void MainWindow::on_actionRename_Symbol_triggered() if (!editor) return; editor->beginUpdate(); -// mClassBrowserModel.beginUpdate(); + BufferCoord oldCaretXY = editor->caretXY(); + // mClassBrowserModel.beginUpdate(); QCursor oldCursor = editor->cursor(); editor->setCursor(Qt::CursorShape::WaitCursor); auto action = finally([oldCursor,editor]{ @@ -5934,10 +5935,19 @@ void MainWindow::on_actionRename_Symbol_triggered() return; } - BufferCoord oldCaretXY = editor->caretXY(); if (editor->inProject() && mProject) { - mProject->cppParser()->parseFileList(); + for (int i=0;ipageCount();i++) { + Editor * e=(*mEditorList)[i]; + if (e->modified()) { + mProject->cppParser()->parseFile(editor->filename(), editor->inProject(), false, false); + } + } QStringList expression = editor->getExpressionAtPosition(oldCaretXY); + if (expression.isEmpty() && oldCaretXY.Char>1) { + BufferCoord coord=oldCaretXY; + coord.Char--; + expression = editor->getExpressionAtPosition(coord); + } // Find it's definition PStatement oldStatement = editor->parser()->findStatementOf( editor->filename(), @@ -5975,9 +5985,11 @@ void MainWindow::on_actionRename_Symbol_triggered() if (word == newWord) return; - PCppParser parser = editor->parser(); - //here we must reparse the file in sync, or rename may fail - parser->parseFile(editor->filename(), editor->inProject(), false, false); + if (!editor->inProject() && editor->modified() ) { + PCppParser parser = editor->parser(); + //here we must reparse the file in sync, or rename may fail + parser->parseFile(editor->filename(), editor->inProject(), false, false); + } CppRefacter refactor; BufferCoord oldXY=editor->caretXY(); int topLine = editor->topLine();