data: Replaced NameDelimiterType in NameHierarchy with std::wstring to allow use with arbitrary delimiters
This commit is contained in:
@@ -21,7 +21,7 @@ std::wstring NameHierarchy::serialize(const NameHierarchy& nameHierarchy)
|
||||
std::wstring NameHierarchy::serializeRange(const NameHierarchy& nameHierarchy, size_t first, size_t last)
|
||||
{
|
||||
std::wstringstream ss;
|
||||
ss << nameDelimiterTypeToString(nameHierarchy.getDelimiter());
|
||||
ss << nameHierarchy.getDelimiter();
|
||||
ss << META_DELIMITER;
|
||||
for (size_t i = first; i < last && i < nameHierarchy.size(); i++)
|
||||
{
|
||||
@@ -47,7 +47,7 @@ NameHierarchy NameHierarchy::deserialize(const std::wstring& serializedName)
|
||||
return NameHierarchy(NAME_DELIMITER_UNKNOWN);
|
||||
}
|
||||
|
||||
NameHierarchy nameHierarchy(stringToNameDelimiterType(serializedName.substr(0, mpos)));
|
||||
NameHierarchy nameHierarchy(serializedName.substr(0, mpos));
|
||||
|
||||
size_t npos = mpos + META_DELIMITER.size();
|
||||
while (npos != std::wstring::npos && npos < serializedName.size())
|
||||
@@ -92,23 +92,23 @@ NameHierarchy NameHierarchy::deserialize(const std::wstring& serializedName)
|
||||
return nameHierarchy;
|
||||
}
|
||||
|
||||
NameDelimiterType NameHierarchy::getDelimiter() const
|
||||
const std::wstring& NameHierarchy::getDelimiter() const
|
||||
{
|
||||
return m_delimiter;
|
||||
}
|
||||
|
||||
void NameHierarchy::setDelimiter(const NameDelimiterType delimiter)
|
||||
void NameHierarchy::setDelimiter(std::wstring delimiter)
|
||||
{
|
||||
m_delimiter = delimiter;
|
||||
m_delimiter = std::move(delimiter);
|
||||
}
|
||||
|
||||
NameHierarchy::NameHierarchy(const NameDelimiterType delimiter)
|
||||
: m_delimiter(delimiter)
|
||||
NameHierarchy::NameHierarchy(std::wstring delimiter)
|
||||
: m_delimiter(std::move(delimiter))
|
||||
{
|
||||
}
|
||||
|
||||
NameHierarchy::NameHierarchy(const std::vector<std::wstring>& names, const NameDelimiterType delimiter)
|
||||
: m_delimiter(delimiter)
|
||||
NameHierarchy::NameHierarchy(const std::vector<std::wstring>& names, std::wstring delimiter)
|
||||
: m_delimiter(std::move(delimiter))
|
||||
{
|
||||
for (const std::wstring& name : names)
|
||||
{
|
||||
@@ -116,12 +116,27 @@ NameHierarchy::NameHierarchy(const std::vector<std::wstring>& names, const NameD
|
||||
}
|
||||
}
|
||||
|
||||
NameHierarchy::NameHierarchy(std::wstring name, const NameDelimiterType delimiter)
|
||||
: m_delimiter(delimiter)
|
||||
NameHierarchy::NameHierarchy(std::wstring name, std::wstring delimiter)
|
||||
: m_delimiter(std::move(delimiter))
|
||||
{
|
||||
push(std::move(name));
|
||||
}
|
||||
|
||||
NameHierarchy::NameHierarchy(const NameDelimiterType delimiterType)
|
||||
: NameHierarchy(nameDelimiterTypeToString(delimiterType))
|
||||
{
|
||||
}
|
||||
|
||||
NameHierarchy::NameHierarchy(std::wstring name, const NameDelimiterType delimiterType)
|
||||
: NameHierarchy(name, nameDelimiterTypeToString(delimiterType))
|
||||
{
|
||||
}
|
||||
|
||||
NameHierarchy::NameHierarchy(const std::vector<std::wstring>& names, const NameDelimiterType delimiterType)
|
||||
: NameHierarchy(names, nameDelimiterTypeToString(delimiterType))
|
||||
{
|
||||
}
|
||||
|
||||
NameHierarchy::NameHierarchy(const NameHierarchy& other)
|
||||
: m_elements(other.m_elements)
|
||||
, m_delimiter(other.m_delimiter)
|
||||
@@ -130,7 +145,7 @@ NameHierarchy::NameHierarchy(const NameHierarchy& other)
|
||||
|
||||
NameHierarchy::NameHierarchy(NameHierarchy&& other)
|
||||
: m_elements(std::move(other.m_elements))
|
||||
, m_delimiter(other.m_delimiter)
|
||||
, m_delimiter(std::move(other.m_delimiter))
|
||||
{
|
||||
}
|
||||
|
||||
@@ -183,7 +198,7 @@ NameHierarchy& NameHierarchy::operator=(const NameHierarchy& other)
|
||||
NameHierarchy& NameHierarchy::operator=(NameHierarchy&& other)
|
||||
{
|
||||
m_elements = std::move(other.m_elements);
|
||||
m_delimiter = other.m_delimiter;
|
||||
m_delimiter = std::move(other.m_delimiter);
|
||||
return *this;
|
||||
}
|
||||
|
||||
@@ -211,7 +226,7 @@ std::wstring NameHierarchy::getQualifiedName() const
|
||||
{
|
||||
if (i > 0)
|
||||
{
|
||||
ss << nameDelimiterTypeToString(m_delimiter);
|
||||
ss << m_delimiter;
|
||||
}
|
||||
ss << m_elements[i].getName();
|
||||
}
|
||||
|
||||
@@ -14,16 +14,20 @@ public:
|
||||
static std::wstring serializeRange(const NameHierarchy& nameHierarchy, size_t first, size_t last);
|
||||
static NameHierarchy deserialize(const std::wstring& serializedName);
|
||||
|
||||
NameHierarchy(const NameDelimiterType delimiter = NAME_DELIMITER_UNKNOWN);
|
||||
NameHierarchy(const std::vector<std::wstring>& names, const NameDelimiterType delimiter);
|
||||
NameHierarchy(std::wstring name, const NameDelimiterType delimiter);
|
||||
NameHierarchy(std::wstring delimiter);
|
||||
NameHierarchy(std::wstring name, std::wstring delimiter);
|
||||
NameHierarchy(const std::vector<std::wstring>& names, std::wstring delimiter);
|
||||
|
||||
NameHierarchy(const NameDelimiterType delimiterType = NAME_DELIMITER_UNKNOWN);
|
||||
NameHierarchy(std::wstring name, const NameDelimiterType delimiterType);
|
||||
NameHierarchy(const std::vector<std::wstring>& names, const NameDelimiterType delimiterType);
|
||||
|
||||
NameHierarchy(const NameHierarchy& other);
|
||||
NameHierarchy(NameHierarchy&& other);
|
||||
~NameHierarchy();
|
||||
|
||||
NameDelimiterType getDelimiter() const;
|
||||
void setDelimiter(const NameDelimiterType delimiter);
|
||||
const std::wstring& getDelimiter() const;
|
||||
void setDelimiter(std::wstring delimiter);
|
||||
|
||||
void push(NameElement element);
|
||||
void push(std::wstring name);
|
||||
@@ -52,7 +56,7 @@ public:
|
||||
|
||||
private:
|
||||
std::vector<NameElement> m_elements;
|
||||
NameDelimiterType m_delimiter;
|
||||
std::wstring m_delimiter;
|
||||
};
|
||||
|
||||
#endif // NAME_ELEMENT_H
|
||||
|
||||
@@ -67,8 +67,6 @@ struct SearchMatch
|
||||
std::vector<Id> tokenIds;
|
||||
std::vector<NameHierarchy> tokenNames;
|
||||
|
||||
NameDelimiterType delimiter;
|
||||
|
||||
std::wstring typeName;
|
||||
|
||||
NodeType nodeType;
|
||||
|
||||
@@ -664,7 +664,7 @@ std::vector<SearchMatch> PersistentStorage::getAutocompletionMatches(const std::
|
||||
else if (lastMatch->score == match.score && match.tokenNames.size())
|
||||
{
|
||||
size_t lastSize = lastMatch->name.size();
|
||||
if (match.name.find(nameDelimiterTypeToString(match.tokenNames[0].getDelimiter()), lastSize) == lastSize)
|
||||
if (match.name.find(match.tokenNames[0].getDelimiter(), lastSize) == lastSize)
|
||||
{
|
||||
match.score -= 10;
|
||||
}
|
||||
@@ -1910,7 +1910,8 @@ TooltipSnippet PersistentStorage::getTooltipSnippetForNode(const StorageNode& no
|
||||
TooltipSnippet snippet;
|
||||
snippet.code = nameHierarchy.getQualifiedNameWithSignature();
|
||||
snippet.locationFile = std::make_shared<SourceLocationFile>(
|
||||
FilePath(nameHierarchy.getDelimiter() == NAME_DELIMITER_JAVA ? L"main.java" : L"main.cpp"), true, true, true);
|
||||
FilePath(nameHierarchy.getDelimiter() == nameDelimiterTypeToString(NAME_DELIMITER_JAVA) ? L"main.java" : L"main.cpp"),
|
||||
true, true, true);
|
||||
|
||||
if (nameHierarchy.hasSignature())
|
||||
{
|
||||
@@ -1994,7 +1995,7 @@ TooltipSnippet PersistentStorage::getTooltipSnippetForNode(const StorageNode& no
|
||||
|
||||
// store texts of annotations
|
||||
std::vector<std::pair<Id, std::wstring>> annotatedTexts;
|
||||
std::wstring delimiter = nameDelimiterTypeToString(nameHierarchy.getDelimiter());
|
||||
std::wstring delimiter = nameHierarchy.getDelimiter();
|
||||
size_t offset = 0;
|
||||
for (const Annotation& annotation : annotations)
|
||||
{
|
||||
@@ -2156,7 +2157,8 @@ TooltipInfo PersistentStorage::getTooltipInfoForSourceLocationIdsAndLocalSymbolI
|
||||
const NameHierarchy nameHierarchy = NameHierarchy::deserialize(node.serializedName);
|
||||
snippet.code = nameHierarchy.getQualifiedName();
|
||||
snippet.locationFile = std::make_shared<SourceLocationFile>(
|
||||
FilePath(nameHierarchy.getDelimiter() == NAME_DELIMITER_JAVA ? L"main.java" : L"main.cpp"), true, true, true);
|
||||
FilePath(nameHierarchy.getDelimiter() == nameDelimiterTypeToString(NAME_DELIMITER_JAVA) ? L"main.java" : L"main.cpp"),
|
||||
true, true, true);
|
||||
|
||||
snippet.locationFile->addSourceLocation(
|
||||
LOCATION_TOKEN, 0, std::vector<Id>(1, node.id), 1, 1, 1, snippet.code.size());
|
||||
@@ -2920,7 +2922,7 @@ void PersistentStorage::buildSearchIndex()
|
||||
|
||||
// replace template arguments with .. to avoid clutter in search results and have different
|
||||
// template specializations share the same node.
|
||||
if (defKind == DEFINITION_NONE && nameHierarchy.getDelimiter() == NAME_DELIMITER_CXX)
|
||||
if (defKind == DEFINITION_NONE && nameHierarchy.getDelimiter() == nameDelimiterTypeToString(NAME_DELIMITER_CXX))
|
||||
{
|
||||
name = utility::replaceBetween(name, L'<', L'>', L"..");
|
||||
}
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
#include "QtSmartSearchBox.h"
|
||||
|
||||
#include <deque>
|
||||
#include <regex>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <QApplication>
|
||||
@@ -193,7 +195,7 @@ bool QtSmartSearchBox::event(QEvent *event)
|
||||
else if (m_highlightedMatch.hasChildren && m_highlightedMatch.tokenNames.size())
|
||||
{
|
||||
setEditText(QString::fromStdWString(
|
||||
m_highlightedMatch.getFullName() + nameDelimiterTypeToString(m_highlightedMatch.tokenNames[0].getDelimiter())));
|
||||
m_highlightedMatch.getFullName() + m_highlightedMatch.tokenNames[0].getDelimiter()));
|
||||
requestAutoCompletions();
|
||||
}
|
||||
else
|
||||
@@ -301,21 +303,43 @@ void QtSmartSearchBox::keyPressEvent(QKeyEvent* event)
|
||||
}
|
||||
else
|
||||
{
|
||||
const NameDelimiterType delimiter = detectDelimiterType(text().toStdWString());
|
||||
std::vector<std::string> names = utility::splitToVector(text().toStdString(), delimiter);
|
||||
if (names.back() == "")
|
||||
std::string str = text().toStdString();
|
||||
std::smatch match;
|
||||
std::regex regExp(".\\b");
|
||||
|
||||
std::deque<std::string> parts;
|
||||
while (std::regex_search(str, match, regExp))
|
||||
{
|
||||
names.pop_back();
|
||||
parts.push_back(str.substr(0, match.position(0) + match.length(0)));
|
||||
str = match.suffix();
|
||||
}
|
||||
|
||||
if (names.size() < 2)
|
||||
if (str.size())
|
||||
{
|
||||
setEditText("");
|
||||
parts.push_back(str);
|
||||
}
|
||||
else
|
||||
|
||||
str.clear();
|
||||
while (parts.size() && int(str.size() + parts.front().size()) < cursorPosition())
|
||||
{
|
||||
names.back() = "";
|
||||
setEditText(utility::join(names, delimiter).c_str());
|
||||
str += parts.front();
|
||||
parts.pop_front();
|
||||
}
|
||||
|
||||
size_t size = 0;
|
||||
if (parts.size())
|
||||
{
|
||||
size = str.size();
|
||||
str += parts.front().substr(cursorPosition() - str.size());
|
||||
parts.pop_front();
|
||||
}
|
||||
|
||||
str += utility::join(parts, "");
|
||||
|
||||
setEditText(QString::fromStdString(str));
|
||||
if (size)
|
||||
{
|
||||
setCursorPosition(size);
|
||||
}
|
||||
|
||||
requestAutoCompletions();
|
||||
|
||||
Reference in New Issue
Block a user