Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add "Line Based" support #112

Merged
merged 13 commits into from
Jun 10, 2014
Merged

Conversation

erran
Copy link
Collaborator

@erran erran commented Apr 22, 2014

  • Add keycaps for "Line Based" runs
  • Add menus for "Line Based" runs
    • Right/ctrl clicking the line number will provide a menu option to run at the current line.
  • Update grammars.coffee for "Line Based" runs

line-based

@erran erran changed the title Add "Selection Based" support Add "Line Based" support Apr 22, 2014
@@ -6,4 +6,5 @@
'cmd-i': 'script:run'
'ctrl-w': 'script:close-view'
'ctrl-c': 'script:kill-process'
'shift-cmd-j': 'script:run-at-line'
Copy link
Member

Choose a reason for hiding this comment

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

I would have used shift-cmd-l, but this is fine.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@rgbkrk I was actually thinking the same. I have fat fingered cmd-j a few times which causes Atom to join lines (remove the previous line's new line char).

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@rgbkrk Just realized that shift-cmd-L is used by Core. I stripped this change.
screen shot 2014-04-22 at 19 21 28

@rgbkrk
Copy link
Member

rgbkrk commented Apr 22, 2014

I'm not a big fan of this argument explosion.

A little bird tells me we should create a CodeContext object that has getPath(), getLineNumber(), etc. methods.

@erran
Copy link
Collaborator Author

erran commented Apr 22, 2014

@rgbkrk Sounds good. I'll do that tonight.

It's worth mentioning that when selecting the entire line the next line is the number that is used. From memory of my earlier implementation: checking for the current selection and grabbing Math.min from the bufferRowRange would give the correct line number in the case of a whole line selection.

@rgbkrk
Copy link
Member

rgbkrk commented Apr 29, 2014

Sorry I had not come back to this for a bit. I definitely appreciate the CodeContext abstraction and that this will work well across line, selection, and file based runs. 😄

@erran
Copy link
Collaborator Author

erran commented Apr 30, 2014

I'm not a big fan of getters if they're just returning an attribute. I'd rather just use the attribute in those cases.

However - this is probably where we can address #86.

@rgbkrk If we do we'd have to send codeContext vs. codeContext.getCode. Perhaps send both context and the actual code as the function arguments?

@erran
Copy link
Collaborator Author

erran commented Apr 30, 2014

Can you add tests for the codeContext?

I'm not sure I follow do you mean in specs or to check that it's set. If the latter, where would I check since it's set outside of any conditionals.

@rgbkrk
Copy link
Member

rgbkrk commented May 5, 2014

I mean adding specs to this PR, so we can actually have unit tests for our own sanity.

See merge-conflicts for some great examples.

@erran
Copy link
Collaborator Author

erran commented May 6, 2014

@rgbkrk you got it. I'll try to get to this tomorrow night or Wednesday some time.

@rgbkrk
Copy link
Member

rgbkrk commented May 25, 2014

Still in the mood for some tests? 😉

@erran
Copy link
Collaborator Author

erran commented May 25, 2014

I've been on vacation for the last three weeks. I'll try to get to it this week, assuming no urgent things popped up at work, though.

@rgbkrk
Copy link
Member

rgbkrk commented May 25, 2014

Hey I understand that. Hope vacation was great!

@erran
Copy link
Collaborator Author

erran commented May 30, 2014

Started with something. See this commit 82eb5e4.
specs Is that what you had in mind? I'll get more done tomorrow.

@rgbkrk
Copy link
Member

rgbkrk commented May 30, 2014

Most definitely. I think you can clean out those junk tests that were basically boilerplate at this point.

@erran
Copy link
Collaborator Author

erran commented May 30, 2014

@rgbrkrk I ended up pushing what I had for the night. Turns out I can't find my Mac charger at home since my vacation, so I'll have to bring the spare from the office tomorrow. 😩

@rgbkrk
Copy link
Member

rgbkrk commented Jun 1, 2014

Ok, finally had a chance to look over this again with the new CodeContext object. I was really hoping that we would just use the CodeContext piece within all the grammars instead of casing off which argument is being run (as well as introducing that new parameter).

@@ -130,6 +136,9 @@ module.exports =
"File Based":
command: "rspec"
args: (filename) -> ['--tty', '--color', filename]
Copy link
Member

Choose a reason for hiding this comment

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

I'm expecting us to use the CodeContext objects here too, instead of the filename as the argument.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Great! 😄 Not sure what made me change this (or abstain from doing so).

@rgbkrk
Copy link
Member

rgbkrk commented Jun 1, 2014

Not surprisingly, since I just merged in Yet Another Language™ you'll need to fetch and rebase against upstream/master (or whatever remote name you have configured for github.com/rgbkrk/atom-script).

git fetch upstream
git rebase -i upstream/master

@erran
Copy link
Collaborator Author

erran commented Jun 1, 2014

@rgbkrk I had less merge conflicts than I'd have guessed. 😉

@erran
Copy link
Collaborator Author

erran commented Jun 1, 2014

@rgbkrk Going to sort out the specs now. Let me know if you have any other things to change in mind.

else
arg = selection.getText()

console.log "#{argType} executing"
Copy link
Member

Choose a reason for hiding this comment

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

Was this meant as a debug statement?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Oops! 😲

+ Update related specs
@rgbkrk
Copy link
Member

rgbkrk commented Jun 1, 2014

I'm currently trying to see if there's a good way to abstract this a bit more. Having setup be the main toggle lacks a lot of readibility. I kind of wish there were multiple entry points (in function name only), like runLine and run for the outer calls. It would be nice if setup was instead called createCodeContext and that we just encapsulated the overall run in that one code context object. Hmmm...

@erran
Copy link
Collaborator Author

erran commented Jun 1, 2014

@rgbkrk setup lines 74 through 97 could probably be moved into a validateLang() method for starters. That'd reduce a lot of code that'd need to be duplicated.

   # Get language
   lang = @getLang editor
   err = null

  # Determine if no language is selected.
   if lang is 'Null Grammar' or lang is 'Plain Text'
     err = $$ ->
       @p 'You must select a language in the lower left, or save the file
         with an appropriate extension.'

   # Provide them a dialog to submit an issue on GH, prepopulated with their
   # language of choice.
   else if not (lang of grammarMap)
     err = $$ ->
       @p class: 'block', "Command not configured for #{lang}!"
       @p class: 'block', =>
         @text 'Add an '
         @a href: "https://github.com/rgbkrk/atom-script/issues/\
           new?title=Add%20support%20for%20#{lang}", 'issue on GitHub'
         @text ' or send your own Pull Request.'

   if err?
     @handleError(err)
     return false

@rgbkrk
Copy link
Member

rgbkrk commented Jun 1, 2014

Yeah, gimme a sec. I'll probably end up submitting a PR against your branch shortly.

@erran
Copy link
Collaborator Author

erran commented Jun 1, 2014

@rgbkrk Fine with me. 👍

rgbkrk and others added 2 commits June 8, 2014 21:01
* Move CodeContext creation into its own build step
* Move language validation to its own function
* Finish extracting lang, codeContext
* Simplify line based path
* Separate line and file/selection runs
* Simplify code context selection
@erran
Copy link
Collaborator Author

erran commented Jun 10, 2014

Playing with a fix for #86 I ended up with this. python-fix

EDIT: Just realized that my change currently subtracts an extra line if we're going by a partial selection vs. an entire line. Which should we choose as the default? It's a matter of the shortcuts or no. of clicks a user uses for their selection.

@erran
Copy link
Collaborator Author

erran commented Jun 10, 2014

My second shot on a fix for #86 python-fix

@erran
Copy link
Collaborator Author

erran commented Jun 10, 2014

Here's the gif I'm thinking of replacing the README gif with:
demo

@rgbkrk
Copy link
Member

rgbkrk commented Jun 10, 2014

Love your color scheme, love the new README GIF, glad you showed off the right-click to run at line.

code = @codeContext.getCode()

expect(typeof code).toEqual('string')
expect(code).toMatch("print 'hello world!'")
Copy link
Member

Choose a reason for hiding this comment

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

Must say, thanks again for adding the tests.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

No problem!

@rgbkrk
Copy link
Member

rgbkrk commented Jun 10, 2014

Once you add the comment about why the whitespace was added for Python runs (or addressed for more langs), we :shipit:. Thanks for the new Line Based functionality AND the refactor to have CodeContext objects.

@erran
Copy link
Collaborator Author

erran commented Jun 10, 2014

I think I'll remove that commit for the sake of this PR since the proper fix would be multi-lingual.

@rgbkrk
Copy link
Member

rgbkrk commented Jun 10, 2014

I think I'll remove that commit for the sake of this PR since the proper fix would be multi-lingual.

I was about to say the same thing. Let's hash that out in a new PR.

@erran
Copy link
Collaborator Author

erran commented Jun 10, 2014

@rgbkrk Removed the commit. I'll add a new PR soon.

rgbkrk added a commit that referenced this pull request Jun 10, 2014
@rgbkrk rgbkrk merged commit 425440d into atom-community:master Jun 10, 2014
@rgbkrk
Copy link
Member

rgbkrk commented Jun 10, 2014

I'll make the release and update the relevant bits tomorrow morning. For now, I'm going to 😴. If you get the whitespace fix in the next day, we'll add that in as part of the release.

@erran erran deleted the line-based-execution branch June 10, 2014 07:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants