forked from Andersbakken/rtags
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes for rtags-get-include-file-for-symbol
Add and use rc --include-file
- Loading branch information
1 parent
08d0e6e
commit 749e9a4
Showing
11 changed files
with
163 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
/* This file is part of RTags. | ||
RTags is free software: you can redistribute it and/or modify | ||
it under the terms of the GNU General Public License as published by | ||
the Free Software Foundation, either version 3 of the License, or | ||
(at your option) any later version. | ||
RTags is distributed in the hope that it will be useful, | ||
but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
GNU General Public License for more details. | ||
You should have received a copy of the GNU General Public License | ||
along with RTags. If not, see <http://www.gnu.org/licenses/>. */ | ||
|
||
#include "IncludeFileJob.h" | ||
#include "RTags.h" | ||
#include "Server.h" | ||
#include "Project.h" | ||
|
||
IncludeFileJob::IncludeFileJob(const std::shared_ptr<QueryMessage> &query, const std::shared_ptr<Project> &project) | ||
: QueryJob(query, 0, project) | ||
{ | ||
const uint32_t fileId = Location::fileId(query->currentFile()); | ||
mSource = project->sources(fileId).value(query->buildIndex()); | ||
if (mSource.isNull()) { | ||
for (const uint32_t dep : project->dependencies(fileId, Project::DependsOnArg)) { | ||
mSource = project->sources(dep).value(query->buildIndex()); | ||
if (!mSource.isNull()) | ||
break; | ||
} | ||
} | ||
mSymbol = query->query(); | ||
} | ||
|
||
int IncludeFileJob::execute() | ||
{ | ||
if (mSource.isNull()) | ||
return 1; | ||
const Path directory = mSource.sourceFile().parentDir(); | ||
const bool fromHeader = queryMessage()->currentFile().isHeader(); | ||
project()->findSymbols(mSymbol, [this, &directory, fromHeader](Project::SymbolMatchType type, const String &, const Set<Location> &locations) { | ||
if (type == Project::StartsWith) | ||
return; | ||
for (const Location &loc : locations) { | ||
const Path path = loc.path(); | ||
if (!path.isHeader()) | ||
continue; | ||
const Symbol sym = project()->findSymbol(loc); | ||
if (sym.isDefinition() || !sym.isClass()) { | ||
if (!fromHeader && path.startsWith(directory)) { | ||
write<256>("#include \"%s\"", path.mid(directory.size()).constData()); | ||
} else { | ||
for (const Source::Include &inc : mSource.includePaths) { | ||
const Path p = inc.path.ensureTrailingSlash(); | ||
if (path.startsWith(p)) { | ||
write<256>("#include <%s>", path.mid(p.size()).constData()); | ||
} | ||
} | ||
} | ||
} | ||
} | ||
}, queryFlags()); | ||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/* This file is part of RTags. | ||
RTags is free software: you can redistribute it and/or modify | ||
it under the terms of the GNU General Public License as published by | ||
the Free Software Foundation, either version 3 of the License, or | ||
(at your option) any later version. | ||
RTags is distributed in the hope that it will be useful, | ||
but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
GNU General Public License for more details. | ||
You should have received a copy of the GNU General Public License | ||
along with RTags. If not, see <http://www.gnu.org/licenses/>. */ | ||
|
||
#ifndef IncludeFileJob_h | ||
#define IncludeFileJob_h | ||
|
||
#include <rct/String.h> | ||
#include <rct/List.h> | ||
#include "RTags.h" | ||
#include "QueryJob.h" | ||
#include "Location.h" | ||
|
||
class IncludeFileJob : public QueryJob | ||
{ | ||
public: | ||
IncludeFileJob(const std::shared_ptr<QueryMessage> &query, const std::shared_ptr<Project> &project); | ||
protected: | ||
virtual int execute() override; | ||
private: | ||
String mSymbol; | ||
Source mSource; | ||
}; | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -67,6 +67,7 @@ class RClient | |
GenerateTest, | ||
HasFileManager, | ||
Help, | ||
IncludeFile, | ||
IMenu, | ||
IsIndexed, | ||
IsIndexing, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters