This repository has been archived by the owner on May 7, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 128
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #261 from greensnark/godef-with-context
Better godef integration: local defs, imports
- Loading branch information
Showing
5 changed files
with
303 additions
and
94 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
doneAlready = -> | ||
new Promise (resolve, reject) -> | ||
resolve() | ||
|
||
module.exports = | ||
class EditorLocationStack | ||
constructor: (@maxSize = 500) -> | ||
@maxSize = 1 if @maxSize < 1 | ||
@stack = [] | ||
|
||
isEmpty: -> | ||
not @stack.length | ||
|
||
reset: -> | ||
@stack = [] | ||
|
||
pushCurrentLocation: -> | ||
editor = atom.workspace.getActiveTextEditor() | ||
return unless editor | ||
loc = | ||
position: editor.getCursorBufferPosition() | ||
file: editor.getURI() | ||
return unless loc.file and loc.position?.row and loc.position?.column | ||
@push(loc) | ||
return | ||
|
||
## | ||
# Returns a promise that is complete when navigation is done. | ||
restorePreviousLocation: -> | ||
return doneAlready() if @isEmpty() | ||
lastLocation = @stack.pop() | ||
atom.workspace.open(lastLocation.file).then (editor) => | ||
@moveEditorCursorTo(editor, lastLocation.position) | ||
|
||
moveEditorCursorTo: (editor, pos) -> | ||
return unless editor | ||
editor.scrollToBufferPosition(pos) | ||
editor.setCursorBufferPosition(pos) | ||
return | ||
|
||
push: (loc) -> | ||
@stack.push(loc) | ||
@stack.splice(0, @stack.length - @maxSize) if @stack.length > @maxSize | ||
return |
Oops, something went wrong.