Skip to content
This repository has been archived by the owner on Mar 3, 2023. It is now read-only.

Add grammar scope to EditorView #2996

Merged
merged 7 commits into from
Aug 25, 2014
Merged

Add grammar scope to EditorView #2996

merged 7 commits into from
Aug 25, 2014

Conversation

thomasjo
Copy link
Contributor

NOTE: This pull request is still work in progress. I just wanted to open it early to keep my intent and progress public, and discoverable.

The sole purpose of this pull request is to add grammar scope information to EditorView instances, so that e.g. editor key bindings can trigger based on grammar. Useful if you want to invoke different build or formatting commands in various packages, for different types of grammars.

Right now I'm solving this by appending CSS classes to the view, but I'm leaning towards adding a data-scope attribute instead, to prevent pollution and potential conflicts that might cause all manner of mayhem.

@thomasjo
Copy link
Contributor Author

With the change to using data attributes, an entry in keymap.cson might look like this

'.editor[data-scope~="python"]':
  'ctrl-alt-shift-a': 'something:awesome'

and this works even if the data-scope attribute is equal to source python.

@thomasjo
Copy link
Contributor Author

@nathansobo Do the changes to ReactEditorView make sense? It seemed like the best place to add the necessary bits, but I must admit I got a little bit lost trying to figure out the exact hierarchy of the React views and components.

@lee-dohm Was this more or less what you had in mind?

If this seems useful to folks, I'll get create a few tests that cover the changes I've made.

@lee-dohm
Copy link
Contributor

Yeah, this seems pretty much like what I was thinking about. Thanks for taking the initiative!

@ioquatix
Copy link

+1 awesome.


if @attached and @editor.buffer.isInConflict()
_.defer => @showBufferConflictAlert(@editor) # Display after editor has a chance to display

addGrammarScopeAttribute: ->
grammarScope = @editor.getGrammar()?.scopeName?.replace(/\./g, ' ')
@attr('data-scope', grammarScope)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you think about data-grammar instead of data-scope? It seems a bit more descriptive.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed, and changed!

@kevinsawicki kevinsawicki self-assigned this Jul 22, 2014
@thomasjo
Copy link
Contributor Author

Should I go ahead and add a few tests that cover the changes? Extremely busy right now, but I'll find time if necessary :bowtie:

@kevinsawicki
Copy link
Contributor

@thomasjo tests would be great whenever you get a chance, also this branch does not appear to cleanly merge anymore so please rebase/merge master.

@thomasjo
Copy link
Contributor Author

@kevinsawicki I've finally gotten around to add a test that verifies The Happy Path™. Let me know if you'd like me to expand with more tests.

I'm unable to actually verify my test though, since I'm still seeing heaps of broken tests on master. And specifically in relation to my test, there are many sibling tests failing because of this error

Error: Must supply an Editor or mini: true
  at EditorView.module.exports.EditorView.initialize (/Users/thomasjo/Projects/atom/src/editor-view.coffee:143:17)
  at EditorView.View (/Users/thomasjo/Projects/atom/node_modules/space-pen/lib/space-pen.js:137:25)
  at new EditorView (/Users/thomasjo/Projects/atom/src/editor-view.coffee:43:3)
  at [object Object].<anonymous> (/Users/thomasjo/Projects/atom/spec/editor-view-spec.coffee:23:24)
  at _fulfilled (/Applications/Atom.app/Contents/Resources/app/node_modules/q/q.js:787:54)
  at self.promiseDispatch.done (/Applications/Atom.app/Contents/Resources/app/node_modules/q/q.js:816:30)
  at Promise.promise.promiseDispatch (/Applications/Atom.app/Contents/Resources/app/node_modules/q/q.js:749:13)
  at /Applications/Atom.app/Contents/Resources/app/node_modules/q/q.js:557:44
  at flush (/Applications/Atom.app/Contents/Resources/app/node_modules/q/q.js:108:17)
  at process._tickCallback (node.js:349:11)

Which results in all calls to editorView.attachToDom() to fail because editorView is undefined.

Are the any special magic tricks I need to perform to get all specs to pass locally? Since we don't see the build status in your CI environment, I don't know if they are broken for everyone of if there is merely something wrong with my development environment.

@kevinsawicki
Copy link
Contributor

Are the any special magic tricks I need to perform to get all specs to pass locally?

There shouldn't be, you should just be able to put run your spec only using the fdescribe keybinding and then run cmd-alt-ctrl-P to launch the specs.

Since we don't see the build status in your CI environment

Yeah, I really wish we were using Travis for core builds like we do for package builds.

I don't know if they are broken

I ran the spec you added locally and it does fail, I will leave some comments on the lines that need to be changed.

it "adds and updates the grammar data attribute based on the current grammar", ->
editorView.attachToDom()
editor.setGrammar(atom.syntax.grammarForScopeName('text.plain'))
expect(editorView.attr('data-grammar')).toEqual 'text.plain'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be text plain instead of text.plain, and also we usually use toBe instead of toEqual for string comparisons.

@thomasjo
Copy link
Contributor Author

Adjusted the spec according to your comments, but I'm still unable to run it locally. Still failing with

EditorView
  grammar data attributes
    it adds and updates the grammar data attribute based on the current grammar
      Error: Must supply an Editor or mini: true
        at EditorView.module.exports.EditorView.initialize (/Users/thomasjo/Projects/atom/src/editor-view.coffee:143:17)
        at EditorView.View (/Users/thomasjo/Projects/atom/node_modules/space-pen/lib/space-pen.js:137:25)
        at new EditorView (/Users/thomasjo/Projects/atom/src/editor-view.coffee:43:3)
        at [object Object].<anonymous> (/Users/thomasjo/Projects/atom/spec/editor-view-spec.coffee:23:24)
        at _fulfilled (/Applications/Atom.app/Contents/Resources/app/node_modules/q/q.js:787:54)
        at self.promiseDispatch.done (/Applications/Atom.app/Contents/Resources/app/node_modules/q/q.js:816:30)
        at Promise.promise.promiseDispatch (/Applications/Atom.app/Contents/Resources/app/node_modules/q/q.js:749:13)
        at /Applications/Atom.app/Contents/Resources/app/node_modules/q/q.js:557:44
        at flush (/Applications/Atom.app/Contents/Resources/app/node_modules/q/q.js:108:17)
        at process._tickCallback (node.js:349:11)
      TypeError: Cannot read property 'attachToDom' of undefined
        at [object Object].<anonymous> (/Users/thomasjo/Projects/atom/spec/editor-view-spec.coffee:3051:17)
        at _fulfilled (/Applications/Atom.app/Contents/Resources/app/node_modules/q/q.js:787:54)
        at self.promiseDispatch.done (/Applications/Atom.app/Contents/Resources/app/node_modules/q/q.js:816:30)
        at Promise.promise.promiseDispatch (/Applications/Atom.app/Contents/Resources/app/node_modules/q/q.js:749:13)
        at /Applications/Atom.app/Contents/Resources/app/node_modules/q/q.js:557:44
        at flush (/Applications/Atom.app/Contents/Resources/app/node_modules/q/q.js:108:17)
        at process._tickCallback (node.js:349:11)


Finished in 1.634 seconds
1 test, 2 assertions, 2 failures, 1253 skipped

Doesn't matter if I run it via Atom GUI or via apm. I believe every single EditorComponent spec fails locally, all seemingly due to the same problem. I'll open an issue for it.

@kevinsawicki
Copy link
Contributor

Really not sure why those are failing for you, I've not seen that exception before and the specs are runnable for me locally.

kevinsawicki added a commit that referenced this pull request Aug 25, 2014
@kevinsawicki kevinsawicki merged commit 4b8fd22 into atom:master Aug 25, 2014
@kevinsawicki
Copy link
Contributor

Thanks for this, it will be included in the next Atom release, 0.124

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants