mirror of
https://github.com/atom/atom.git
synced 2026-02-04 11:45:16 -05:00
Test firstLineRegex first when finding grammar
This is required for the property-list bundle to highlight .plist files that maybe in XML or non-XML formats. Also specify the cached buffer disk contents to grammarForFilePath so fs.read doesn't need to be called again if the contents are already read.
This commit is contained in:
@@ -48,10 +48,12 @@ class LanguageMode
|
||||
false
|
||||
|
||||
reloadGrammar: ->
|
||||
path = @buffer.getPath()
|
||||
pathContents = @buffer.cachedDiskContents
|
||||
if @buffer.project?
|
||||
@grammar = @buffer.project.grammarForFilePath(@buffer.getPath())
|
||||
@grammar = @buffer.project.grammarForFilePath(path, pathContents)
|
||||
else
|
||||
@grammar = syntax.grammarForFilePath(@buffer.getPath())
|
||||
@grammar = syntax.grammarForFilePath(path, pathContents)
|
||||
|
||||
isQuote: (string) ->
|
||||
/'|"/.test(string)
|
||||
|
||||
@@ -45,8 +45,8 @@ class Project
|
||||
grammarOverrideForPath: (path) ->
|
||||
syntax.grammarForScopeName(@grammarOverridesByPath[path])
|
||||
|
||||
grammarForFilePath: (path) ->
|
||||
@grammarOverrideForPath(path) or syntax.grammarForFilePath(path)
|
||||
grammarForFilePath: (path, contents) ->
|
||||
@grammarOverrideForPath(path) or syntax.grammarForFilePath(path, contents)
|
||||
|
||||
getPath: ->
|
||||
@rootDirectory?.path
|
||||
|
||||
@@ -20,15 +20,15 @@ class Syntax
|
||||
@grammarsByFileType[fileType] = grammar
|
||||
@grammarsByScopeName[grammar.scopeName] = grammar
|
||||
|
||||
grammarForFilePath: (filePath) ->
|
||||
grammarForFilePath: (filePath, fileContents) ->
|
||||
return @grammarsByFileType["txt"] unless filePath
|
||||
|
||||
extension = fs.extension(filePath)?[1..]
|
||||
if filePath and extension.length == 0
|
||||
extension = fs.base(filePath)
|
||||
|
||||
@grammarsByFileType[extension] or
|
||||
@grammarByFirstLineRegex(filePath) or
|
||||
@grammarByFirstLineRegex(filePath, fileContents) or
|
||||
@grammarsByFileType[extension] or
|
||||
@grammarByFileTypeSuffix(filePath) or
|
||||
@grammarsByFileType["txt"]
|
||||
|
||||
@@ -36,9 +36,9 @@ class Syntax
|
||||
for fileType, grammar of @grammarsByFileType
|
||||
return grammar if _.endsWith(filePath, fileType)
|
||||
|
||||
grammarByFirstLineRegex: (filePath) ->
|
||||
grammarByFirstLineRegex: (filePath, fileContents) ->
|
||||
try
|
||||
fileContents = fs.read(filePath)
|
||||
fileContents = fs.read(filePath) unless fileContents?
|
||||
catch e
|
||||
null
|
||||
|
||||
|
||||
Reference in New Issue
Block a user