Store grammar overrides on project

This commit is contained in:
Corey Johnson & Kevin Sawicki
2013-01-08 14:39:32 -08:00
parent fee1e7bc8b
commit c67fbef2b2
6 changed files with 21 additions and 17 deletions

View File

@@ -42,9 +42,9 @@ class GrammarView extends SelectList
confirmed: (grammar) ->
@cancel()
if grammar is @autoDetect
syntax.removeGrammarForPath(@path)
rootView.project.removeGrammarOverrideForPath(@path)
else
syntax.addGrammarForPath(@path, grammar)
rootView.project.addGrammarOverrideForPath(@path, grammar)
@editor.reloadGrammar()
attach: ->

View File

@@ -48,7 +48,7 @@ class LanguageMode
false
reloadGrammar: ->
@grammar = syntax.grammarForFilePath(@buffer.getPath())
@grammar = rootView.project.grammarForFilePath(@buffer.getPath())
isQuote: (string) ->
/'|"/.test(string)

View File

@@ -18,6 +18,7 @@ class Project
rootDirectory: null
editSessions: null
ignoredPathRegexes: null
grammarOverridesByPath: {}
constructor: (path) ->
@setPath(path)
@@ -27,6 +28,16 @@ class Project
destroy: ->
editSession.destroy() for editSession in @getEditSessions()
addGrammarOverrideForPath: (path, grammar) ->
@grammarOverridesByPath[path] = grammar.scopeName
removeGrammarOverrideForPath: (path) ->
delete @grammarOverridesByPath[path]
grammarForFilePath: (path) ->
grammar = syntax.grammarForScopeName(@grammarOverridesByPath[path]) if path
grammar or syntax.grammarForFilePath(path)
getPath: ->
@rootDirectory?.path

View File

@@ -8,7 +8,6 @@ module.exports =
class Syntax
constructor: ->
@grammars = []
@grammarsByPath = {}
@grammarsByFileType = {}
@grammarsByScopeName = {}
@globalProperties = {}
@@ -21,12 +20,6 @@ class Syntax
@grammarsByFileType[fileType] = grammar
@grammarsByScopeName[grammar.scopeName] = grammar
addGrammarForPath: (path, grammar) ->
@grammarsByPath[path] = grammar
removeGrammarForPath: (path) ->
delete @grammarsByPath[path]
grammarForFilePath: (filePath) ->
return @grammarsByFileType["txt"] unless filePath
@@ -34,8 +27,7 @@ class Syntax
if filePath and extension.length == 0
extension = fs.base(filePath)
@grammarsByPath[filePath] or
@grammarsByFileType[extension] or
@grammarsByFileType[extension] or
@grammarByShebang(filePath) or
@grammarByFileTypeSuffix(filePath) or
@grammarsByFileType["txt"]