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

Commit fd77e38

Browse files
committed
Issue #114 handle ctags -n jumping to symbol
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 pattern will not be compares unless it is a line containing only a number, so will almost always return False. An additional test fixture was added for tags generated using the `ctags -R -n`.
1 parent a785dc7 commit fd77e38

File tree

4 files changed

+44
-0
lines changed

4 files changed

+44
-0
lines changed

lib/symbols-view.coffee

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,11 @@ class SymbolsView extends SelectListView
100100
# Remove leading /^ and trailing $/
101101
pattern = tag.pattern?.replace(/(^^\/\^)|(\$\/$)/g, '').trim()
102102

103+
# `ctags -excmd=number`, giving line numbers instead of patterns to locate
104+
# symbols. The line number is being interpreted as a pattern by node-ctags
105+
if not isNaN(pattern) and tag.lineNumber is parseInt(pattern)
106+
return new Point(tag.lineNumber - 1, 0)
107+
103108
return unless pattern
104109
file = path.join(tag.directory, tag.file)
105110
return unless fs.isFileSync(file)
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
function saySorry() {
2+
return "I'm sorry";
3+
}
4+
5+
var isItTooLate = saySorry();
6+
7+
var didIletYouDown = true;
8+
9+
function redeemOhReedeem() {
10+
return !didIletYouDown;
11+
}

spec/fixtures/js-excmd-number/tags

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
!_TAG_FILE_FORMAT 2 /extended format; --format=1 will not append ;" to lines/
2+
!_TAG_FILE_SORTED 1 /0=unsorted, 1=sorted, 2=foldcase/
3+
!_TAG_PROGRAM_AUTHOR Darren Hiebert /[email protected]/
4+
!_TAG_PROGRAM_NAME Exuberant Ctags //
5+
!_TAG_PROGRAM_URL http://ctags.sourceforge.net /official site/
6+
!_TAG_PROGRAM_VERSION 5.8 //
7+
didIletYouDown sorry.js 7;" v
8+
redeemOhReedeem sorry.js 9;" f
9+
saySorry sorry.js 1;" f

spec/symbols-view-spec.coffee

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,25 @@ describe "SymbolsView", ->
246246
expect(atom.workspace.getActiveTextEditor().getPath()).toBe directory.resolve("tagged-duplicate.js")
247247
expect(atom.workspace.getActiveTextEditor().getCursorBufferPosition()).toEqual [0, 4]
248248

249+
it "moves the cursor to the declaration if the tags are numbered instead of patterned", ->
250+
atom.project.setPaths([temp.mkdirSync("atom-symbols-view-js-excmd-number-")])
251+
fs.copySync(path.join(__dirname, "fixtures", "js-excmd-number"), atom.project.getPaths()[0])
252+
253+
waitsForPromise ->
254+
atom.workspace.open "sorry.js"
255+
256+
runs ->
257+
editor = atom.workspace.getActiveTextEditor()
258+
editor.setCursorBufferPosition([9, 16])
259+
spyOn(SymbolsView.prototype, "moveToPosition").andCallThrough()
260+
atom.commands.dispatch(getEditorView(), 'symbols-view:go-to-declaration')
261+
262+
waitsFor ->
263+
SymbolsView::moveToPosition.callCount is 1
264+
265+
runs ->
266+
expect(editor.getCursorBufferPosition()).toEqual [6, 0]
267+
249268
it "includes ? and ! characters in ruby symbols", ->
250269
atom.project.setPaths([temp.mkdirSync("atom-symbols-view-ruby-")])
251270
fs.copySync(path.join(__dirname, 'fixtures', 'ruby'), atom.project.getPaths()[0])

0 commit comments

Comments
 (0)