diff --git a/spec/atom-spec.coffee b/spec/atom-spec.coffee index a0b8ff458..82795d3b9 100644 --- a/spec/atom-spec.coffee +++ b/spec/atom-spec.coffee @@ -240,24 +240,24 @@ describe "the `atom` global", -> describe "grammar loading", -> it "loads the package's grammars", -> atom.activatePackage('package-with-grammars') - expect(syntax.selectGrammar('a.alot').name).toBe 'Alot' - expect(syntax.selectGrammar('a.alittle').name).toBe 'Alittle' + expect(atom.syntax.selectGrammar('a.alot').name).toBe 'Alot' + expect(atom.syntax.selectGrammar('a.alittle').name).toBe 'Alittle' describe "scoped-property loading", -> it "loads the scoped properties", -> atom.activatePackage("package-with-scoped-properties") - expect(syntax.getProperty ['.source.omg'], 'editor.increaseIndentPattern').toBe '^a' + expect(atom.syntax.getProperty ['.source.omg'], 'editor.increaseIndentPattern').toBe '^a' describe "textmate packages", -> it "loads the package's grammars", -> - expect(syntax.selectGrammar("file.rb").name).toBe "Null Grammar" + expect(atom.syntax.selectGrammar("file.rb").name).toBe "Null Grammar" atom.activatePackage('language-ruby', sync: true) - expect(syntax.selectGrammar("file.rb").name).toBe "Ruby" + expect(atom.syntax.selectGrammar("file.rb").name).toBe "Ruby" it "translates the package's scoped properties to Atom terms", -> - expect(syntax.getProperty(['.source.ruby'], 'editor.commentStart')).toBeUndefined() + expect(atom.syntax.getProperty(['.source.ruby'], 'editor.commentStart')).toBeUndefined() atom.activatePackage('language-ruby', sync: true) - expect(syntax.getProperty(['.source.ruby'], 'editor.commentStart')).toBe '# ' + expect(atom.syntax.getProperty(['.source.ruby'], 'editor.commentStart')).toBe '# ' describe "when the package has no grammars but does have preferences", -> it "loads the package's preferences as scoped properties", -> @@ -267,9 +267,9 @@ describe "the `atom` global", -> atom.activatePackage('package-with-preferences-tmbundle') waitsFor -> - syntax.addProperties.callCount > 0 + atom.syntax.addProperties.callCount > 0 runs -> - expect(syntax.getProperty(['.source.pref'], 'editor.increaseIndentPattern')).toBe '^abc$' + expect(atom.syntax.getProperty(['.source.pref'], 'editor.increaseIndentPattern')).toBe '^abc$' describe ".deactivatePackage(id)", -> describe "atom packages", -> @@ -311,8 +311,8 @@ describe "the `atom` global", -> it "removes the package's grammars", -> atom.activatePackage('package-with-grammars') atom.deactivatePackage('package-with-grammars') - expect(syntax.selectGrammar('a.alot').name).toBe 'Null Grammar' - expect(syntax.selectGrammar('a.alittle').name).toBe 'Null Grammar' + expect(atom.syntax.selectGrammar('a.alot').name).toBe 'Null Grammar' + expect(atom.syntax.selectGrammar('a.alittle').name).toBe 'Null Grammar' it "removes the package's keymaps", -> atom.activatePackage('package-with-keymaps') @@ -332,22 +332,22 @@ describe "the `atom` global", -> it "removes the package's scoped-properties", -> atom.activatePackage("package-with-scoped-properties") - expect(syntax.getProperty ['.source.omg'], 'editor.increaseIndentPattern').toBe '^a' + expect(atom.syntax.getProperty ['.source.omg'], 'editor.increaseIndentPattern').toBe '^a' atom.deactivatePackage("package-with-scoped-properties") - expect(syntax.getProperty ['.source.omg'], 'editor.increaseIndentPattern').toBeUndefined() + expect(atom.syntax.getProperty ['.source.omg'], 'editor.increaseIndentPattern').toBeUndefined() describe "textmate packages", -> it "removes the package's grammars", -> - expect(syntax.selectGrammar("file.rb").name).toBe "Null Grammar" + expect(atom.syntax.selectGrammar("file.rb").name).toBe "Null Grammar" atom.activatePackage('language-ruby', sync: true) - expect(syntax.selectGrammar("file.rb").name).toBe "Ruby" + expect(atom.syntax.selectGrammar("file.rb").name).toBe "Ruby" atom.deactivatePackage('language-ruby') - expect(syntax.selectGrammar("file.rb").name).toBe "Null Grammar" + expect(atom.syntax.selectGrammar("file.rb").name).toBe "Null Grammar" it "removes the package's scoped properties", -> atom.activatePackage('language-ruby', sync: true) atom.deactivatePackage('language-ruby') - expect(syntax.getProperty(['.source.ruby'], 'editor.commentStart')).toBeUndefined() + expect(atom.syntax.getProperty(['.source.ruby'], 'editor.commentStart')).toBeUndefined() describe ".activate()", -> packageActivator = null diff --git a/spec/edit-session-spec.coffee b/spec/edit-session-spec.coffee index afb990ddf..03ebbf406 100644 --- a/spec/edit-session-spec.coffee +++ b/spec/edit-session-spec.coffee @@ -2390,14 +2390,14 @@ describe "EditSession", -> describe "when a better-matched grammar is added to syntax", -> it "switches to the better-matched grammar and re-tokenizes the buffer", -> editSession.destroy() - jsGrammar = syntax.selectGrammar('a.js') - syntax.removeGrammar(jsGrammar) + jsGrammar = atom.syntax.selectGrammar('a.js') + atom.syntax.removeGrammar(jsGrammar) editSession = project.openSync('sample.js', autoIndent: false) - expect(editSession.getGrammar()).toBe syntax.nullGrammar + expect(editSession.getGrammar()).toBe atom.syntax.nullGrammar expect(editSession.lineForScreenRow(0).tokens.length).toBe 1 - syntax.addGrammar(jsGrammar) + atom.syntax.addGrammar(jsGrammar) expect(editSession.getGrammar()).toBe jsGrammar expect(editSession.lineForScreenRow(0).tokens.length).toBeGreaterThan 1 diff --git a/spec/editor-spec.coffee b/spec/editor-spec.coffee index 6d2c83fca..35bdea5fa 100644 --- a/spec/editor-spec.coffee +++ b/spec/editor-spec.coffee @@ -1925,7 +1925,7 @@ describe "Editor", -> miniEditor = new Editor(mini: true) miniEditor.setText("var something") previousTokens = miniEditor.lineForScreenRow(0).tokens - miniEditor.setGrammar(syntax.selectGrammar('something.js')) + miniEditor.setGrammar(atom.syntax.selectGrammar('something.js')) expect(miniEditor.getGrammar().name).toBe "JavaScript" expect(previousTokens).not.toEqual miniEditor.lineForScreenRow(0).tokens @@ -2357,7 +2357,7 @@ describe "Editor", -> it "updates all the rendered lines when the grammar changes", -> editor.edit(project.openSync(filePath)) expect(editor.getGrammar().name).toBe 'Plain Text' - syntax.setGrammarOverrideForPath(filePath, 'source.js') + atom.syntax.setGrammarOverrideForPath(filePath, 'source.js') editor.reloadGrammar() expect(editor.getGrammar().name).toBe 'JavaScript' @@ -2383,7 +2383,7 @@ describe "Editor", -> expect(eventHandler).not.toHaveBeenCalled() - syntax.setGrammarOverrideForPath(filePath, 'source.js') + atom.syntax.setGrammarOverrideForPath(filePath, 'source.js') editor.reloadGrammar() expect(eventHandler).toHaveBeenCalled() diff --git a/spec/spec-helper.coffee b/spec/spec-helper.coffee index 9316ebd77..95f6618c9 100644 --- a/spec/spec-helper.coffee +++ b/spec/spec-helper.coffee @@ -126,7 +126,7 @@ afterEach -> delete atom.windowState jasmine.unspy(atom, 'saveWindowState') ensureNoPathSubscriptions() - syntax.off() + atom.syntax.off() waits(0) # yield to ui thread to make screen update more frequently ensureNoPathSubscriptions = -> diff --git a/spec/syntax-spec.coffee b/spec/syntax-spec.coffee index 3bf598dd2..8cc7ed73b 100644 --- a/spec/syntax-spec.coffee +++ b/spec/syntax-spec.coffee @@ -13,52 +13,52 @@ describe "the `syntax` global", -> describe "serialization", -> it "remembers grammar overrides by path", -> filePath = '/foo/bar/file.js' - expect(syntax.selectGrammar(filePath).name).not.toBe 'Ruby' - syntax.setGrammarOverrideForPath(filePath, 'source.ruby') - syntax2 = deserialize(syntax.serialize()) - syntax2.addGrammar(grammar) for grammar in syntax.grammars when grammar isnt syntax.nullGrammar + expect(atom.syntax.selectGrammar(filePath).name).not.toBe 'Ruby' + atom.syntax.setGrammarOverrideForPath(filePath, 'source.ruby') + syntax2 = deserialize(atom.syntax.serialize()) + syntax2.addGrammar(grammar) for grammar in atom.syntax.grammars when grammar isnt atom.syntax.nullGrammar expect(syntax2.selectGrammar(filePath).name).toBe 'Ruby' describe ".selectGrammar(filePath)", -> it "can use the filePath to load the correct grammar based on the grammar's filetype", -> atom.activatePackage('language-git', sync: true) - expect(syntax.selectGrammar("file.js").name).toBe "JavaScript" # based on extension (.js) - expect(syntax.selectGrammar(path.join(temp.dir, '.git', 'config')).name).toBe "Git Config" # based on end of the path (.git/config) - expect(syntax.selectGrammar("Rakefile").name).toBe "Ruby" # based on the file's basename (Rakefile) - expect(syntax.selectGrammar("curb").name).toBe "Null Grammar" - expect(syntax.selectGrammar("/hu.git/config").name).toBe "Null Grammar" + expect(atom.syntax.selectGrammar("file.js").name).toBe "JavaScript" # based on extension (.js) + expect(atom.syntax.selectGrammar(path.join(temp.dir, '.git', 'config')).name).toBe "Git Config" # based on end of the path (.git/config) + expect(atom.syntax.selectGrammar("Rakefile").name).toBe "Ruby" # based on the file's basename (Rakefile) + expect(atom.syntax.selectGrammar("curb").name).toBe "Null Grammar" + expect(atom.syntax.selectGrammar("/hu.git/config").name).toBe "Null Grammar" it "uses the filePath's shebang line if the grammar cannot be determined by the extension or basename", -> filePath = require.resolve("./fixtures/shebang") - expect(syntax.selectGrammar(filePath).name).toBe "Ruby" + expect(atom.syntax.selectGrammar(filePath).name).toBe "Ruby" it "uses the number of newlines in the first line regex to determine the number of lines to test against", -> atom.activatePackage('language-property-list', sync: true) fileContent = "first-line\n" - expect(syntax.selectGrammar("dummy.coffee", fileContent).name).toBe "CoffeeScript" + expect(atom.syntax.selectGrammar("dummy.coffee", fileContent).name).toBe "CoffeeScript" fileContent = '' - expect(syntax.selectGrammar("grammar.tmLanguage", fileContent).name).toBe "Null Grammar" + expect(atom.syntax.selectGrammar("grammar.tmLanguage", fileContent).name).toBe "Null Grammar" fileContent += '\n' - expect(syntax.selectGrammar("grammar.tmLanguage", fileContent).name).toBe "Property List (XML)" + expect(atom.syntax.selectGrammar("grammar.tmLanguage", fileContent).name).toBe "Property List (XML)" it "doesn't read the file when the file contents are specified", -> filePath = require.resolve("./fixtures/shebang") filePathContents = fs.readFileSync(filePath, 'utf8') spyOn(fs, 'read').andCallThrough() - expect(syntax.selectGrammar(filePath, filePathContents).name).toBe "Ruby" + expect(atom.syntax.selectGrammar(filePath, filePathContents).name).toBe "Ruby" expect(fs.read).not.toHaveBeenCalled() it "allows the default grammar to be overridden for a path", -> filePath = '/foo/bar/file.js' - expect(syntax.selectGrammar(filePath).name).not.toBe 'Ruby' - syntax.setGrammarOverrideForPath(filePath, 'source.ruby') - expect(syntax.selectGrammar(filePath).name).toBe 'Ruby' - syntax.clearGrammarOverrideForPath(filePath) - expect(syntax.selectGrammar(filePath).name).not.toBe 'Ruby' + expect(atom.syntax.selectGrammar(filePath).name).not.toBe 'Ruby' + atom.syntax.setGrammarOverrideForPath(filePath, 'source.ruby') + expect(atom.syntax.selectGrammar(filePath).name).toBe 'Ruby' + atom.syntax.clearGrammarOverrideForPath(filePath) + expect(atom.syntax.selectGrammar(filePath).name).not.toBe 'Ruby' describe "when multiple grammars have matching fileTypes", -> it "selects the grammar with the longest fileType match", -> @@ -72,46 +72,46 @@ describe "the `syntax` global", -> scopeName: 'source2' fileTypes: ['test'] - syntax.addGrammar(grammar1) - syntax.addGrammar(grammar2) + atom.syntax.addGrammar(grammar1) + atom.syntax.addGrammar(grammar2) - expect(syntax.selectGrammar('more.test', '')).toBe grammar1 + expect(atom.syntax.selectGrammar('more.test', '')).toBe grammar1 describe "when there is no file path", -> it "does not throw an exception (regression)", -> - expect(-> syntax.selectGrammar(null, '#!/usr/bin/ruby')).not.toThrow() - expect(-> syntax.selectGrammar(null, '')).not.toThrow() - expect(-> syntax.selectGrammar(null, null)).not.toThrow() + expect(-> atom.syntax.selectGrammar(null, '#!/usr/bin/ruby')).not.toThrow() + expect(-> atom.syntax.selectGrammar(null, '')).not.toThrow() + expect(-> atom.syntax.selectGrammar(null, null)).not.toThrow() describe ".removeGrammar(grammar)", -> it "removes the grammar, so it won't be returned by selectGrammar", -> - grammar = syntax.selectGrammar('foo.js') - syntax.removeGrammar(grammar) - expect(syntax.selectGrammar('foo.js').name).not.toBe grammar.name + grammar = atom.syntax.selectGrammar('foo.js') + atom.syntax.removeGrammar(grammar) + expect(atom.syntax.selectGrammar('foo.js').name).not.toBe grammar.name describe ".getProperty(scopeDescriptor)", -> it "returns the property with the most specific scope selector", -> - syntax.addProperties(".source.coffee .string.quoted.double.coffee", foo: bar: baz: 42) - syntax.addProperties(".source .string.quoted.double", foo: bar: baz: 22) - syntax.addProperties(".source", foo: bar: baz: 11) + atom.syntax.addProperties(".source.coffee .string.quoted.double.coffee", foo: bar: baz: 42) + atom.syntax.addProperties(".source .string.quoted.double", foo: bar: baz: 22) + atom.syntax.addProperties(".source", foo: bar: baz: 11) - expect(syntax.getProperty([".source.coffee", ".string.quoted.double.coffee"], "foo.bar.baz")).toBe 42 - expect(syntax.getProperty([".source.js", ".string.quoted.double.js"], "foo.bar.baz")).toBe 22 - expect(syntax.getProperty([".source.js", ".variable.assignment.js"], "foo.bar.baz")).toBe 11 - expect(syntax.getProperty([".text"], "foo.bar.baz")).toBeUndefined() + expect(atom.syntax.getProperty([".source.coffee", ".string.quoted.double.coffee"], "foo.bar.baz")).toBe 42 + expect(atom.syntax.getProperty([".source.js", ".string.quoted.double.js"], "foo.bar.baz")).toBe 22 + expect(atom.syntax.getProperty([".source.js", ".variable.assignment.js"], "foo.bar.baz")).toBe 11 + expect(atom.syntax.getProperty([".text"], "foo.bar.baz")).toBeUndefined() it "favors the most recently added properties in the event of a specificity tie", -> - syntax.addProperties(".source.coffee .string.quoted.single", foo: bar: baz: 42) - syntax.addProperties(".source.coffee .string.quoted.double", foo: bar: baz: 22) + atom.syntax.addProperties(".source.coffee .string.quoted.single", foo: bar: baz: 42) + atom.syntax.addProperties(".source.coffee .string.quoted.double", foo: bar: baz: 22) - expect(syntax.getProperty([".source.coffee", ".string.quoted.single"], "foo.bar.baz")).toBe 42 - expect(syntax.getProperty([".source.coffee", ".string.quoted.single.double"], "foo.bar.baz")).toBe 22 + expect(atom.syntax.getProperty([".source.coffee", ".string.quoted.single"], "foo.bar.baz")).toBe 42 + expect(atom.syntax.getProperty([".source.coffee", ".string.quoted.single.double"], "foo.bar.baz")).toBe 22 describe ".removeProperties(name)", -> it "allows properties to be removed by name", -> - syntax.addProperties("a", ".source.coffee .string.quoted.double.coffee", foo: bar: baz: 42) - syntax.addProperties("b", ".source .string.quoted.double", foo: bar: baz: 22) + atom.syntax.addProperties("a", ".source.coffee .string.quoted.double.coffee", foo: bar: baz: 42) + atom.syntax.addProperties("b", ".source .string.quoted.double", foo: bar: baz: 22) - syntax.removeProperties("b") - expect(syntax.getProperty([".source.js", ".string.quoted.double.js"], "foo.bar.baz")).toBeUndefined() - expect(syntax.getProperty([".source.coffee", ".string.quoted.double.coffee"], "foo.bar.baz")).toBe 42 + atom.syntax.removeProperties("b") + expect(atom.syntax.getProperty([".source.js", ".string.quoted.double.js"], "foo.bar.baz")).toBeUndefined() + expect(atom.syntax.getProperty([".source.coffee", ".string.quoted.double.coffee"], "foo.bar.baz")).toBe 42 diff --git a/spec/text-mate-grammar-spec.coffee b/spec/text-mate-grammar-spec.coffee index 2c76a9796..00198afff 100644 --- a/spec/text-mate-grammar-spec.coffee +++ b/spec/text-mate-grammar-spec.coffee @@ -13,7 +13,7 @@ describe "TextMateGrammar", -> atom.activatePackage('language-html', sync: true) atom.activatePackage('language-php', sync: true) atom.activatePackage('language-python', sync: true) - grammar = syntax.selectGrammar("hello.coffee") + grammar = atom.syntax.selectGrammar("hello.coffee") describe "@loadSync(path)", -> it "loads grammars from plists", -> @@ -49,7 +49,7 @@ describe "TextMateGrammar", -> describe "when the line doesn't match any patterns", -> it "returns the entire line as a single simple token with the grammar's scope", -> - textGrammar = syntax.selectGrammar('foo.txt') + textGrammar = atom.syntax.selectGrammar('foo.txt') {tokens} = textGrammar.tokenizeLine("abc def") expect(tokens.length).toBe 1 @@ -126,20 +126,20 @@ describe "TextMateGrammar", -> describe "when the line matches no patterns", -> it "does not infinitely loop", -> - grammar = syntax.selectGrammar("sample.txt") + grammar = atom.syntax.selectGrammar("sample.txt") {tokens} = grammar.tokenizeLine('hoo') expect(tokens.length).toBe 1 expect(tokens[0]).toEqual value: 'hoo', scopes: ["text.plain", "meta.paragraph.text"] describe "when the line matches a pattern with a 'contentName'", -> it "creates tokens using the content of contentName as the token name", -> - grammar = syntax.selectGrammar("sample.txt") + grammar = atom.syntax.selectGrammar("sample.txt") {tokens} = grammar.tokenizeLine('ok, cool') expect(tokens[0]).toEqual value: 'ok, cool', scopes: ["text.plain", "meta.paragraph.text"] describe "when the line matches a pattern with no `name` or `contentName`", -> it "creates tokens without adding a new scope", -> - grammar = syntax.selectGrammar('foo.rb') + grammar = atom.syntax.selectGrammar('foo.rb') {tokens} = grammar.tokenizeLine('%w|oh \\look|') expect(tokens.length).toBe 5 expect(tokens[0]).toEqual value: '%w|', scopes: ["source.ruby", "string.quoted.other.literal.lower.ruby", "punctuation.definition.string.begin.ruby"] @@ -184,7 +184,7 @@ describe "TextMateGrammar", -> describe "when the end pattern contains a back reference", -> it "constructs the end rule based on its back-references to captures in the begin rule", -> - grammar = syntax.selectGrammar('foo.rb') + grammar = atom.syntax.selectGrammar('foo.rb') {tokens} = grammar.tokenizeLine('%w|oh|,') expect(tokens.length).toBe 4 expect(tokens[0]).toEqual value: '%w|', scopes: ["source.ruby", "string.quoted.other.literal.lower.ruby", "punctuation.definition.string.begin.ruby"] @@ -193,7 +193,7 @@ describe "TextMateGrammar", -> expect(tokens[3]).toEqual value: ',', scopes: ["source.ruby", "punctuation.separator.object.ruby"] it "allows the rule containing that end pattern to be pushed to the stack multiple times", -> - grammar = syntax.selectGrammar('foo.rb') + grammar = atom.syntax.selectGrammar('foo.rb') {tokens} = grammar.tokenizeLine('%Q+matz had some #{%Q-crazy ideas-} for ruby syntax+ # damn.') expect(tokens[0]).toEqual value: '%Q+', scopes: ["source.ruby","string.quoted.other.literal.upper.ruby","punctuation.definition.string.begin.ruby"] expect(tokens[1]).toEqual value: 'matz had some ', scopes: ["source.ruby","string.quoted.other.literal.upper.ruby"] @@ -214,7 +214,7 @@ describe "TextMateGrammar", -> atom.activatePackage('language-html', sync: true) atom.activatePackage('language-ruby-on-rails', sync: true) - grammar = syntax.grammarForScopeName('text.html.ruby') + grammar = atom.syntax.grammarForScopeName('text.html.ruby') {tokens} = grammar.tokenizeLine("
<%= User.find(2).full_name %>
") expect(tokens[0]).toEqual value: '<', scopes: ["text.html.ruby","meta.tag.block.any.html","punctuation.definition.tag.begin.html"] @@ -245,7 +245,7 @@ describe "TextMateGrammar", -> atom.activatePackage('language-html', sync: true) atom.activatePackage('language-ruby-on-rails', sync: true) - grammar = syntax.selectGrammar('foo.html.erb') + grammar = atom.syntax.selectGrammar('foo.html.erb') grammarUpdatedHandler = jasmine.createSpy("grammarUpdatedHandler") grammar.on 'grammar-updated', grammarUpdatedHandler @@ -263,7 +263,7 @@ describe "TextMateGrammar", -> atom.deactivatePackage('language-html') atom.activatePackage('language-ruby-on-rails', sync: true) - grammar = syntax.grammarForScopeName('text.html.ruby') + grammar = atom.syntax.grammarForScopeName('text.html.ruby') {tokens} = grammar.tokenizeLine("
<%= User.find(2).full_name %>
") expect(tokens[0]).toEqual value: "
", scopes: ["text.html.ruby"] expect(tokens[1]).toEqual value: '<%=', scopes: ["text.html.ruby","source.ruby.rails.embedded.html","punctuation.section.embedded.ruby"] @@ -308,7 +308,7 @@ describe "TextMateGrammar", -> expect(tokens[1].value).toBe " a singleLineComment" it "does not loop infinitely (regression)", -> - grammar = syntax.selectGrammar("hello.js") + grammar = atom.syntax.selectGrammar("hello.js") {tokens, ruleStack} = grammar.tokenizeLine("// line comment") {tokens, ruleStack} = grammar.tokenizeLine(" // second line comment with a single leading space", ruleStack) @@ -317,12 +317,12 @@ describe "TextMateGrammar", -> atom.activatePackage('language-c', sync: true) it "correctly parses a method. (regression)", -> - grammar = syntax.selectGrammar("hello.c") + grammar = atom.syntax.selectGrammar("hello.c") {tokens, ruleStack} = grammar.tokenizeLine("if(1){m()}") expect(tokens[5]).toEqual value: "m", scopes: ["source.c", "meta.block.c", "meta.function-call.c", "support.function.any-method.c"] it "correctly parses nested blocks. (regression)", -> - grammar = syntax.selectGrammar("hello.c") + grammar = atom.syntax.selectGrammar("hello.c") {tokens, ruleStack} = grammar.tokenizeLine("if(1){if(1){m()}}") expect(tokens[5]).toEqual value: "if", scopes: ["source.c", "meta.block.c", "keyword.control.c"] expect(tokens[10]).toEqual value: "m", scopes: ["source.c", "meta.block.c", "meta.block.c", "meta.function-call.c", "support.function.any-method.c"] @@ -331,7 +331,7 @@ describe "TextMateGrammar", -> it "aborts tokenization", -> spyOn(console, 'error') atom.activatePackage("package-with-infinite-loop-grammar") - grammar = syntax.selectGrammar("something.package-with-infinite-loop-grammar") + grammar = atom.syntax.selectGrammar("something.package-with-infinite-loop-grammar") {tokens} = grammar.tokenizeLine("abc") expect(tokens[0].value).toBe "a" expect(tokens[1].value).toBe "bc" @@ -340,13 +340,13 @@ describe "TextMateGrammar", -> describe "when a grammar has a pattern that has back references in the match value", -> it "does not special handle the back references and instead allows oniguruma to resolve them", -> atom.activatePackage('language-sass', sync: true) - grammar = syntax.selectGrammar("style.scss") + grammar = atom.syntax.selectGrammar("style.scss") {tokens} = grammar.tokenizeLine("@mixin x() { -moz-selector: whatever; }") expect(tokens[9]).toEqual value: "-moz-selector", scopes: ["source.css.scss", "meta.property-list.scss", "meta.property-name.scss"] describe "when a line has more tokens than `maxTokensPerLine`", -> it "creates a final token with the remaining text and resets the ruleStack to match the begining of the line", -> - grammar = syntax.selectGrammar("hello.js") + grammar = atom.syntax.selectGrammar("hello.js") spyOn(grammar, 'getMaxTokensPerLine').andCallFake -> 5 originalRuleStack = [grammar.initialRule, grammar.initialRule, grammar.initialRule] {tokens, ruleStack} = grammar.tokenizeLine("one(two(three(four(five(_param_)))))", originalRuleStack) @@ -356,7 +356,7 @@ describe "TextMateGrammar", -> describe "when a grammar has a capture with patterns", -> it "matches the patterns and includes the scope specified as the pattern's match name", -> - grammar = syntax.selectGrammar("hello.php") + grammar = atom.syntax.selectGrammar("hello.php") {tokens} = grammar.tokenizeLine("") expect(tokens[2].value).toBe "public" @@ -402,7 +402,7 @@ describe "TextMateGrammar", -> describe "when the grammar has injections", -> it "correctly includes the injected patterns when tokenizing", -> - grammar = syntax.selectGrammar("hello.php") + grammar = atom.syntax.selectGrammar("hello.php") {tokens} = grammar.tokenizeLine("
") expect(tokens[3].value).toBe " describe "when the grammar's pattern name has a group number in it", -> it "replaces the group number with the matched captured text", -> atom.activatePackage('language-hyperlink', sync: true) - grammar = syntax.grammarForScopeName("text.hyperlink") + grammar = atom.syntax.grammarForScopeName("text.hyperlink") {tokens} = grammar.tokenizeLine("https://github.com") expect(tokens[0].scopes).toEqual ["text.hyperlink", "markup.underline.link.https.hyperlink"] describe "when the grammar has an injection selector", -> it "includes the grammar's patterns when the selector matches the current scope in other grammars", -> atom.activatePackage('language-hyperlink', sync: true) - grammar = syntax.selectGrammar("text.js") + grammar = atom.syntax.selectGrammar("text.js") {tokens} = grammar.tokenizeLine("var i; // http://github.com") expect(tokens[0].value).toBe "var" @@ -469,7 +469,7 @@ describe "TextMateGrammar", -> expect(tokens[1].value).toBe " SELECT * FROM OCTOCATS" expect(tokens[1].scopes).toEqual ["source.js", "comment.line.double-slash.js"] - syntax.addGrammar(new TextMateGrammar( + atom.syntax.addGrammar(new TextMateGrammar( name: "test" scopeName: "source.test" repository: {} @@ -515,7 +515,7 @@ describe "TextMateGrammar", -> beforeEach -> atom.activatePackage('language-todo', sync: true) - grammar = syntax.selectGrammar('main.rb') + grammar = atom.syntax.selectGrammar('main.rb') lines = grammar.tokenizeLines "# TODO be nicer" it "replaces the number with the capture group and translates the text", -> @@ -529,7 +529,7 @@ describe "TextMateGrammar", -> describe "Git commit messages", -> beforeEach -> atom.activatePackage('language-git', sync: true) - grammar = syntax.selectGrammar('COMMIT_EDITMSG') + grammar = atom.syntax.selectGrammar('COMMIT_EDITMSG') lines = grammar.tokenizeLines """ longggggggggggggggggggggggggggggggggggggggggggggggg # Please enter the commit message for your changes. Lines starting @@ -548,7 +548,7 @@ describe "TextMateGrammar", -> describe "C++", -> beforeEach -> atom.activatePackage('language-c', sync: true) - grammar = syntax.selectGrammar('includes.cc') + grammar = atom.syntax.selectGrammar('includes.cc') lines = grammar.tokenizeLines """ #include "a.h" #include "b.h" @@ -570,7 +570,7 @@ describe "TextMateGrammar", -> describe "Ruby", -> beforeEach -> - grammar = syntax.selectGrammar('hello.rb') + grammar = atom.syntax.selectGrammar('hello.rb') lines = grammar.tokenizeLines """ a = { "b" => "c", @@ -587,7 +587,7 @@ describe "TextMateGrammar", -> beforeEach -> atom.activatePackage('language-c', sync: true) atom.activatePackage('language-objective-c', sync: true) - grammar = syntax.selectGrammar('function.mm') + grammar = atom.syntax.selectGrammar('function.mm') lines = grammar.tokenizeLines """ void test() { NSString *a = @"a\\nb"; @@ -613,7 +613,7 @@ describe "TextMateGrammar", -> describe "Java", -> beforeEach -> atom.activatePackage('language-java', sync: true) - grammar = syntax.selectGrammar('Function.java') + grammar = atom.syntax.selectGrammar('Function.java') it "correctly parses single line comments", -> lines = grammar.tokenizeLines """ @@ -636,7 +636,7 @@ describe "TextMateGrammar", -> describe "HTML (Ruby - ERB)", -> beforeEach -> - grammar = syntax.selectGrammar('page.erb') + grammar = atom.syntax.selectGrammar('page.erb') lines = grammar.tokenizeLines '<% page_title "My Page" %>' it "correctly parses strings inside tags", -> @@ -652,7 +652,7 @@ describe "TextMateGrammar", -> describe "Unicode support", -> describe "Surrogate pair characters", -> beforeEach -> - grammar = syntax.selectGrammar('main.js') + grammar = atom.syntax.selectGrammar('main.js') lines = grammar.tokenizeLines "'\uD835\uDF97'" it "correctly parses JavaScript strings containing surrogate pair characters", -> @@ -665,7 +665,7 @@ describe "TextMateGrammar", -> describe "when the line contains unicode characters", -> it "correctly parses tokens starting after them", -> atom.activatePackage('language-json', sync: true) - grammar = syntax.selectGrammar('package.json') + grammar = atom.syntax.selectGrammar('package.json') {tokens} = grammar.tokenizeLine '{"\u2026": 1}' expect(tokens.length).toBe 8 @@ -674,7 +674,7 @@ describe "TextMateGrammar", -> describe "python", -> it "parses import blocks correctly", -> - grammar = syntax.selectGrammar("file.py") + grammar = atom.syntax.selectGrammar("file.py") lines = grammar.tokenizeLines "import a\nimport b" line1 = lines[0] diff --git a/spec/tokenized-buffer-spec.coffee b/spec/tokenized-buffer-spec.coffee index 096060bec..f24cfae6e 100644 --- a/spec/tokenized-buffer-spec.coffee +++ b/spec/tokenized-buffer-spec.coffee @@ -393,7 +393,7 @@ describe "TokenizedBuffer", -> buffer = project.bufferForPathSync() buffer.setText "
<%= User.find(2).full_name %>
" tokenizedBuffer = new TokenizedBuffer({buffer}) - tokenizedBuffer.setGrammar(syntax.selectGrammar('test.erb')) + tokenizedBuffer.setGrammar(atom.syntax.selectGrammar('test.erb')) fullyTokenize(tokenizedBuffer) {tokens} = tokenizedBuffer.lineForScreenRow(0) diff --git a/spec/window-spec.coffee b/spec/window-spec.coffee index 3a54265b0..f7b8dbe01 100644 --- a/spec/window-spec.coffee +++ b/spec/window-spec.coffee @@ -84,7 +84,7 @@ describe "Window", -> describe ".unloadEditorWindow()", -> it "saves the serialized state of the window so it can be deserialized after reload", -> rootViewState = rootView.serialize() - syntaxState = syntax.serialize() + syntaxState = atom.syntax.serialize() window.unloadEditorWindow() diff --git a/src/atom-package.coffee b/src/atom-package.coffee index 772b09761..7566c887f 100644 --- a/src/atom-package.coffee +++ b/src/atom-package.coffee @@ -105,9 +105,9 @@ class AtomPackage extends Package atom.keymap.add(keymapPath, map) for [keymapPath, map] in @keymaps atom.contextMenu.add(menuPath, map['context-menu']) for [menuPath, map] in @menus atom.menu.add(map.menu) for [menuPath, map] in @menus when map.menu - syntax.addGrammar(grammar) for grammar in @grammars + atom.syntax.addGrammar(grammar) for grammar in @grammars for [scopedPropertiesPath, selector, properties] in @scopedProperties - syntax.addProperties(scopedPropertiesPath, selector, properties) + atom.syntax.addProperties(scopedPropertiesPath, selector, properties) loadKeymaps: -> @keymaps = @getKeymapPaths().map (keymapPath) -> [keymapPath, CSON.readFileSync(keymapPath)] @@ -180,8 +180,8 @@ class AtomPackage extends Package @configActivated = false deactivateResources: -> - syntax.removeGrammar(grammar) for grammar in @grammars - syntax.removeProperties(scopedPropertiesPath) for [scopedPropertiesPath] in @scopedProperties + atom.syntax.removeGrammar(grammar) for grammar in @grammars + atom.syntax.removeProperties(scopedPropertiesPath) for [scopedPropertiesPath] in @scopedProperties atom.keymap.remove(keymapPath) for [keymapPath] in @keymaps atom.themes.removeStylesheet(stylesheetPath) for [stylesheetPath] in @stylesheets @stylesheetsActivated = false diff --git a/src/language-mode.coffee b/src/language-mode.coffee index 462be533d..1947de408 100644 --- a/src/language-mode.coffee +++ b/src/language-mode.coffee @@ -38,7 +38,7 @@ class LanguageMode # Returns an {Array} of the commented {Ranges}. toggleLineCommentsForBufferRows: (start, end) -> scopes = @editSession.scopesForBufferPosition([start, 0]) - properties = syntax.propertiesForScope(scopes, "editor.commentStart")[0] + properties = atom.syntax.propertiesForScope(scopes, "editor.commentStart")[0] return unless properties commentStartString = _.valueForKeyPath(properties, "editor.commentStart") @@ -292,14 +292,15 @@ class LanguageMode tokenizeLine: (line, stack, firstLine) -> {tokens, stack} = @grammar.tokenizeLine(line, stack, firstLine) + getRegexForProperty: (scopes, property) -> + if pattern = atom.syntax.getProperty(scopes, property) + new OnigRegExp(pattern) + increaseIndentRegexForScopes: (scopes) -> - if increaseIndentPattern = syntax.getProperty(scopes, 'editor.increaseIndentPattern') - new OnigRegExp(increaseIndentPattern) + @getRegexForProperty(scopes, 'editor.increaseIndentPattern') decreaseIndentRegexForScopes: (scopes) -> - if decreaseIndentPattern = syntax.getProperty(scopes, 'editor.decreaseIndentPattern') - new OnigRegExp(decreaseIndentPattern) + @getRegexForProperty(scopes, 'editor.decreaseIndentPattern') foldEndRegexForScopes: (scopes) -> - if foldEndPattern = syntax.getProperty(scopes, 'editor.foldEndPattern') - new OnigRegExp(foldEndPattern) + @getRegexForProperty(scopes, 'editor.foldEndPattern') diff --git a/src/text-mate-grammar.coffee b/src/text-mate-grammar.coffee index 8cedf4c19..74c88569f 100644 --- a/src/text-mate-grammar.coffee +++ b/src/text-mate-grammar.coffee @@ -68,14 +68,14 @@ class TextMateGrammar grammarUpdated: (scopeName) -> return false unless _.include(@includedGrammarScopes, scopeName) @clearRules() - syntax.grammarUpdated(@scopeName) + atom.syntax.grammarUpdated(@scopeName) @emit 'grammar-updated' true getScore: (filePath, contents) -> contents = fs.readFileSync(filePath, 'utf8') if not contents? and fs.isFileSync(filePath) - if syntax.grammarOverrideForPath(filePath) is @scopeName + if atom.syntax.grammarOverrideForPath(filePath) is @scopeName 2 + (filePath?.length ? 0) else if @matchesContents(contents) 1 + (filePath?.length ? 0) @@ -288,7 +288,7 @@ class Rule results.push(result) scopes = scopesFromStack(ruleStack) - for injectionGrammar in _.without(syntax.injectionGrammars, @grammar, baseGrammar) + for injectionGrammar in _.without(atom.syntax.injectionGrammars, @grammar, baseGrammar) if injectionGrammar.injectionSelector.matches(scopes) scanner = injectionGrammar.getInitialRule().getScanner(injectionGrammar, position, firstLine) if result = scanner.findNextMatch(lineWithNewline, position) @@ -409,7 +409,7 @@ class Pattern baseGrammar.getInitialRule() else @grammar.addIncludedGrammarScope(name) - syntax.grammarForScopeName(name)?.getInitialRule() + atom.syntax.grammarForScopeName(name)?.getInitialRule() getIncludedPatterns: (baseGrammar, included) -> if @include diff --git a/src/text-mate-package.coffee b/src/text-mate-package.coffee index 8ab56f844..036d47577 100644 --- a/src/text-mate-package.coffee +++ b/src/text-mate-package.coffee @@ -41,15 +41,15 @@ class TextMatePackage extends Package activate: -> @measure 'activateTime', => - syntax.addGrammar(grammar) for grammar in @grammars + atom.syntax.addGrammar(grammar) for grammar in @grammars for { selector, properties } in @scopedProperties - syntax.addProperties(@path, selector, properties) + atom.syntax.addProperties(@path, selector, properties) activateConfig: -> # noop deactivate: -> - syntax.removeGrammar(grammar) for grammar in @grammars - syntax.removeProperties(@path) + atom.syntax.removeGrammar(grammar) for grammar in @grammars + atom.syntax.removeProperties(@path) legalGrammarExtensions: ['plist', 'tmLanguage', 'tmlanguage', 'json', 'cson'] @@ -77,7 +77,7 @@ class TextMatePackage extends Package addGrammar: (grammar) -> @grammars.push(grammar) - syntax.addGrammar(grammar) if @isActive() + atom.syntax.addGrammar(grammar) if @isActive() getGrammars: -> @grammars @@ -98,38 +98,38 @@ class TextMatePackage extends Package loadScopedPropertiesSync: -> for grammar in @getGrammars() if properties = @propertiesFromTextMateSettings(grammar) - selector = syntax.cssSelectorFromScopeSelector(grammar.scopeName) + selector = atom.syntax.cssSelectorFromScopeSelector(grammar.scopeName) @scopedProperties.push({selector, properties}) for preferencePath in fs.listSync(@getPreferencesPath()) {scope, settings} = fs.readObjectSync(preferencePath) if properties = @propertiesFromTextMateSettings(settings) - selector = syntax.cssSelectorFromScopeSelector(scope) if scope? + selector = atom.syntax.cssSelectorFromScopeSelector(scope) if scope? @scopedProperties.push({selector, properties}) if @isActive() for {selector, properties} in @scopedProperties - syntax.addProperties(@path, selector, properties) + atom.syntax.addProperties(@path, selector, properties) loadScopedProperties: (callback) -> scopedProperties = [] for grammar in @getGrammars() if properties = @propertiesFromTextMateSettings(grammar) - selector = syntax.cssSelectorFromScopeSelector(grammar.scopeName) + selector = atom.syntax.cssSelectorFromScopeSelector(grammar.scopeName) scopedProperties.push({selector, properties}) preferenceObjects = [] done = => for {scope, settings} in preferenceObjects if properties = @propertiesFromTextMateSettings(settings) - selector = syntax.cssSelectorFromScopeSelector(scope) if scope? + selector = atom.syntax.cssSelectorFromScopeSelector(scope) if scope? scopedProperties.push({selector, properties}) @scopedProperties = scopedProperties if @isActive() for {selector, properties} in @scopedProperties - syntax.addProperties(@path, selector, properties) + atom.syntax.addProperties(@path, selector, properties) callback?() @loadTextMatePreferenceObjects(preferenceObjects, done) diff --git a/src/tokenized-buffer.coffee b/src/tokenized-buffer.coffee index e6e97c46e..f5dcc1af1 100644 --- a/src/tokenized-buffer.coffee +++ b/src/tokenized-buffer.coffee @@ -64,7 +64,7 @@ class TokenizedBuffer @emit 'grammar-changed', grammar reloadGrammar: -> - if grammar = syntax.selectGrammar(@buffer.getPath(), @buffer.getText()) + if grammar = atom.syntax.selectGrammar(@buffer.getPath(), @buffer.getText()) @setGrammar(grammar) else throw new Error("No grammar found for path: #{path}")