ui: Extracted syntax highlighting rules for java and cpp to files
* pass file language from storage to code view * load syntax highlighting rules files from install directory "syntax_highlighting_rules" * files must be named <language_identifier>.rules to make syntax highlighting work
This commit is contained in:
@@ -48,7 +48,7 @@ void CodeController::handleMessage(MessageActivateAll* message)
|
||||
|
||||
statsSnippet.reduced = true;
|
||||
|
||||
statsSnippet.locationFile = std::make_shared<SourceLocationFile>(FilePath(), true, true, true);
|
||||
statsSnippet.locationFile = std::make_shared<SourceLocationFile>(FilePath(), L"", true, true, true);
|
||||
|
||||
std::vector<std::string> description = getProjectDescription(statsSnippet.locationFile.get());
|
||||
|
||||
|
||||
@@ -90,9 +90,9 @@ DEF_GETTER_2(getActiveTokenIdsForId, Id, Id*, std::vector<Id>, {})
|
||||
DEF_GETTER_1(getNodeIdsForLocationIds, const std::vector<Id>&, std::vector<Id>, {})
|
||||
DEF_GETTER_1(getSourceLocationsForTokenIds, const std::vector<Id>&, std::shared_ptr<SourceLocationCollection>, std::make_shared<SourceLocationCollection>())
|
||||
DEF_GETTER_1(getSourceLocationsForLocationIds, const std::vector<Id>&, std::shared_ptr<SourceLocationCollection>, std::make_shared<SourceLocationCollection>())
|
||||
DEF_GETTER_1(getSourceLocationsForFile, const FilePath&, std::shared_ptr<SourceLocationFile>, std::make_shared<SourceLocationFile>(FilePath(), false, false, false))
|
||||
DEF_GETTER_3(getSourceLocationsForLinesInFile, const FilePath&, size_t, size_t, std::shared_ptr<SourceLocationFile>, std::make_shared<SourceLocationFile>(FilePath(), false, false, false))
|
||||
DEF_GETTER_2(getSourceLocationsOfTypeInFile, const FilePath&, LocationType, std::shared_ptr<SourceLocationFile>, std::make_shared<SourceLocationFile>(FilePath(), false, false, false))
|
||||
DEF_GETTER_1(getSourceLocationsForFile, const FilePath&, std::shared_ptr<SourceLocationFile>, std::make_shared<SourceLocationFile>(FilePath(), L"", false, false, false))
|
||||
DEF_GETTER_3(getSourceLocationsForLinesInFile, const FilePath&, size_t, size_t, std::shared_ptr<SourceLocationFile>, std::make_shared<SourceLocationFile>(FilePath(), L"", false, false, false))
|
||||
DEF_GETTER_2(getSourceLocationsOfTypeInFile, const FilePath&, LocationType, std::shared_ptr<SourceLocationFile>, std::make_shared<SourceLocationFile>(FilePath(), L"", false, false, false))
|
||||
DEF_GETTER_2(getFileContent, const FilePath&, bool, std::shared_ptr<TextAccess>, nullptr)
|
||||
DEF_GETTER_1(getFileInfoForFileId, Id, FileInfo, FileInfo())
|
||||
DEF_GETTER_1(getFileInfoForFilePath, const FilePath&, FileInfo, FileInfo())
|
||||
|
||||
@@ -81,8 +81,8 @@ SourceLocation* SourceLocationCollection::addSourceLocation(
|
||||
SourceLocation* SourceLocationCollection::addSourceLocationCopy(const SourceLocation* location)
|
||||
{
|
||||
SourceLocationFile* other = location->getSourceLocationFile();
|
||||
SourceLocationFile* file =
|
||||
createSourceLocationFile(location->getFilePath(), other->isWhole(), other->isComplete(), other->isIndexed());
|
||||
SourceLocationFile* file = createSourceLocationFile(
|
||||
location->getFilePath(), other->getLanguage(), other->isWhole(), other->isComplete(), other->isIndexed());
|
||||
return file->addSourceLocationCopy(location);
|
||||
}
|
||||
|
||||
@@ -92,7 +92,8 @@ void SourceLocationCollection::addSourceLocationCopies(const SourceLocationColle
|
||||
[this](std::shared_ptr<SourceLocationFile> otherFile)
|
||||
{
|
||||
SourceLocationFile* file = createSourceLocationFile(
|
||||
otherFile->getFilePath(), otherFile->isWhole(), otherFile->isComplete(), otherFile->isIndexed());
|
||||
otherFile->getFilePath(), otherFile->getLanguage(), otherFile->isWhole(), otherFile->isComplete(),
|
||||
otherFile->isIndexed());
|
||||
|
||||
otherFile->forEachSourceLocation(
|
||||
[file](SourceLocation* otherLocation)
|
||||
@@ -127,7 +128,7 @@ void SourceLocationCollection::forEachSourceLocation(std::function<void(SourceLo
|
||||
}
|
||||
|
||||
SourceLocationFile* SourceLocationCollection::createSourceLocationFile(
|
||||
const FilePath& filePath, bool isWhole, bool isComplete, bool isIndexed)
|
||||
const FilePath& filePath, const std::wstring& language, bool isWhole, bool isComplete, bool isIndexed)
|
||||
{
|
||||
SourceLocationFile* file = getSourceLocationFileByPath(filePath).get();
|
||||
if (file)
|
||||
@@ -136,7 +137,7 @@ SourceLocationFile* SourceLocationCollection::createSourceLocationFile(
|
||||
}
|
||||
|
||||
std::shared_ptr<SourceLocationFile> filePtr =
|
||||
std::make_shared<SourceLocationFile>(filePath, isWhole, isComplete, isIndexed);
|
||||
std::make_shared<SourceLocationFile>(filePath, language, isWhole, isComplete, isIndexed);
|
||||
m_files.emplace(filePath, filePtr);
|
||||
return filePtr.get();
|
||||
}
|
||||
|
||||
@@ -43,7 +43,7 @@ public:
|
||||
|
||||
private:
|
||||
SourceLocationFile* createSourceLocationFile(
|
||||
const FilePath& filePath, bool isWhole = false, bool isComplete = false, bool isIndexed = false);
|
||||
const FilePath& filePath, const std::wstring& language = L"", bool isWhole = false, bool isComplete = false, bool isIndexed = false);
|
||||
|
||||
std::map<FilePath, std::shared_ptr<SourceLocationFile>> m_files;
|
||||
};
|
||||
|
||||
@@ -1,7 +1,10 @@
|
||||
#include "SourceLocationFile.h"
|
||||
|
||||
SourceLocationFile::SourceLocationFile(const FilePath& filePath, bool isWhole, bool isComplete, bool isIndexed)
|
||||
SourceLocationFile::SourceLocationFile(
|
||||
const FilePath& filePath, const std::wstring& language, bool isWhole, bool isComplete, bool isIndexed
|
||||
)
|
||||
: m_filePath(filePath)
|
||||
, m_language(language)
|
||||
, m_isWhole(isWhole)
|
||||
, m_isComplete(isComplete)
|
||||
, m_isIndexed(isIndexed)
|
||||
@@ -17,6 +20,16 @@ const FilePath& SourceLocationFile::getFilePath() const
|
||||
return m_filePath;
|
||||
}
|
||||
|
||||
void SourceLocationFile::setLanguage(const std::wstring& language)
|
||||
{
|
||||
m_language = language;
|
||||
}
|
||||
|
||||
const std::wstring& SourceLocationFile::getLanguage() const
|
||||
{
|
||||
return m_language;
|
||||
}
|
||||
|
||||
void SourceLocationFile::setIsWhole(bool isWhole)
|
||||
{
|
||||
m_isWhole = isWhole;
|
||||
@@ -182,7 +195,7 @@ std::shared_ptr<SourceLocationFile> SourceLocationFile::getFilteredByLines(
|
||||
size_t firstLineNumber, size_t lastLineNumber) const
|
||||
{
|
||||
std::shared_ptr<SourceLocationFile> ret =
|
||||
std::make_shared<SourceLocationFile>(getFilePath(), false, isComplete(), isIndexed());
|
||||
std::make_shared<SourceLocationFile>(getFilePath(), getLanguage(), false, isComplete(), isIndexed());
|
||||
|
||||
for (const std::shared_ptr<SourceLocation>& location : m_locations)
|
||||
{
|
||||
@@ -198,7 +211,7 @@ std::shared_ptr<SourceLocationFile> SourceLocationFile::getFilteredByLines(
|
||||
std::shared_ptr<SourceLocationFile> SourceLocationFile::getFilteredByType(LocationType type) const
|
||||
{
|
||||
std::shared_ptr<SourceLocationFile> ret =
|
||||
std::make_shared<SourceLocationFile>(getFilePath(), false, isComplete(), isIndexed());
|
||||
std::make_shared<SourceLocationFile>(getFilePath(), getLanguage(), false, isComplete(), isIndexed());
|
||||
|
||||
for (const std::shared_ptr<SourceLocation>& location : m_locations)
|
||||
{
|
||||
@@ -220,7 +233,7 @@ std::shared_ptr<SourceLocationFile> SourceLocationFile::getFilteredByTypes(const
|
||||
}
|
||||
|
||||
std::shared_ptr<SourceLocationFile> ret =
|
||||
std::make_shared<SourceLocationFile>(getFilePath(), false, isComplete(), isIndexed());
|
||||
std::make_shared<SourceLocationFile>(getFilePath(), getLanguage(), false, isComplete(), isIndexed());
|
||||
|
||||
for (const std::shared_ptr<SourceLocation>& location : m_locations)
|
||||
{
|
||||
|
||||
@@ -23,11 +23,14 @@ public:
|
||||
}
|
||||
};
|
||||
|
||||
SourceLocationFile(const FilePath& filePath, bool isWhole, bool isComplete, bool isIndexed);
|
||||
SourceLocationFile(const FilePath& filePath, const std::wstring& language, bool isWhole, bool isComplete, bool isIndexed);
|
||||
virtual ~SourceLocationFile();
|
||||
|
||||
const FilePath& getFilePath() const;
|
||||
|
||||
void setLanguage(const std::wstring& language);
|
||||
const std::wstring& getLanguage() const;
|
||||
|
||||
void setIsWhole(bool isWhole);
|
||||
bool isWhole() const;
|
||||
|
||||
@@ -62,6 +65,7 @@ public:
|
||||
|
||||
private:
|
||||
const FilePath m_filePath;
|
||||
std::wstring m_language;
|
||||
bool m_isWhole;
|
||||
bool m_isComplete;
|
||||
bool m_isIndexed;
|
||||
|
||||
@@ -289,6 +289,7 @@ void PersistentStorage::clearCaches()
|
||||
m_fileNodePaths.clear();
|
||||
m_fileNodeComplete.clear();
|
||||
m_fileNodeIndexed.clear();
|
||||
m_fileNodeLanguage.clear();
|
||||
m_symbolDefinitionKinds.clear();
|
||||
|
||||
m_hierarchyCache.clear();
|
||||
@@ -1303,7 +1304,7 @@ std::shared_ptr<SourceLocationCollection> PersistentStorage::getSourceLocationsF
|
||||
{
|
||||
TRACE();
|
||||
|
||||
std::vector<FilePath> filePaths;
|
||||
std::map<Id, FilePath> filePaths;
|
||||
std::vector<Id> nonFileIds;
|
||||
|
||||
for (const Id tokenId : tokenIds)
|
||||
@@ -1326,14 +1327,15 @@ std::shared_ptr<SourceLocationCollection> PersistentStorage::getSourceLocationsF
|
||||
}
|
||||
else
|
||||
{
|
||||
filePaths.push_back(path);
|
||||
filePaths.emplace(tokenId, path);
|
||||
}
|
||||
}
|
||||
|
||||
std::shared_ptr<SourceLocationCollection> collection = std::make_shared<SourceLocationCollection>();
|
||||
for (const FilePath& path : filePaths)
|
||||
for (const std::pair<Id, FilePath>& p : filePaths)
|
||||
{
|
||||
collection->addSourceLocationFile(std::make_shared<SourceLocationFile>(path, true, false, false));
|
||||
collection->addSourceLocationFile(
|
||||
std::make_shared<SourceLocationFile>(p.second, getFileNodeLanguage(p.first), true, false, false));
|
||||
}
|
||||
|
||||
if (nonFileIds.size())
|
||||
@@ -1909,9 +1911,16 @@ TooltipSnippet PersistentStorage::getTooltipSnippetForNode(const StorageNode& no
|
||||
const NameHierarchy nameHierarchy = NameHierarchy::deserialize(node.serializedName);
|
||||
TooltipSnippet snippet;
|
||||
snippet.code = nameHierarchy.getQualifiedNameWithSignature();
|
||||
snippet.locationFile = std::make_shared<SourceLocationFile>(
|
||||
FilePath(nameHierarchy.getDelimiter() == nameDelimiterTypeToString(NAME_DELIMITER_JAVA) ? L"main.java" : L"main.cpp"),
|
||||
true, true, true);
|
||||
snippet.locationFile = std::make_shared<SourceLocationFile>(FilePath(L"main.txt"), L"", true, true, true);
|
||||
|
||||
// set file language
|
||||
std::vector<StorageOccurrence> occurrences = m_sqliteIndexStorage.getOccurrencesForElementIds({ node.id });
|
||||
if (occurrences.size())
|
||||
{
|
||||
const Id locationId = occurrences.front().sourceLocationId;
|
||||
const Id fileId = m_sqliteIndexStorage.getFirstById<StorageSourceLocation>(locationId).fileNodeId;
|
||||
snippet.locationFile->setLanguage(getFileNodeLanguage(fileId));
|
||||
}
|
||||
|
||||
if (nameHierarchy.hasSignature())
|
||||
{
|
||||
@@ -2148,6 +2157,9 @@ TooltipInfo PersistentStorage::getTooltipInfoForSourceLocationIdsAndLocalSymbolI
|
||||
|
||||
if (!locationIds.empty())
|
||||
{
|
||||
std::wstring fileLanguage = getFileNodeLanguage(
|
||||
m_sqliteIndexStorage.getFirstById<StorageSourceLocation>(locationIds.front()).fileNodeId);
|
||||
|
||||
const std::vector<Id> nodeIds = getNodeIdsForLocationIds(locationIds);
|
||||
|
||||
for (const StorageNode& node : m_sqliteIndexStorage.getAllByIds<StorageNode>(nodeIds))
|
||||
@@ -2156,9 +2168,7 @@ TooltipInfo PersistentStorage::getTooltipInfoForSourceLocationIdsAndLocalSymbolI
|
||||
|
||||
const NameHierarchy nameHierarchy = NameHierarchy::deserialize(node.serializedName);
|
||||
snippet.code = nameHierarchy.getQualifiedName();
|
||||
snippet.locationFile = std::make_shared<SourceLocationFile>(
|
||||
FilePath(nameHierarchy.getDelimiter() == nameDelimiterTypeToString(NAME_DELIMITER_JAVA) ? L"main.java" : L"main.cpp"),
|
||||
true, true, true);
|
||||
snippet.locationFile = std::make_shared<SourceLocationFile>(FilePath(L"main.txt"), fileLanguage, true, true, true);
|
||||
|
||||
snippet.locationFile->addSourceLocation(
|
||||
LOCATION_TOKEN, 0, std::vector<Id>(1, node.id), 1, 1, 1, snippet.code.size());
|
||||
@@ -2177,7 +2187,7 @@ TooltipInfo PersistentStorage::getTooltipInfoForSourceLocationIdsAndLocalSymbolI
|
||||
TooltipSnippet snippet;
|
||||
|
||||
snippet.code = L"local symbol";
|
||||
snippet.locationFile = std::make_shared<SourceLocationFile>(FilePath(L"main.cpp"), true, true, true);
|
||||
snippet.locationFile = std::make_shared<SourceLocationFile>(FilePath(L"main.txt"), L"", true, true, true);
|
||||
snippet.locationFile->addSourceLocation(
|
||||
LOCATION_LOCAL_SYMBOL, 0, std::vector<Id>(1, id), 1, 1, 1, snippet.code.size());
|
||||
|
||||
@@ -2275,6 +2285,17 @@ bool PersistentStorage::getFileNodeIndexed(Id fileId) const
|
||||
return false;
|
||||
}
|
||||
|
||||
std::wstring PersistentStorage::getFileNodeLanguage(Id fileId) const
|
||||
{
|
||||
auto it = m_fileNodeLanguage.find(fileId);
|
||||
if (it != m_fileNodeLanguage.end())
|
||||
{
|
||||
return it->second;
|
||||
}
|
||||
|
||||
return L"";
|
||||
}
|
||||
|
||||
std::unordered_map<Id, std::set<Id>> PersistentStorage::getFileIdToIncludingFileIdMap() const
|
||||
{
|
||||
std::unordered_map<Id, std::set<Id>> fileIdToIncludingFileIdMap;
|
||||
@@ -2778,6 +2799,7 @@ void PersistentStorage::addCompleteFlagsToSourceLocationCollection(SourceLocatio
|
||||
Id fileId = getFileNodeId(file->getFilePath());
|
||||
file->setIsComplete(getFileNodeComplete(fileId));
|
||||
file->setIsIndexed(getFileNodeIndexed(fileId));
|
||||
file->setLanguage(getFileNodeLanguage(fileId));
|
||||
}
|
||||
);
|
||||
}
|
||||
@@ -2862,6 +2884,7 @@ void PersistentStorage::buildFilePathMaps()
|
||||
m_fileNodePaths.emplace(file.id, path);
|
||||
m_fileNodeComplete.emplace(file.id, file.complete);
|
||||
m_fileNodeIndexed.emplace(file.id, file.indexed);
|
||||
m_fileNodeLanguage.emplace(file.id, file.languageIdentifier);
|
||||
|
||||
if (!m_hasJavaFiles && path.extension() == L".java")
|
||||
{
|
||||
|
||||
@@ -173,6 +173,7 @@ private:
|
||||
FilePath getFileNodePath(Id fileId) const;
|
||||
bool getFileNodeComplete(Id fileId) const;
|
||||
bool getFileNodeIndexed(Id fileId) const;
|
||||
std::wstring getFileNodeLanguage(Id fileId) const;
|
||||
|
||||
std::unordered_map<Id, std::set<Id>> getFileIdToIncludingFileIdMap() const;
|
||||
std::unordered_map<Id, std::set<Id>> getFileIdToIncludedFileIdMap() const;
|
||||
@@ -224,6 +225,7 @@ private:
|
||||
std::map<Id, FilePath> m_fileNodePaths;
|
||||
std::map<Id, bool> m_fileNodeComplete;
|
||||
std::map<Id, bool> m_fileNodeIndexed;
|
||||
std::map<Id, std::wstring> m_fileNodeLanguage;
|
||||
|
||||
std::map<Id, DefinitionKind> m_symbolDefinitionKinds;
|
||||
std::map<Id, Id> m_memberEdgeIdOrderMap;
|
||||
|
||||
@@ -832,7 +832,7 @@ void SqliteIndexStorage::setNodeType(int type, Id nodeId)
|
||||
std::shared_ptr<SourceLocationFile> SqliteIndexStorage::getSourceLocationsForFile(
|
||||
const FilePath& filePath, const std::string& query) const
|
||||
{
|
||||
std::shared_ptr<SourceLocationFile> ret = std::make_shared<SourceLocationFile>(filePath, true, false, false);
|
||||
std::shared_ptr<SourceLocationFile> ret = std::make_shared<SourceLocationFile>(filePath, L"", true, false, false);
|
||||
|
||||
const StorageFile file = getFileByPath(filePath.wstr());
|
||||
if (file.id == 0) // early out
|
||||
@@ -840,6 +840,7 @@ std::shared_ptr<SourceLocationFile> SqliteIndexStorage::getSourceLocationsForFil
|
||||
return ret;
|
||||
}
|
||||
|
||||
ret->setLanguage(file.languageIdentifier);
|
||||
ret->setIsComplete(file.complete);
|
||||
ret->setIsIndexed(file.indexed);
|
||||
|
||||
|
||||
@@ -7,6 +7,11 @@ FilePath ResourcePaths::getColorSchemesPath()
|
||||
return AppPath::getAppPath().concatenate(L"data/color_schemes/");
|
||||
}
|
||||
|
||||
FilePath ResourcePaths::getSyntaxHighlightingRulesPath()
|
||||
{
|
||||
return AppPath::getAppPath().concatenate(L"data/syntax_highlighting_rules/");
|
||||
}
|
||||
|
||||
FilePath ResourcePaths::getFallbackPath()
|
||||
{
|
||||
return AppPath::getAppPath().concatenate(L"data/fallback/");
|
||||
|
||||
@@ -9,6 +9,7 @@ class ResourcePaths
|
||||
{
|
||||
public:
|
||||
static FilePath getColorSchemesPath();
|
||||
static FilePath getSyntaxHighlightingRulesPath();
|
||||
static FilePath getFallbackPath();
|
||||
static FilePath getFontsPath();
|
||||
static FilePath getGuiPath();
|
||||
|
||||
Reference in New Issue
Block a user