mirror of
https://github.com/atom/atom.git
synced 2026-02-10 14:45:11 -05:00
Move grammar overrides to syntax (no serialization yet)
This commit is contained in:
committed by
Nathan Sobo
parent
dacb00ed67
commit
db4420e068
@@ -48,9 +48,9 @@ class GrammarView extends SelectList
|
||||
confirmed: (grammar) ->
|
||||
@cancel()
|
||||
if grammar is @autoDetect
|
||||
project.removeGrammarOverrideForPath(@path)
|
||||
syntax.clearGrammarOverrideForPath(@path)
|
||||
else
|
||||
project.addGrammarOverrideForPath(@path, grammar)
|
||||
syntax.setGrammarOverrideForPath(@path, grammar.scopeName)
|
||||
@editor.reloadGrammar()
|
||||
|
||||
attach: ->
|
||||
|
||||
@@ -17,10 +17,7 @@ class LanguageMode
|
||||
path = @buffer.getPath()
|
||||
pathContents = @buffer.cachedDiskContents
|
||||
previousGrammar = @grammar
|
||||
if @buffer.project?
|
||||
@grammar = @buffer.project.selectGrammar(path, pathContents)
|
||||
else
|
||||
@grammar = syntax.selectGrammar(path, pathContents)
|
||||
@grammar = syntax.selectGrammar(path, pathContents)
|
||||
throw new Error("No grammar found for path: #{path}") unless @grammar
|
||||
previousGrammar isnt @grammar
|
||||
|
||||
|
||||
@@ -13,7 +13,7 @@ class Project
|
||||
registerDeserializer(this)
|
||||
|
||||
@deserialize: (state) ->
|
||||
new Project(state.path, state.grammarOverridesByPath)
|
||||
new Project(state.path)
|
||||
|
||||
tabLength: 2
|
||||
softTabs: true
|
||||
@@ -21,9 +21,8 @@ class Project
|
||||
rootDirectory: null
|
||||
editSessions: null
|
||||
ignoredPathRegexes: null
|
||||
grammarOverridesByPath: null
|
||||
|
||||
constructor: (path, @grammarOverridesByPath={}) ->
|
||||
constructor: (path) ->
|
||||
@setPath(path)
|
||||
@editSessions = []
|
||||
@buffers = []
|
||||
@@ -31,23 +30,10 @@ class Project
|
||||
serialize: ->
|
||||
deserializer: 'Project'
|
||||
path: @getPath()
|
||||
grammarOverridesByPath: @grammarOverridesByPath
|
||||
|
||||
destroy: ->
|
||||
editSession.destroy() for editSession in @getEditSessions()
|
||||
|
||||
addGrammarOverrideForPath: (path, grammar) ->
|
||||
@grammarOverridesByPath[path] = grammar.scopeName
|
||||
|
||||
removeGrammarOverrideForPath: (path) ->
|
||||
delete @grammarOverridesByPath[path]
|
||||
|
||||
grammarOverrideForPath: (path) ->
|
||||
syntax.grammarForScopeName(@grammarOverridesByPath[path])
|
||||
|
||||
selectGrammar: (path, contents) ->
|
||||
@grammarOverrideForPath(path) or syntax.selectGrammar(path, contents)
|
||||
|
||||
getPath: ->
|
||||
@rootDirectory?.path
|
||||
|
||||
|
||||
@@ -14,6 +14,7 @@ class Syntax
|
||||
@grammars = []
|
||||
@grammarsByFileType = {}
|
||||
@grammarsByScopeName = {}
|
||||
@grammarOverridesByPath = {}
|
||||
@globalProperties = {}
|
||||
@scopedPropertiesIndex = 0
|
||||
@scopedProperties = []
|
||||
@@ -25,13 +26,26 @@ class Syntax
|
||||
@grammarsByFileType[fileType] = grammar
|
||||
@grammarsByScopeName[grammar.scopeName] = grammar
|
||||
|
||||
setGrammarOverrideForPath: (path, scopeName) ->
|
||||
@grammarOverridesByPath[path] = scopeName
|
||||
|
||||
clearGrammarOverrideForPath: (path) ->
|
||||
delete @grammarOverridesByPath[path]
|
||||
|
||||
clearGrammarOverrides: ->
|
||||
@grammarOverridesByPath = {}
|
||||
|
||||
selectGrammar: (filePath, fileContents) ->
|
||||
return @grammarsByFileType["txt"] ? @nullGrammar unless filePath
|
||||
@grammarByFirstLineRegex(filePath, fileContents) ?
|
||||
@grammarOverrideForPath(filePath) ?
|
||||
@grammarByFirstLineRegex(filePath, fileContents) ?
|
||||
@grammarByPath(filePath) ?
|
||||
@grammarsByFileType["txt"] ?
|
||||
@nullGrammar
|
||||
|
||||
grammarOverrideForPath: (path) ->
|
||||
@grammarsByScopeName[@grammarOverridesByPath[path]]
|
||||
|
||||
grammarByPath: (path) ->
|
||||
pathComponents = path.split(pathSplitRegex)
|
||||
for fileType, grammar of @grammarsByFileType
|
||||
|
||||
Reference in New Issue
Block a user