mirror of
https://github.com/atom/atom.git
synced 2026-04-28 03:01:47 -04:00
Store grammar overrides on project
This commit is contained in:
@@ -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: ->
|
||||
|
||||
@@ -48,7 +48,7 @@ class LanguageMode
|
||||
false
|
||||
|
||||
reloadGrammar: ->
|
||||
@grammar = syntax.grammarForFilePath(@buffer.getPath())
|
||||
@grammar = rootView.project.grammarForFilePath(@buffer.getPath())
|
||||
|
||||
isQuote: (string) ->
|
||||
/'|"/.test(string)
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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"]
|
||||
|
||||
Reference in New Issue
Block a user