Skip to content
This repository has been archived by the owner on Dec 15, 2022. It is now read-only.

Commit

Permalink
Issue #114 handle ctags -n jumping to symbol
Browse files Browse the repository at this point in the history
symbols-view expects there to be patterns in `tags` files. This is the default behavior when running ctags (you can also explictly set it with the -F, or --excmd=pattern options). When running ctags with the number option (-n or --excmd=number), e.g ctags -R -n, numbers are used instead of patterns to identify lines.

This package should expect and accept both formats. To determine which format a tag uses, check if tag.pattern and tag.lineNumber represent the same number.  If so create a Point based on line number instead of pattern.  `node-ctags` populates the tag.pattern parameter with the stringified lineNumber if `ctags -n` is run. When a tag has a pattern instead of a lineNumber,  tag.LineNumber defaults to 0, and comparison to parseInt(tag.pattern) (NaN) returns False.

An additional test fixture was added for tags generated using the `ctags -R -n`.
  • Loading branch information
mshenfield committed Dec 5, 2015
1 parent a785dc7 commit a186434
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/symbols-view.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,10 @@ class SymbolsView extends SelectListView
# Remove leading /^ and trailing $/
pattern = tag.pattern?.replace(/(^^\/\^)|(\$\/$)/g, '').trim()

# `ctags -excmd=number`, giving line numbers instead of patterns to locate
# symbols. The line number is being interpreted as a pattern by node-ctags
return new Point(tag.lineNumber - 1, 0) if tag.lineNumber is parseInt(pattern)

return unless pattern
file = path.join(tag.directory, tag.file)
return unless fs.isFileSync(file)
Expand Down
11 changes: 11 additions & 0 deletions spec/fixtures/js-excmd-number/sorry.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
function saySorry() {
return "I'm sorry";
}

var isItTooLate = saySorry();

var didIletYouDown = true;

function redeemOhReedeem() {
return !didIletYouDown;
}
9 changes: 9 additions & 0 deletions spec/fixtures/js-excmd-number/tags
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
!_TAG_FILE_FORMAT 2 /extended format; --format=1 will not append ;" to lines/
!_TAG_FILE_SORTED 1 /0=unsorted, 1=sorted, 2=foldcase/
!_TAG_PROGRAM_AUTHOR Darren Hiebert /[email protected]/
!_TAG_PROGRAM_NAME Exuberant Ctags //
!_TAG_PROGRAM_URL http://ctags.sourceforge.net /official site/
!_TAG_PROGRAM_VERSION 5.8 //
didIletYouDown sorry.js 7;" v
redeemOhReedeem sorry.js 9;" f
saySorry sorry.js 1;" f
19 changes: 19 additions & 0 deletions spec/symbols-view-spec.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,25 @@ describe "SymbolsView", ->
expect(atom.workspace.getActiveTextEditor().getPath()).toBe directory.resolve("tagged-duplicate.js")
expect(atom.workspace.getActiveTextEditor().getCursorBufferPosition()).toEqual [0, 4]

it "moves the cursor to the declaration if the tags are numbered instead of patterned", ->
atom.project.setPaths([temp.mkdirSync("atom-symbols-view-js-excmd-number-")])
fs.copySync(path.join(__dirname, "fixtures", "js-excmd-number"), atom.project.getPaths()[0])

waitsForPromise ->
atom.workspace.open "sorry.js"

runs ->
editor = atom.workspace.getActiveTextEditor()
editor.setCursorBufferPosition([9, 16])
spyOn(SymbolsView.prototype, "moveToPosition").andCallThrough()
atom.commands.dispatch(getEditorView(), 'symbols-view:go-to-declaration')

waitsFor ->
SymbolsView::moveToPosition.callCount is 1

runs ->
expect(editor.getCursorBufferPosition()).toEqual [6, 0]

it "includes ? and ! characters in ruby symbols", ->
atom.project.setPaths([temp.mkdirSync("atom-symbols-view-ruby-")])
fs.copySync(path.join(__dirname, 'fixtures', 'ruby'), atom.project.getPaths()[0])
Expand Down

0 comments on commit a186434

Please sign in to comment.