Replace atom.syntax with atom.grammars

This commit is contained in:
Nathan Sobo
2014-11-20 11:42:49 -07:00
parent 131522f93d
commit d53d01d95b
12 changed files with 82 additions and 78 deletions

View File

@@ -131,8 +131,8 @@ class Atom extends Model
# Public: A {Project} instance
project: null
# Public: A {Syntax} instance
syntax: null
# Public: A {GrammarRegistry} instance
grammars: null
# Public: A {PackageManager} instance
packages: null
@@ -241,7 +241,11 @@ class Atom extends Model
@menu = new MenuManager({resourcePath})
@clipboard = new Clipboard()
@syntax = @deserializers.deserialize(@state.syntax) ? new GrammarRegistry()
@grammars = @deserializers.deserialize(@state.grammars ? @state.syntax) ? new GrammarRegistry()
Object.defineProperty this, 'syntax', get: ->
deprecate "The atom.syntax global is deprecated. Use atom.grammars instead."
@grammars
@subscribe @packages.onDidActivateAll => @watchThemes()
@@ -554,7 +558,7 @@ class Atom extends Model
unloadEditorWindow: ->
return if not @project and not @workspaceView
@state.syntax = @syntax.serialize()
@state.grammars = @grammars.serialize()
@state.project = @project.serialize()
@state.workspace = @workspace.serialize()
@packages.deactivatePackages()

View File

@@ -12,7 +12,7 @@ Token = require './token'
# Extended: Syntax class holding the grammars used for tokenizing.
#
# An instance of this class is always available as the `atom.syntax` global.
# An instance of this class is always available as the `atom.grammars` global.
#
# The Syntax class also contains properties for things such as the
# language-specific comment regexes. See {::getProperty} for more details.

View File

@@ -254,7 +254,7 @@ class Package
grammarPaths = fs.listSync(grammarsDirPath, ['json', 'cson'])
for grammarPath in grammarPaths
try
grammar = atom.syntax.readGrammarSync(grammarPath)
grammar = atom.grammars.readGrammarSync(grammarPath)
grammar.packageName = @name
@grammars.push(grammar)
grammar.activate()
@@ -268,7 +268,7 @@ class Package
return Q() if @grammarsLoaded
loadGrammar = (grammarPath, callback) =>
atom.syntax.readGrammar grammarPath, (error, grammar) =>
atom.grammars.readGrammar grammarPath, (error, grammar) =>
if error?
console.warn("Failed to load grammar: #{grammarPath}", error.stack ? error)
else

View File

@@ -26,8 +26,8 @@ class TokenizedBuffer extends Model
constructor: ({@buffer, @tabLength, @invisibles}) ->
@emitter = new Emitter
@subscribe atom.syntax.onDidAddGrammar(@grammarAddedOrUpdated)
@subscribe atom.syntax.onDidUpdateGrammar(@grammarAddedOrUpdated)
@subscribe atom.grammars.onDidAddGrammar(@grammarAddedOrUpdated)
@subscribe atom.grammars.onDidUpdateGrammar(@grammarAddedOrUpdated)
@subscribe @buffer.preemptDidChange (e) => @handleBufferChange(e)
@subscribe @buffer.onDidChangePath (@bufferPath) => @reloadGrammar()
@@ -98,7 +98,7 @@ class TokenizedBuffer extends Model
@emitter.emit 'did-change-grammar', grammar
reloadGrammar: ->
if grammar = atom.syntax.selectGrammar(@buffer.getPath(), @buffer.getText())
if grammar = atom.grammars.selectGrammar(@buffer.getPath(), @buffer.getText())
@setGrammar(grammar)
else
throw new Error("No grammar found for path: #{path}")

View File

@@ -105,13 +105,13 @@ class Workspace extends Model
packageNames.push(packageName)
for scopeName in includedGrammarScopes ? []
addGrammar(atom.syntax.grammarForScopeName(scopeName))
addGrammar(atom.grammars.grammarForScopeName(scopeName))
editors = @getTextEditors()
addGrammar(editor.getGrammar()) for editor in editors
if editors.length > 0
for grammar in atom.syntax.getGrammars() when grammar.injectionSelector
for grammar in atom.grammars.getGrammars() when grammar.injectionSelector
addGrammar(grammar)
_.uniq(packageNames)