-
Notifications
You must be signed in to change notification settings - Fork 7.6k
Getting mode from file extension won't always work #2923
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. |
@peterflynn no bug, if you look at the Mode constructor, it assumes to add a '$' to the expression:
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:
|
@MarkMurphy: this is definitely about to become a lot more declarative -- see pull request #2844, in particular LanguageManager.js and the languages.json file that feeds into it. 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). |
@peterflynn that makes sense. |
Cool. Well, feel free to make a branch off of #2844's and start playing with an implementation of this if you're interested :-) |
@peterflynn Sure, I should be able to have something done soon. |
Fixing issue #2923 - Getting mode from file extension won't always work
@MarkMurphy Can you verify this as working? |
@DennisKehrig Confirmed. Tested by creating an extension-less file named "Cakefile" in a project which Brackets successfully interpreted as a CoffeeScript file. |
@MarkMurphy Woohoo, thanks! Then I'll go ahead and close this one :) |
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: