From a1864343acfeab7ed71629940b4968afcb0c9922 Mon Sep 17 00:00:00 2001 From: Max Shenfield Date: Sat, 5 Dec 2015 03:09:24 -0600 Subject: [PATCH] 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 comparison to parseInt(tag.pattern) (NaN) returns False. An additional test fixture was added for tags generated using the `ctags -R -n`. --- lib/symbols-view.coffee | 4 ++++ spec/fixtures/js-excmd-number/sorry.js | 11 +++++++++++ spec/fixtures/js-excmd-number/tags | 9 +++++++++ spec/symbols-view-spec.coffee | 19 +++++++++++++++++++ 4 files changed, 43 insertions(+) create mode 100644 spec/fixtures/js-excmd-number/sorry.js create mode 100644 spec/fixtures/js-excmd-number/tags diff --git a/lib/symbols-view.coffee b/lib/symbols-view.coffee index a26797d..dd25e7e 100644 --- a/lib/symbols-view.coffee +++ b/lib/symbols-view.coffee @@ -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) diff --git a/spec/fixtures/js-excmd-number/sorry.js b/spec/fixtures/js-excmd-number/sorry.js new file mode 100644 index 0000000..adb42e1 --- /dev/null +++ b/spec/fixtures/js-excmd-number/sorry.js @@ -0,0 +1,11 @@ +function saySorry() { + return "I'm sorry"; +} + +var isItTooLate = saySorry(); + +var didIletYouDown = true; + +function redeemOhReedeem() { + return !didIletYouDown; +} diff --git a/spec/fixtures/js-excmd-number/tags b/spec/fixtures/js-excmd-number/tags new file mode 100644 index 0000000..42be080 --- /dev/null +++ b/spec/fixtures/js-excmd-number/tags @@ -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 /dhiebert@users.sourceforge.net/ +!_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 diff --git a/spec/symbols-view-spec.coffee b/spec/symbols-view-spec.coffee index a75599b..7f0a461 100644 --- a/spec/symbols-view-spec.coffee +++ b/spec/symbols-view-spec.coffee @@ -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])