mirror of
https://github.com/atom/atom.git
synced 2026-04-06 03:02:13 -04:00
Support grammar fileTypes that contains more than extensions
The Git bundle registers fileTypes with multiple path segments such as '.git/config'
This commit is contained in:
@@ -36,6 +36,9 @@ describe "TextMateBundle", ->
|
||||
filePath = require.resolve("fixtures/shebang")
|
||||
expect(TextMateBundle.grammarForFilePath(filePath).name).toBe "Ruby"
|
||||
|
||||
it "uses the grammar's fileType as a suffix of the full filePath if the grammar cannot be determined by shebang line", ->
|
||||
expect(TextMateBundle.grammarForFilePath("/tmp/.git/config").name).toBe "Git Config"
|
||||
|
||||
it "uses plain text if no grammar can be found", ->
|
||||
filePath = require.resolve("this-is-not-a-real-file")
|
||||
expect(TextMateBundle.grammarForFilePath(filePath).name).toBe "Plain Text"
|
||||
|
||||
@@ -36,11 +36,17 @@ class TextMateBundle
|
||||
@grammarsByScopeName[grammar.scopeName] = grammar
|
||||
|
||||
@grammarForFilePath: (filePath) ->
|
||||
return @grammarsByFileType["txt"] unless filePath
|
||||
|
||||
extension = fs.extension(filePath)?[1...]
|
||||
if filePath and extension.length == 0
|
||||
extension = fs.base(filePath)
|
||||
|
||||
@grammarsByFileType[extension] or @grammarByShebang(filePath) or @grammarsByFileType["txt"]
|
||||
@grammarsByFileType[extension] or @grammarByShebang(filePath) or @grammarByFileTypeSuffix(filePath) or @grammarsByFileType["txt"]
|
||||
|
||||
@grammarByFileTypeSuffix: (filePath) ->
|
||||
for fileType, grammar of @grammarsByFileType
|
||||
return grammar if _.endsWith(filePath, fileType)
|
||||
|
||||
@grammarByShebang: (filePath) ->
|
||||
try
|
||||
|
||||
@@ -82,3 +82,6 @@ _.mixin
|
||||
|
||||
@pendingNextTickFns.push(fn)
|
||||
@messageChannel.port2.postMessage(0)
|
||||
|
||||
endsWith: (string, suffix) ->
|
||||
string.indexOf(suffix, string.length - suffix.length) isnt -1
|
||||
|
||||
Reference in New Issue
Block a user