mirror of
https://github.com/atom/atom.git
synced 2026-01-23 13:58:08 -05:00
Only use the first line when determine the syntax via file contents
This commit is contained in:
@@ -12,6 +12,10 @@ describe "the `syntax` global", ->
|
||||
filePath = require.resolve("fixtures/shebang")
|
||||
expect(syntax.grammarForFilePath(filePath).name).toBe "Ruby"
|
||||
|
||||
it "only use the first line to determine the syntax", ->
|
||||
fileContent = "first-line\n<html>"
|
||||
expect(syntax.grammarForFilePath("dummy.coffee", fileContent).name).toBe "CoffeeScript"
|
||||
|
||||
it "doesn't read the file when the file contents are specified", ->
|
||||
filePath = require.resolve("fixtures/shebang")
|
||||
filePathContents = fs.read(filePath)
|
||||
|
||||
@@ -43,7 +43,9 @@ class Syntax
|
||||
catch e
|
||||
null
|
||||
|
||||
_.find @grammars, (grammar) -> grammar.firstLineRegex?.test(fileContents)
|
||||
if fileContents
|
||||
firstLine = fileContents.match(/^.*$/m)
|
||||
_.find @grammars, (grammar) -> grammar.firstLineRegex?.test(firstLine)
|
||||
|
||||
grammarForScopeName: (scopeName) ->
|
||||
@grammarsByScopeName[scopeName]
|
||||
|
||||
Reference in New Issue
Block a user