Added a new option to set files associations in projects.

Introduced a new configuration file for projects in the project file `.ecode/settings.json` file.
Initially it supports files associations the following way:
```json
{
	"files.associations": {
		"glob_pattern": "language_name",
		"functional": "cpp",
		"map": "cpp",
		"**/c++/**": "cpp"
	}
}
```

Format is exactly the same as in vscode, and also, if no `.ecode/settings.json` file exists but does `.vscode/settings.json` file exists, it will fallback to that one.
This is related to the discussion in issue SpartanJ/ecode#585.
This commit is contained in:
Martín Lucas Golini
2025-10-06 00:12:05 -03:00
parent 92bb0c9d75
commit 4edb776d51
5 changed files with 60 additions and 0 deletions
+46
View File
@@ -919,10 +919,56 @@ void AppConfig::loadProject( std::string projectFolder, UICodeEditorSplitter* ed
plugin->onLoadProject( projectFolder, projectPluginsStatePath );
} );
}
loadFileAssociations( projectFolder );
}
bool AppConfig::isNewVersion() const {
return windowState.lastRunVersion != ecode::Version::getVersionNum();
}
void AppConfig::loadFileAssociations( const std::string& projectFolder ) {
std::string faPath( projectFolder + ".ecode/settings.json" );
if ( !FileSystem::fileExists( faPath ) ) {
faPath = projectFolder + ".vscode/settings.json";
if ( !FileSystem::fileExists( faPath ) )
return;
}
std::string data;
if ( !FileSystem::fileGet( faPath, data ) )
return;
json j;
try {
j = json::parse( data, nullptr, true, true );
} catch ( const json::exception& e ) {
Log::error( "AppConfig::loadFileAssociations - Error parsing config from "
"path %s, error: %s, config file content:\n%s",
faPath, e.what(), data );
return;
}
if ( j.contains( "files.associations" ) && j["files.associations"].is_object() ) {
const auto& associations = j["files.associations"];
SyntaxDefinitionManager::FileAssociations fa;
for ( const auto& item : associations.items() ) {
const std::string& key = item.key();
const json& val = item.value();
if ( val.is_string() ) {
fa[key] = val;
} else {
Log::warning( "AppConfig::loadFileAssociations - Skipping key '%s' because its "
"value is not a string.",
key );
}
}
SyntaxDefinitionManager::instance()->setFileAssociations( std::move( fa ) );
}
}
} // namespace ecode