Skip to content
This repository has been archived by the owner on Oct 19, 2018. It is now read-only.

Commit

Permalink
Use scope name when grammar name is missing
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinsawicki committed Feb 28, 2014
1 parent d17a8c4 commit 51c5310
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 3 deletions.
5 changes: 3 additions & 2 deletions lib/grammar-list-view.coffee
Expand Up @@ -25,7 +25,7 @@ class GrammarListView extends SelectListView
viewForItem: (grammar) ->
element = document.createElement('li')
element.classList.add('active') if grammar is @currentGrammar
element.textContent = grammar.name
element.textContent = grammar.name ? grammar.scopeName
element

confirmed: (grammar) ->
Expand All @@ -51,6 +51,7 @@ class GrammarListView extends SelectListView
else if grammarB.scopeName is 'text.plain'
1
else
grammarA.name.localeCompare(grammarB.name)
grammarA.name?.localeCompare?(grammarB.name) ? grammarA.scopeName?.localeCompare?(grammarB.name) ? 1

grammars.unshift(@autoDetect)
grammars
2 changes: 1 addition & 1 deletion lib/grammar-status-view.coffee
Expand Up @@ -29,7 +29,7 @@ class GrammarStatusView extends View
if grammar is atom.syntax.nullGrammar
grammarName = 'Plain Text'
else
grammarName = grammar.name
grammarName = grammar.name ? grammar.scopeName
@text(grammarName).show()
else
@hide()
8 changes: 8 additions & 0 deletions spec/fixtures/language-with-no-name/grammars/a.json
@@ -0,0 +1,8 @@
{
"scopeName": "source.a",
"fileTypes": [
".a",
".aa",
"a"
]
}
4 changes: 4 additions & 0 deletions spec/fixtures/language-with-no-name/package.json
@@ -0,0 +1,4 @@
{
"name": "language-test",
"version": "1.0"
}
9 changes: 9 additions & 0 deletions spec/grammar-selector-spec.coffee
@@ -1,3 +1,4 @@
path = require 'path'
{$, WorkspaceView, View} = require 'atom'

class StatusBarMock extends View
Expand Down Expand Up @@ -27,6 +28,9 @@ describe "GrammarSelector", ->
waitsForPromise ->
atom.packages.activatePackage('language-javascript')

waitsForPromise ->
atom.packages.activatePackage(path.join(__dirname, 'fixtures', 'language-with-no-name'))

runs ->
atom.workspaceView.openSync('sample.js')
editorView = atom.workspaceView.getActiveView()
Expand All @@ -45,6 +49,7 @@ describe "GrammarSelector", ->
{grammars} = atom.syntax
expect(grammarView.list.children('li').length).toBe grammars.length
expect(grammarView.list.children('li:first').text()).toBe 'Auto Detect'
expect(grammarView.list.children('li:contains(source.a)')).toExist()
for li in grammarView.list.children('li')
expect($(li).text()).not.toBe atom.syntax.nullGrammar.name

Expand Down Expand Up @@ -114,6 +119,10 @@ describe "GrammarSelector", ->
editor.reloadGrammar()
expect(grammarStatus.text()).toBe 'Plain Text'

atom.syntax.setGrammarOverrideForPath(editor.getPath(), 'source.a')
editor.reloadGrammar()
expect(grammarStatus.text()).toBe 'source.a'

describe "when clicked", ->
it "toggles the grammar-selector:show event", ->
eventHandler = jasmine.createSpy('eventHandler')
Expand Down

0 comments on commit 51c5310

Please sign in to comment.