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

Allow to open file by current word #13

Merged
merged 1 commit into from
Oct 13, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions keymaps/atom-rails.cson
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@
'.editor':
'ctrl-alt-m': 'atom-rails:switch-to-model'
'ctrl-alt-r': 'atom-rails:related'
'shift-alt-r': 'atom-rails:open-definition-file'
10 changes: 9 additions & 1 deletion lib/atom-rails.coffee
Original file line number Diff line number Diff line change
@@ -1,18 +1,26 @@
Model = require './model'
Related = require './related'
DefinitionOpener = require './definitionOpener'

module.exports =
atomRailsView: null

activate: (state) ->
atom.workspaceView.command "atom-rails:switch-to-model", => @switchToModel()
atom.workspaceView.command "atom-rails:related", => @related()
atom.workspaceView.command "atom-rails:open-definition-file", =>
@openDefinitionFile()

switchToModel: ->
currentFile = atom.workspace.getActiveEditor().getPath()
file = new Model(currentFile).path()
atom.workspaceView.open(file) if file?


openDefinitionFile: ->
opener = new DefinitionOpener
opener.openOrIgnore()


related: ->
currentFile = atom.workspace.getActiveEditor().getPath()
file = new Related(currentFile).path()
Expand Down
24 changes: 24 additions & 0 deletions lib/definitionOpener.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
class DefinitionOpener
getDefinition: ->
activeEditor = atom.workspace.getActiveEditor()
cursor = activeEditor.cursors[0]
activeEditor.getCursor()
activeEditor.getTextInRange(cursor.getCurrentWordBufferRange())

openOrIgnore: (callback)->
@potentialPath (path)->
atom.workspaceView.open(path)

potentialPath: (callback)-> # it does not trigger callback if no path found
definition = @getDefinition()
regexp = new RegExp(" *((class)|(module)){1}( +)#{definition}[^\\w]")
potentialPath = null
atom.project.scan regexp, {}, (result, error) ->
return if potentialPath?

result ||= {}
potentialPath = result.filePath
callback(potentialPath) if potentialPath?


module.exports = DefinitionOpener
1 change: 1 addition & 0 deletions menus/atom-rails.cson
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
'label': 'atom-rails'
'submenu': [
{ 'label': 'Switch To Model', 'command': 'atom-rails:switch-to-model' }
{ 'label': 'Open definition file', 'command': 'atom-rails:open-definition-file' }
{ 'label': 'Related', 'command': 'atom-rails:related' }
]
]
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
"author": "Tom Kadwill",
"activationEvents": [
"atom-rails:switch-to-model",
"atom-rails:related"
"atom-rails:related",
"atom-rails:open-definition-file"
],
"repository": "https://github.com/tomkadwill/atom-rails",
"license": "MIT",
Expand Down