- fix: Results of "find symbol usage" in project not correctly set in the search result view

This commit is contained in:
royqh1979@gmail.com 2021-11-04 22:56:11 +08:00
parent 3352d413b3
commit 14254a2f15
5 changed files with 38 additions and 52 deletions

View File

@ -3,6 +3,7 @@ Version 0.7.9
- fix: hit info not correctly displayed in the search result view - fix: hit info not correctly displayed in the search result view
- fix: If find in files found no hits, search result view will not be shown. - fix: If find in files found no hits, search result view will not be shown.
- fix: wront indents when paste one line content - fix: wront indents when paste one line content
- fix: Results of "find symbol usage" in project not correctly set in the search result view
Version 0.7.8 Version 0.7.8
- enhancement: In problem view's output control, indicates which line is different with the expected - enhancement: In problem view's output control, indicates which line is different with the expected

View File

@ -35,23 +35,33 @@ bool CppRefacter::findOccurence(Editor *editor, const BufferCoord &pos)
std::shared_ptr<Project> project = pMainWindow->project(); std::shared_ptr<Project> project = pMainWindow->project();
if (editor->inProject() && project) { if (editor->inProject() && project) {
PSearchResults results = pMainWindow->searchResultModel()->addSearchResults(
statement->fullName,
SearchFileScope::wholeProject
);
foreach (const PProjectUnit& unit, project->units()) { foreach (const PProjectUnit& unit, project->units()) {
if (isCfile(unit->fileName()) || isHfile(unit->fileName())) { if (isCfile(unit->fileName()) || isHfile(unit->fileName())) {
findOccurenceInFile( PSearchResultTreeItem item = findOccurenceInFile(
phrase, unit->fileName(),
unit->fileName(), statement,
statement, editor->parser());
pos.Line, if (item && !(item->results.isEmpty())) {
editor->parser()); results->results.append(item);
}
} }
} }
} else { } else {
findOccurenceInFile( PSearchResults results = pMainWindow->searchResultModel()->addSearchResults(
phrase, statement->fullName,
SearchFileScope::currentFile
);
PSearchResultTreeItem item = findOccurenceInFile(
editor->filename(), editor->filename(),
statement, statement,
pos.Line,
editor->parser()); editor->parser());
if (item && !(item->results.isEmpty())) {
results->results.append(item);
}
} }
pMainWindow->searchResultModel()->notifySearchResultsUpdated(); pMainWindow->searchResultModel()->notifySearchResultsUpdated();
return true; return true;
@ -241,25 +251,3 @@ void CppRefacter::renameSymbolInFile(const QString &filename, const PStatement &
realEncoding); realEncoding);
} }
} }
void CppRefacter::findOccurenceInFile(
const QString& phrase,
const QString &filename,
const PStatement &statement,
int line,
const PCppParser &parser)
{
PSearchResults results = pMainWindow->searchResultModel()->addSearchResults(
phrase,
filename,
line
);
PSearchResultTreeItem item = findOccurenceInFile(
filename,
statement,
parser);
if (item && !(item->results.isEmpty())) {
results->results.append(item);
}
}

View File

@ -19,12 +19,6 @@ public:
void renameSymbol(Editor* editor, const BufferCoord& pos, const QString& word, const QString& newWord); void renameSymbol(Editor* editor, const BufferCoord& pos, const QString& word, const QString& newWord);
signals: signals:
private: private:
void findOccurenceInFile(
const QString& phrase,
const QString& filename,
const PStatement& statement,
int line,
const PCppParser& parser);
PSearchResultTreeItem findOccurenceInFile( PSearchResultTreeItem findOccurenceInFile(
const QString& filename, const QString& filename,
const PStatement& statement, const PStatement& statement,

View File

@ -31,15 +31,17 @@ PSearchResults SearchResultModel::addSearchResults(const QString &keyword, SynSe
return results; return results;
} }
PSearchResults SearchResultModel::addSearchResults(const QString &keyword, const QString &filename, int symbolLine) PSearchResults SearchResultModel::addSearchResults(
const QString& symbolFullname,
SearchFileScope scope)
{ {
int index=-1; int index=-1;
for (int i=0;i<mSearchResults.size();i++) { for (int i=0;i<mSearchResults.size();i++) {
PSearchResults results = mSearchResults[i]; PSearchResults results = mSearchResults[i];
if (results->searchType == SearchType::FindOccurences if (results->searchType == SearchType::FindOccurences
&& results->keyword == keyword && results->scope == scope
&& results->filename == filename && results->keyword == symbolFullname
&& results->symbolLine == symbolLine) { ) {
index=i; index=i;
break; break;
} }
@ -51,10 +53,10 @@ PSearchResults SearchResultModel::addSearchResults(const QString &keyword, const
mSearchResults.pop_back(); mSearchResults.pop_back();
} }
PSearchResults results = std::make_shared<SearchResults>(); PSearchResults results = std::make_shared<SearchResults>();
results->keyword = keyword; results->keyword = symbolFullname;
results->filename = filename; results->filename = "";
results->symbolLine = symbolLine;
results->searchType = SearchType::FindOccurences; results->searchType = SearchType::FindOccurences;
results->scope = scope;
mSearchResults.push_front(results); mSearchResults.push_front(results);
mCurrentIndex = 0; mCurrentIndex = 0;
return results; return results;
@ -367,10 +369,13 @@ QVariant SearchResultListModel::data(const QModelIndex &index, int role) const
return tr("Open Files:") + QString(" \"%1\"").arg(results->keyword); return tr("Open Files:") + QString(" \"%1\"").arg(results->keyword);
} }
} else if (results->searchType == SearchType::FindOccurences) { } else if (results->searchType == SearchType::FindOccurences) {
return tr("References to symbol \'%1\' at '%2':%3") if (results->scope == SearchFileScope::currentFile) {
.arg(results->keyword) return tr("Find Usages in Current File: '%1'")
.arg(extractFileName(results->filename)) .arg(results->keyword);
.arg(results->symbolLine); } else {
return tr("Find Usages in Project: '%1'")
.arg(results->keyword);
}
} }
} }
return QVariant(); return QVariant();

View File

@ -35,7 +35,6 @@ struct SearchResults{
SearchFileScope scope; SearchFileScope scope;
SearchType searchType; SearchType searchType;
QString filename; QString filename;
int symbolLine;
QList<PSearchResultTreeItem> results; QList<PSearchResultTreeItem> results;
}; };
@ -48,9 +47,8 @@ public:
PSearchResults addSearchResults(const QString& keyword,SynSearchOptions options, PSearchResults addSearchResults(const QString& keyword,SynSearchOptions options,
SearchFileScope scope); SearchFileScope scope);
PSearchResults addSearchResults( PSearchResults addSearchResults(
const QString& keyword, const QString& symbolFullname,
const QString& filename, SearchFileScope scope);
int symbolLine);
PSearchResults results(int index); PSearchResults results(int index);
void notifySearchResultsUpdated(); void notifySearchResultsUpdated();
int currentIndex() const; int currentIndex() const;