From e0212ba02b6eca5f70cf197b6936f2cfcf1057c7 Mon Sep 17 00:00:00 2001 From: Corey Johnson Date: Wed, 20 Feb 2013 12:38:49 -0800 Subject: [PATCH] Only use the first line when determine the syntax via file contents --- spec/app/syntax-spec.coffee | 4 ++++ src/app/syntax.coffee | 4 +++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/spec/app/syntax-spec.coffee b/spec/app/syntax-spec.coffee index 9660fcecb..b532decef 100644 --- a/spec/app/syntax-spec.coffee +++ b/spec/app/syntax-spec.coffee @@ -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" + 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) diff --git a/src/app/syntax.coffee b/src/app/syntax.coffee index 1488ddf67..ab61bf122 100644 --- a/src/app/syntax.coffee +++ b/src/app/syntax.coffee @@ -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]