Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
EditorConfig plugin: cache the .editorconfig parsed for future use
EditorConfig plugin: changes are applied once the .editorconfig is saved, there is no need to reload the file being edited for the changes to take place
- Loading branch information
Showing
9 changed files
with
298 additions
and
160 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
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,38 @@ | ||
#include "EditorConfigCache.h" | ||
#include "fileutils.h" | ||
|
||
EditorConfigCache::EditorConfigCache() {} | ||
|
||
EditorConfigCache::~EditorConfigCache() {} | ||
|
||
bool EditorConfigCache::Get(const wxFileName& filename, clEditorConfigSection& section) | ||
{ | ||
wxString key = filename.GetFullPath(); | ||
if(m_map.count(key) == 0) return false; | ||
|
||
CachedItem& entry = m_map[key]; | ||
time_t lastModTimeOnDisk = FileUtils::GetFileModificationTime(entry.section.GetFilename()); | ||
if(lastModTimeOnDisk != entry.lastModified) { | ||
// remove this entry and return false | ||
m_map.erase(key); | ||
return false; | ||
} | ||
|
||
section = entry.section; | ||
return true; | ||
} | ||
|
||
void EditorConfigCache::Add(const wxFileName& filename, const clEditorConfigSection& section) | ||
{ | ||
wxString key = filename.GetFullPath(); | ||
if(m_map.count(key)) { | ||
m_map.erase(key); | ||
} | ||
|
||
CachedItem entry; | ||
entry.lastModified = FileUtils::GetFileModificationTime(section.GetFilename()); | ||
entry.section = section; | ||
m_map.insert(std::make_pair(key, entry)); | ||
} | ||
|
||
void EditorConfigCache::Clear() { m_map.clear(); } |
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,38 @@ | ||
#ifndef EDITORCONFIGCACHE_H | ||
#define EDITORCONFIGCACHE_H | ||
|
||
#include <wx/filename.h> | ||
#include "clEditorConfig.h" | ||
#include <map> | ||
|
||
class EditorConfigCache | ||
{ | ||
private: | ||
struct CachedItem { | ||
clEditorConfigSection section; | ||
time_t lastModified; | ||
}; | ||
|
||
std::map<wxString, CachedItem> m_map; | ||
|
||
public: | ||
EditorConfigCache(); | ||
virtual ~EditorConfigCache(); | ||
|
||
/** | ||
* @brief find cached item for given filename | ||
*/ | ||
bool Get(const wxFileName& filename, clEditorConfigSection& section); | ||
|
||
/** | ||
* @brief add entry to the cache | ||
*/ | ||
void Add(const wxFileName& filename, const clEditorConfigSection& section); | ||
|
||
/** | ||
* @brief clear the cache | ||
*/ | ||
void Clear(); | ||
}; | ||
|
||
#endif // EDITORCONFIGCACHE_H |
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
Oops, something went wrong.