Skip to content
Permalink
Browse files

Some changes to --include-path

  • Loading branch information...
Andersbakken committed Mar 13, 2019
1 parent f06a782 commit c1a93c2bba41076dbdad5e50d502fb99503520e3
Showing with 82 additions and 58 deletions.
  1. +42 −14 src/IncludePathJob.cpp
  2. +1 −0 src/JobScheduler.cpp
  3. +0 −33 src/Project.cpp
  4. +0 −1 src/Project.h
  5. +3 −3 src/QueryMessage.cpp
  6. +4 −1 src/QueryMessage.h
  7. +13 −2 src/RClient.cpp
  8. +4 −2 src/RClient.h
  9. +15 −2 src/rtags.el
@@ -40,29 +40,57 @@ int IncludePathJob::execute()
return 1;
const Symbol prev = symbols->valueAt(idx - 1);
if (prev.kind == CXCursor_MemberRefExpr
&& prev.location.column() == symbol.location.column() - 1
&& prev.location.line() == symbol.location.line()
&& prev.symbolName.contains("~")) {
&& prev.location.column() == symbol.location.column() - 1
&& prev.location.line() == symbol.location.line()
&& prev.symbolName.contains("~")) {
symbol = prev;
}
}

if (queryFlags() & QueryMessage::TargetUsrs) {
const Set<String> usrs = project()->findTargetUsrs(location);
for (const String &usr : usrs) {
write(usr);
}
return 0;
}

auto targets = RTags::sortTargets(project()->findTargets(symbol));

String allTargetPath;
int maxDepth = queryMessage()->maxDepth();
if (maxDepth == -1)
maxDepth = 8;
const bool absolute = queryFlags() & QueryMessage::AbsolutePath;
const std::shared_ptr<Project> proj = project();
if (!proj)
return 1;
const Path projectPath = proj->path();
for (const auto &target : targets) {
allTargetPath += project()->dumpIncludePath(location, target) + "\n";
DependencyNode *depNode = project()->dependencyNode(location.fileId());
if (depNode) {
List<uint32_t> paths;
bool done = false;
std::function<void(DependencyNode *)> process = [&](DependencyNode *n) {
if (done || !paths.contains(n->fileId)) {
paths.append(n->fileId);
if (n->fileId == target.location.fileId()) {
String path;
for (uint32_t fileId : paths) {
if (!path.isEmpty())
path += " -> ";
Path p = Location::path(fileId);
if (!absolute && p.startsWith(projectPath)) {
path += p.mid(projectPath.size());
} else {
path += p;
}
}
if (!write(path))
done = true;
} else if (paths.size() < static_cast<size_t>(maxDepth)) {
for (const auto &includeNode : n->includes) {
process(includeNode.second);
}
}
paths.removeLast();
}
};
process(depNode);
}
}

// debug() << "IncludePathJob::allTargetPath: " << allTargetPath;
write(allTargetPath);
return 0;
}
@@ -381,6 +381,7 @@ void JobScheduler::abort(const std::shared_ptr<IndexerJob> &job)
if (node->process) {
debug() << "Killing process" << node->process;
node->process->kill();
mDaemons.remove(node->process); // ### this is not ideal
mActiveByProcess.remove(node->process);
}
}
@@ -2024,39 +2024,6 @@ static String addDeps(const Dependencies &deps)
return ret;
}

String Project::dumpIncludePath(const Location loc, const Symbol symbol) const
{
String allPath;

Set<DependencyNode*> seen;
DependencyNode *depNode = mDependencies.value(loc.fileId());
if (depNode) {
int startDepth = 1;

String path;
std::function<void(DependencyNode *, int)> process = [&](DependencyNode *n, int depth) {
String nodePath = String::format<1024>("%s%s", String(depth * 2, ' ').constData(), Location::path(n->fileId).constData());
path += nodePath;

if (seen.insert(n) && !n->includes.isEmpty()) {
if (n->fileId == symbol.location.fileId()) {
allPath += path + "\n";

path.clear();
return;
}
for (const auto &includeNode : n->includes) {
process(includeNode.second, depth + 1);
}
}
path.remove(nodePath);
};
process(depNode, startDepth);
}

return allPath;
}

String Project::dumpDependencies(uint32_t fileId, const List<String> &args, Flags<QueryMessage::Flag> flags) const
{
String ret;
@@ -137,7 +137,6 @@ class Project : public std::enable_shared_from_this<Project>
String dumpDependencies(uint32_t fileId,
const List<String> &args = List<String>(),
Flags<QueryMessage::Flag> flags = Flags<QueryMessage::Flag>()) const;
String dumpIncludePath(const Location loc, const Symbol symbol) const;
const Hash<uint32_t, DependencyNode*> &dependencies() const { return mDependencies; }
DependencyNode *dependencyNode(uint32_t fileId) const { return mDependencies.value(fileId); }

@@ -19,21 +19,21 @@
#include "RTags.h"

QueryMessage::QueryMessage(Type type)
: RTagsMessage(MessageId), mType(type), mMax(-1), mMinLine(-1), mMaxLine(-1), mBuildIndex(0), mTerminalWidth(-1)
: RTagsMessage(MessageId), mType(type), mMax(-1), mMaxDepth(-1), mMinLine(-1), mMaxLine(-1), mBuildIndex(0), mTerminalWidth(-1)
{
}

void QueryMessage::encode(Serializer &serializer) const
{
serializer << mCommandLine << mQuery << mCodeCompletePrefix << mType << mFlags << mMax
<< mMinLine << mMaxLine << mBuildIndex << mPathFilters << mKindFilters
<< mMaxDepth << mMinLine << mMaxLine << mBuildIndex << mPathFilters << mKindFilters
<< mCurrentFile << mUnsavedFiles << mTerminalWidth;
}

void QueryMessage::decode(Deserializer &deserializer)
{
deserializer >> mCommandLine >> mQuery >> mCodeCompletePrefix >> mType >> mFlags >> mMax
>> mMinLine >> mMaxLine >> mBuildIndex >> mPathFilters >> mKindFilters
>> mMaxDepth >> mMinLine >> mMaxLine >> mBuildIndex >> mPathFilters >> mKindFilters
>> mCurrentFile >> mUnsavedFiles >> mTerminalWidth;
}

@@ -205,6 +205,9 @@ class QueryMessage : public RTagsMessage
int minLine() const { return mMinLine; }
int maxLine() const { return mMaxLine; }

int maxDepth() const { return mMaxDepth; }
void setMaxDepth(int depth) { mMaxDepth = depth; }

int max() const { return mMax; }
void setMax(int max) { mMax = max; }

@@ -244,7 +247,7 @@ class QueryMessage : public RTagsMessage
String mQuery, mCodeCompletePrefix;
Type mType;
Flags<QueryMessage::Flag> mFlags;
int mMax, mMinLine, mMaxLine, mBuildIndex;
int mMax, mMaxDepth, mMinLine, mMaxLine, mBuildIndex;
List<PathFilter> mPathFilters;
KindFilters mKindFilters;
Path mCurrentFile;
@@ -179,6 +179,7 @@ std::initializer_list<CommandLineParser::Option<RClient::OptionType> > opts = {
{ RClient::TokensIncludeSymbols, "tokens-include-symbols", 0, CommandLineParser::NoValue, "Include symbols for tokens." },
{ RClient::NoRealPath, "no-realpath", 0, CommandLineParser::NoValue, "Don't resolve paths using realpath(3)." },
{ RClient::IncludePath, "include-path", 0, CommandLineParser::Required, "Dump include path for symbol." },
{ RClient::MaxDepth, "max-depth", 0, CommandLineParser::Required, "Max search depth. Used for --include-path." },
{ RClient::None, String(), 0, CommandLineParser::NoValue, 0 }
};

@@ -223,6 +224,7 @@ class QueryCommand : public RCCommand
msg.setTerminalWidth(rc->terminalWidth());
msg.setCurrentFile(rc->currentFile());
msg.setCodeCompletePrefix(rc->codeCompletePrefix());
msg.setMaxDepth(rc->maxDepth());
return connection->send(msg) ? RTags::Success : RTags::NetworkFailure;
}

@@ -315,7 +317,7 @@ class CompileCommand : public RCCommand
};

RClient::RClient()
: mMax(-1), mTimeout(-1), mMinOffset(-1), mMaxOffset(-1),
: mMax(-1), mMaxDepth(-1), mTimeout(-1), mMinOffset(-1), mMaxOffset(-1),
mConnectTimeout(DEFAULT_CONNECT_TIMEOUT), mBuildIndex(0),
mLogLevel(LogLevel::Error), mTcpPort(0), mGuessFlags(false),
mTerminalWidth(-1), mExitCode(RTags::ArgumentParseError)
@@ -1300,11 +1302,20 @@ CommandLineParser::ParseStatus RClient::parse(size_t argc, char **argv)
case IncludePath: {
String encoded = Location::encode(value);
if (encoded.isEmpty()) {
return { String::format<1024>("include path Can't resolve argument %s", value.constData()), CommandLineParser::Parse_Error };
return { String::format<1024>("include path can't resolve argument %s", value.constData()), CommandLineParser::Parse_Error };
}

addQuery(QueryMessage::IncludePath, std::move(encoded));
break; }
case MaxDepth: {
const int depth = atoi(value.constData());
if (depth <= 0) {
return { String::format<1024>("Invalid depth %s", value.constData()), CommandLineParser::Parse_Error };
}

mMaxDepth = depth;
break; }

}
return { String(), CommandLineParser::Parse_Exec };
};
@@ -91,6 +91,7 @@ class RClient
HasFileManager,
Help,
IncludeFile,
IncludePath,
IsIndexed,
IsIndexing,
JSON,
@@ -107,6 +108,7 @@ class RClient
MatchCaseInsensitive,
MatchRegex,
Max,
MaxDepth,
NoColor,
NoContext,
NoRealPath,
@@ -158,7 +160,6 @@ class RClient
Wait,
WildcardSymbolNames,
XML,
IncludePath,
NumOptions
};

@@ -169,6 +170,7 @@ class RClient
CommandLineParser::ParseStatus parse(size_t argc, char **argv);

int max() const { return mMax; }
int maxDepth() const { return mMaxDepth; }
LogLevel logLevel() const { return mLogLevel; }
int timeout() const { return mTimeout; }
int buildIndex() const { return mBuildIndex; }
@@ -205,7 +207,7 @@ class RClient
void addCompile(Path &&compileCommands);

Flags<QueryMessage::Flag> mQueryFlags;
int mMax, mTimeout, mMinOffset, mMaxOffset, mConnectTimeout, mBuildIndex;
int mMax, mMaxDepth, mTimeout, mMinOffset, mMaxOffset, mConnectTimeout, mBuildIndex;
LogLevel mLogLevel;
Set<QueryMessage::PathFilter> mPathFilters;
QueryMessage::KindFilters mKindFilters;
@@ -73,7 +73,7 @@
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Constants
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defconst rtags-protocol-version 127)
(defconst rtags-protocol-version 128)
(defconst rtags-package-version "2.31")
(defconst rtags-popup-available (require 'popup nil t))
(defconst rtags-supported-major-modes '(c-mode c++-mode objc-mode) "Major modes RTags supports.")
@@ -1735,7 +1735,7 @@ instead of file from `current-buffer'.
(defun rtags-print-include-path ()
"Print include path of the current symbol in cursor."
(interactive)
(let ((dep-buffer (rtags-get-buffer))
(let ((dep-buffer (rtags-get-buffer "*RTags Include Path*"))
(arg (rtags-current-location)))
(rtags-delete-rtags-windows)
(rtags-location-stack-push)
@@ -4007,6 +4007,19 @@ other window instead of the current one."
(let ((cur (rtags-dependency-tree-current-file)))
(when cur
(rtags-goto-location (car cur) nil other-window))))
((string= (buffer-name) "*RTags Include Path*")
(let (start path)
(save-excursion
(setq start (if (search-backward " " (point-at-bol) t)
(1+ (point))
(point-at-bol))))
(save-excursion
(setq path (buffer-substring-no-properties start
(if (search-forward " " (point-at-eol) t)
(1- (point))
(point-at-eol)))))
(unless (string= "->" path)
(rtags-goto-location path))))
((string= (buffer-name) "*RTags Location Stack*")
(let ((index (- (length rtags-location-stack) line)))
(setq rtags-location-stack-index index)

0 comments on commit c1a93c2

Please sign in to comment.
You can’t perform that action at this time.