From 01662a95d1488780e96dbf1eab4d56f403d8d639 Mon Sep 17 00:00:00 2001 From: Roy Qu Date: Thu, 7 Apr 2022 21:35:09 +0800 Subject: [PATCH] - fix: auto syntax check doesn't work for new files - change: don't auto jump to the first syntax error location when compile --- NEWS.md | 2 + RedPandaIDE/HighlighterManager.cpp | 22 +++++------ RedPandaIDE/editor.cpp | 10 +++-- RedPandaIDE/mainwindow.cpp | 60 ++++++++++++++---------------- 4 files changed, 46 insertions(+), 48 deletions(-) diff --git a/NEWS.md b/NEWS.md index 1bb7ea93..15bca97e 100644 --- a/NEWS.md +++ b/NEWS.md @@ -8,6 +8,8 @@ Red Panda C++ Version 1.0.3 - fix: crash when editing txt file and input symbol at the beginning of a line - fix: ctrl+shift+end doesn't select - fix: don't show tips in the editor, when selecting by mouse + - fix: auto syntax check doesn't work for new files + - change: don't auto jump to the first syntax error location when compile Red Panda C++ Version 1.0.2 - enhancement: press tab in column mode won't exit column mode diff --git a/RedPandaIDE/HighlighterManager.cpp b/RedPandaIDE/HighlighterManager.cpp index 3d2489a4..3e30c61d 100644 --- a/RedPandaIDE/HighlighterManager.cpp +++ b/RedPandaIDE/HighlighterManager.cpp @@ -32,20 +32,16 @@ HighlighterManager::HighlighterManager() PSynHighlighter HighlighterManager::getHighlighter(const QString &filename) { - if (filename.isEmpty() || filename.startsWith(QObject::tr("untitled"))) { + QFileInfo info(filename); + QString suffix = info.suffix(); + if (suffix.isEmpty() || suffix == "c" || suffix == "cpp" || suffix == "cxx" + || suffix == "cc" || suffix == "h" || suffix == "hpp" + || suffix == "hxx" || suffix == "hh" || suffix == "C" + || suffix == "CPP" || suffix =="H" || suffix == "c++" + || suffix == "h++") { return getCppHighlighter(); - } else { - QFileInfo info(filename); - QString suffix = info.suffix(); - if (suffix.isEmpty() || suffix == "c" || suffix == "cpp" || suffix == "cxx" - || suffix == "cc" || suffix == "h" || suffix == "hpp" - || suffix == "hxx" || suffix == "hh" || suffix == "C" - || suffix == "CPP" || suffix =="H" || suffix == "c++" - || suffix == "h++") { - return getCppHighlighter(); - } else if (suffix == "vs" || suffix == "fs" || suffix == "frag") { - return getGLSLHighlighter(); - } + } else if (suffix == "vs" || suffix == "fs" || suffix == "frag") { + return getGLSLHighlighter(); } return PSynHighlighter(); } diff --git a/RedPandaIDE/editor.cpp b/RedPandaIDE/editor.cpp index e388e502..a8808f6f 100644 --- a/RedPandaIDE/editor.cpp +++ b/RedPandaIDE/editor.cpp @@ -1115,7 +1115,7 @@ bool Editor::event(QEvent *event) if (pMainWindow->functionTip()->isVisible()) { pMainWindow->functionTip()->hide(); } - QToolTip::showText(mapToGlobal(helpEvent->pos()),hint); + QToolTip::showText(mapToGlobal(helpEvent->pos()),hint,this); event->ignore(); } else { updateMouseCursor(); @@ -1618,7 +1618,7 @@ void Editor::onTipEvalValueReady(const QString& value) } else { newValue = value; } - QToolTip::showText(QCursor::pos(), mCurrentDebugTipWord + " = " + newValue); + QToolTip::showText(QCursor::pos(), mCurrentDebugTipWord + " = " + newValue, this); } disconnect(pMainWindow->debugger(), &Debugger::evalValueReady, this, &Editor::onTipEvalValueReady); @@ -1753,7 +1753,11 @@ QStringList Editor::getExpressionAtPosition( int ch = pos.Char-1; int symbolMatchingLevel = 0; LastSymbolType lastSymbolType=LastSymbolType::None; - PSynHighlighter highlighter = highlighterManager.getHighlighter(mFilename); + PSynHighlighter highlighter; + if (isNew()) + highlighter = highlighterManager.getCppHighlighter(); + else + highlighter = highlighterManager.getHighlighter(mFilename); if (!highlighter) return result; while (true) { diff --git a/RedPandaIDE/mainwindow.cpp b/RedPandaIDE/mainwindow.cpp index eca6bfd2..b1e301b3 100644 --- a/RedPandaIDE/mainwindow.cpp +++ b/RedPandaIDE/mainwindow.cpp @@ -1446,13 +1446,15 @@ void MainWindow::checkSyntaxInBack(Editor *e) // if not devEditor.AutoCheckSyntax then // Exit; //not c or cpp file - FileType fileType = getFileType(e->filename()); - if (fileType != FileType::CSource - && fileType != FileType::CppSource - && fileType != FileType::CHeader - && fileType != FileType::CppHeader - ) - return; + if (!e->isNew()) { + FileType fileType = getFileType(e->filename()); + if (fileType != FileType::CSource + && fileType != FileType::CppSource + && fileType != FileType::CHeader + && fileType != FileType::CppHeader + ) + return; + } if (mCompilerManager->backgroundSyntaxChecking()) return; if (mCompilerManager->compiling()) @@ -4546,21 +4548,17 @@ void MainWindow::onCompileFinished(bool isCheckSyntax) } } - // Close it if there's nothing to show if (isCheckSyntax) { // check syntax in back, don't change message panel - } else if ( - (ui->tableIssues->count() == 0) - ) { - openCloseBottomPanel(false); - // Or open it if there is anything to show + } else if (ui->tableIssues->count() == 0) { + // Close it if there's nothing to show + if (ui->tabMessages->currentIndex() == i) + openCloseBottomPanel(false); } else { - if (ui->tableIssues->count() > 0) { - if (ui->tabMessages->currentIndex() != i) { - ui->tabMessages->setCurrentIndex(i); - } - openCloseBottomPanel(true); + if (ui->tabMessages->currentIndex() != i) { + ui->tabMessages->setCurrentIndex(i); } + openCloseBottomPanel(true); } Editor * e = mEditorList->getEditor(); @@ -4590,28 +4588,26 @@ void MainWindow::onCompileFinished(bool isCheckSyntax) mCompileSuccessionTask.reset(); // Jump to problem location, sorted by significance } else if ((mCompilerManager->compileIssueCount() > 0) && (!mCheckSyntaxInBack)) { + bool hasError = false; // First try to find errors for (int i=0;itableIssues->count();i++) { PCompileIssue issue = ui->tableIssues->issue(i); if (issue->type == CompileIssueType::Error) { - if (e && e->filename() != issue->filename) - continue; ui->tableIssues->selectRow(i); - QModelIndex index =ui->tableIssues->model()->index(i,0); - emit ui->tableIssues->doubleClicked(index); + ui->tabIssues->setFocus(); + hasError = true; break; } } - - // Then try to find warnings - for (int i=0;itableIssues->count();i++) { - PCompileIssue issue = ui->tableIssues->issue(i); - if (issue->type == CompileIssueType::Warning) { - if (e && e->filename() != issue->filename) - continue; - ui->tableIssues->selectRow(i); - QModelIndex index =ui->tableIssues->model()->index(i,0); - emit ui->tableIssues->doubleClicked(index); + if (!hasError) { + // Then try to find warnings + for (int i=0;itableIssues->count();i++) { + PCompileIssue issue = ui->tableIssues->issue(i); + if (issue->type == CompileIssueType::Warning) { + ui->tableIssues->selectRow(i); + ui->tabIssues->setFocus(); + break; + } } } }