-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[CLOSED] Getting mode from file extension won't always work #2762
Comments
Hi Mark, |
Are there cases where you'd need a full-blown regexp? Or would a list of extensionless filenames suffice? Something like this:
I'd worry a little bit that regexps make it too easy to create bugs where language extensions match an overly-broad set of filenames. (I think your example above actually contains such a bug :-) -- there's no "^" before the last item, so any filename containing the contiguous substring "make" would get matched). Regexps also make it impractical to detect clashing extensions, whereas with simple lists we can automatically detect & warn when two language extensions are fighting over the same file. |
In this case the regexps are so simplistic that there's really no reason to worry about using them for this. Performance wise, it wouldn't be any faster that the current implementation of using the switch + whatever time ti takes to evaluate against each regex. What I do like about about this approach is that it makes it much easier for me to quickly see what extension is associated to what language/mode. Another approach I was considering was to create a key/value pair object where the keys would be extensions and extension-less file names and the value would be an object containing the mode name, options, mime, etc. Here's an example:
|
Sorry about the "bug" confusion -- I didn't realize that you were preprocessing the "match" string and not using it as a literal regexp directly. I think my concerns there remain, though... I'd prefer if we could do this via a simple list of filenames, similar to your last proposal above. (Except that I think we should keep it separate from the list of extensions -- otherwise an extensionless file whose name matches any file extension would get mapped to that mode automatically, which seems wrong). |
|
Cool. Well, feel free to make a branch off of #2844's and start playing with an implementation of this if you're interested :-) |
|
|
|
|
Thursday Feb 21, 2013 at 04:31 GMT
Originally opened as adobe/brackets#2923
Getting mode from file extension won't always work where some files don't have extensions like Makefiles for example.
Instead I propose that the getModeFromFileExtension method be refactored to getModeFromFilePath where the filename including the extension can be compared to a regex representing each mode.
for example:
The text was updated successfully, but these errors were encountered: