how to set allowed_extensions?
Hi, Great project.
Can you tell us how to sepcify allowed_extensions in a flask app?
Currently this is not possible filter file types but this feature is in backlog and will be added in future development.
Looking forward to this new release. I need to edit files with 'conf' type extensions.
How to get rid of "This file type is not allowed to open..."
I digged into the source code and just found out a function called flaskcode.validResource() into file flaskcode.js,
It's the core of file type validation.
This function try to find a syntax handler. If it can't, just raise the error. But it would be a lot more easy if it just handle it as plain/text ascii.
flaskcode.validResource = function (filename) {
var ext = flaskcode.getExt(filename);
var lang = ext ? flaskcode.getLanguageByExtension(ext) : null;
return lang ? flaskcode.allowedLangIds.indexOf(lang.id) > -1 : false;
};
You can see at line #18 the default handler!
flaskcode.languages = [];
flaskcode.defaultExt = 'txt';
flaskcode.defaultLangId = 'plaintext';
flaskcode.defaultLang = null;
flaskcode.fallbackLang = null;
The return of flaskcode.getLanguageByExtension(ext) is something like this:
{
"id": "python",
"extensions": [
".py",
".rpy",
".pyw",
".cpy",
".gyp",
".gypi"
],
"aliases": [
"Python",
"py"
],
"firstLine": "^#!/.*\\bpython[0-9.-]*\\b"
}
This is my validResource() version:
⭐⭐ ⭐ ⭐ ⭐
flaskcode.validResource = function (filename) {
var ext = flaskcode.getExt(filename);
var lang = ext ? flaskcode.getLanguageByExtension(ext) : null;
/* fallback to plaintext */
if(!lang){ /* if not found try text file */
lang = flaskcode.getLanguageByExtension('txt')
//alert(JSON.stringify(lang, null, 4));
if(lang){ /* Just to be sure! */
if(ext) /* add ext to array */
lang.extensions.push("."+ext);
/* return the struct */
return lang
}
}
return lang ? flaskcode.allowedLangIds.indexOf(lang.id) > -1 : false;
};
💡💡💡 Also a good trick would be ignore all '.git' and '.env' folder! It can slow down the editor! 💡💡💡
💣💣 💣 Be carefull! If you try to open a binary file, things can get messy! 💣💣 💣