From 08a27cf93d9edf5ff43d6ac969794934d62d901d Mon Sep 17 00:00:00 2001 From: Nathan Sobo Date: Mon, 31 Dec 2012 18:28:38 -0600 Subject: [PATCH] Load grammars from `TextMatePackage`. Delete `TextMateBundle`. TextMatePackage is only designed to load resources out of a TextMate bundle. It's used only at load time, and from that point out we only refer to our own global `syntax` data structure to access the data that it loads. --- benchmark/benchmark-helper.coffee | 2 -- benchmark/benchmark-suite.coffee | 1 - spec/app/edit-session-spec.coffee | 1 - spec/app/text-mate-bundle-spec.coffee | 11 ----------- spec/spec-helper.coffee | 2 -- src/app/atom-package.coffee | 4 ++-- src/app/atom.coffee | 1 - src/app/language-mode.coffee | 1 - src/app/package.coffee | 3 +++ src/app/text-mate-bundle.coffee | 7 ------- src/app/text-mate-package.coffee | 20 +++++++++++++------- src/app/window.coffee | 2 -- 12 files changed, 18 insertions(+), 37 deletions(-) delete mode 100644 spec/app/text-mate-bundle-spec.coffee diff --git a/benchmark/benchmark-helper.coffee b/benchmark/benchmark-helper.coffee index 663ebd344..49b82d2ed 100644 --- a/benchmark/benchmark-helper.coffee +++ b/benchmark/benchmark-helper.coffee @@ -5,8 +5,6 @@ Keymap = require 'keymap' Point = require 'point' Config = require 'config' Project = require 'project' -TextMateBundle = require 'text-mate-bundle' -TextMateTheme = require 'text-mate-theme' require 'window' requireStylesheet "jasmine.css" diff --git a/benchmark/benchmark-suite.coffee b/benchmark/benchmark-suite.coffee index 46af80571..1f784071b 100644 --- a/benchmark/benchmark-suite.coffee +++ b/benchmark/benchmark-suite.coffee @@ -3,7 +3,6 @@ fs = require 'fs' $ = require 'jquery' _ = require 'underscore' TokenizedBuffer = require 'tokenized-buffer' -TextMateBundle = require 'text-mate-bundle' describe "editor.", -> editor = null diff --git a/spec/app/edit-session-spec.coffee b/spec/app/edit-session-spec.coffee index 62b301381..cf8888ffd 100644 --- a/spec/app/edit-session-spec.coffee +++ b/spec/app/edit-session-spec.coffee @@ -1,7 +1,6 @@ Project = require 'project' Buffer = require 'buffer' EditSession = require 'edit-session' -TextMateBundle = require 'text-mate-bundle' describe "EditSession", -> [buffer, editSession, lineLengths] = [] diff --git a/spec/app/text-mate-bundle-spec.coffee b/spec/app/text-mate-bundle-spec.coffee deleted file mode 100644 index f2d89e882..000000000 --- a/spec/app/text-mate-bundle-spec.coffee +++ /dev/null @@ -1,11 +0,0 @@ -fs = require('fs') -TextMateBundle = require 'text-mate-bundle' - -describe "TextMateBundle", -> - describe ".constructor(bundlePath)", -> - it "logs warning, but does not raise errors if a grammar can't be parsed", -> - bundlePath = fs.join(require.resolve('fixtures'), "test.tmbundle") - spyOn(console, 'warn') - expect(-> new TextMateBundle(bundlePath)).not.toThrow() - expect(console.warn).toHaveBeenCalled() - diff --git a/spec/spec-helper.coffee b/spec/spec-helper.coffee index 5de43bccc..c31695dfe 100644 --- a/spec/spec-helper.coffee +++ b/spec/spec-helper.coffee @@ -9,8 +9,6 @@ Directory = require 'directory' File = require 'file' RootView = require 'root-view' Editor = require 'editor' -TextMateBundle = require 'text-mate-bundle' -TextMateTheme = require 'text-mate-theme' TokenizedBuffer = require 'tokenized-buffer' fs = require 'fs' require 'window' diff --git a/src/app/atom-package.coffee b/src/app/atom-package.coffee index 11d322461..e8a8b262b 100644 --- a/src/app/atom-package.coffee +++ b/src/app/atom-package.coffee @@ -3,7 +3,7 @@ fs = require 'fs' module.exports = class AtomPackage extends Package - constructor: -> + constructor: (@name) -> super @module = require(@path) @module.name = @name @@ -14,4 +14,4 @@ class AtomPackage extends Package extensionKeymapPath = require.resolve(fs.join(@name, "src/keymap"), verifyExistence: false) require extensionKeymapPath if fs.exists(extensionKeymapPath) catch e - console.error "Failed to load package named '#{name}'", e.stack + console.error "Failed to load package named '#{@name}'", e.stack diff --git a/src/app/atom.coffee b/src/app/atom.coffee index 928271c89..a90b675b3 100644 --- a/src/app/atom.coffee +++ b/src/app/atom.coffee @@ -1,4 +1,3 @@ -TextMateBundle = require("text-mate-bundle") fs = require 'fs' _ = require 'underscore' Package = require 'package' diff --git a/src/app/language-mode.coffee b/src/app/language-mode.coffee index 023208bec..37dcd98e7 100644 --- a/src/app/language-mode.coffee +++ b/src/app/language-mode.coffee @@ -1,5 +1,4 @@ Range = require 'range' -TextMateBundle = require 'text-mate-bundle' _ = require 'underscore' require 'underscore-extensions' diff --git a/src/app/package.coffee b/src/app/package.coffee index cac85ba42..47e99039b 100644 --- a/src/app/package.coffee +++ b/src/app/package.coffee @@ -17,5 +17,8 @@ class Package @path = fs.directory(@path) unless fs.isDirectory(@path) load: -> + for grammar in @getGrammars() + syntax.addGrammar(grammar) + for { selector, properties } in @getScopedProperties() syntax.addProperties(selector, properties) diff --git a/src/app/text-mate-bundle.coffee b/src/app/text-mate-bundle.coffee index 7baf505f5..3d6067784 100644 --- a/src/app/text-mate-bundle.coffee +++ b/src/app/text-mate-bundle.coffee @@ -19,13 +19,6 @@ class TextMateBundle grammars: null constructor: (@path) -> - @grammars = [] - if fs.exists(@getSyntaxesPath()) - for syntaxPath in fs.list(@getSyntaxesPath()) - try - @grammars.push TextMateGrammar.loadFromPath(syntaxPath) - catch e - console.warn "Failed to load grammar at path '#{syntaxPath}'", e getSyntaxesPath: -> fs.join(@path, "Syntaxes") diff --git a/src/app/text-mate-package.coffee b/src/app/text-mate-package.coffee index 48feae536..4e2ce8598 100644 --- a/src/app/text-mate-package.coffee +++ b/src/app/text-mate-package.coffee @@ -1,8 +1,8 @@ Package = require 'package' -TextMateBundle = require 'text-mate-bundle' fs = require 'fs' plist = require 'plist' _ = require 'underscore' +TextMateGrammar = require 'text-mate-grammar' module.exports = class TextMatePackage extends Package @@ -18,20 +18,26 @@ class TextMatePackage extends Package ).join(' ') ).join(', ') - load: -> - @bundle = TextMateBundle.load(@name) - @grammars = @bundle.grammars - super - constructor: -> super @preferencesPath = fs.join(@path, "Preferences") @syntaxesPath = fs.join(@path, "Syntaxes") + getGrammars: -> + return @grammars if @grammars + @grammars = [] + if fs.exists(@syntaxesPath) + for grammarPath in fs.list(@syntaxesPath) + try + @grammars.push TextMateGrammar.loadFromPath(grammarPath) + catch e + console.warn "Failed to load grammar at path '#{grammarPath}'", e.stack + @grammars + getScopedProperties: -> scopedProperties = [] - for grammar in @grammars + for grammar in @getGrammars() if properties = @propertiesFromTextMateSettings(grammar) selector = @cssSelectorFromScopeSelector(grammar.scopeName) scopedProperties.push({selector, properties}) diff --git a/src/app/window.coffee b/src/app/window.coffee index 5eccba916..d888f031a 100644 --- a/src/app/window.coffee +++ b/src/app/window.coffee @@ -2,8 +2,6 @@ # the DOM window. Native = require 'native' -TextMateBundle = require 'text-mate-bundle' -TextMateTheme = require 'text-mate-theme' fs = require 'fs' _ = require 'underscore' $ = require 'jquery'