From 784160320309212d0acf865092133ba55980c605 Mon Sep 17 00:00:00 2001 From: yongkangchen Date: Sun, 6 Jul 2014 22:28:34 +0800 Subject: [PATCH] use crag command param to parse line number MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit −−fields=[+|−]flags n Line number of tag definition --- lib/file-view.coffee | 5 ++--- lib/symbols-view.coffee | 11 ++++------- lib/tag-generator.coffee | 19 +++++++++++++++++-- 3 files changed, 23 insertions(+), 12 deletions(-) diff --git a/lib/file-view.coffee b/lib/file-view.coffee index 48d52fc..bb95289 100644 --- a/lib/file-view.coffee +++ b/lib/file-view.coffee @@ -27,9 +27,8 @@ class FileView extends SymbolsView @span pattern, class: 'pull-right' @div class: 'secondary-line', => - @span file, class: 'pull-left' - # @span "Line #{position.row + 1}", class: 'pull-left' - # @span file, class: 'pull-right' + @span "Line #{position.row + 1}", class: 'pull-left' + @span file, class: 'pull-right' toggle: -> if @hasParent() diff --git a/lib/symbols-view.coffee b/lib/symbols-view.coffee index b55efb9..f33c3b2 100644 --- a/lib/symbols-view.coffee +++ b/lib/symbols-view.coffee @@ -1,5 +1,5 @@ {$$, SelectListView} = require 'atom' -fs = require 'fs-plus' +fs = null module.exports = class SymbolsView extends SelectListView @@ -28,6 +28,9 @@ class SymbolsView extends SelectListView super confirmed : (tag) -> + if fs == null + fs = require 'fs-plus' + if tag.file and not fs.isFileSync(atom.project.resolve(tag.file)) @setError('Selected file does not exist') setTimeout((=> @setError()), 2000) @@ -45,12 +48,6 @@ class SymbolsView extends SelectListView atom.workspaceView.open(tag.file).done => - if position.row == -1 - regex = new RegExp(tag.pattern.replace(/[-\/\\^$*+?.()|[\]{}]/g, '\\$&')) - atom.workspace.getActiveEditor().buffer.scan regex , (obj)=> - position.row = obj.range.start.row - obj.stop() - @moveToPosition(position) if position @stack.push(previous) diff --git a/lib/tag-generator.coffee b/lib/tag-generator.coffee index 25c05a0..d577797 100644 --- a/lib/tag-generator.coffee +++ b/lib/tag-generator.coffee @@ -2,6 +2,9 @@ Q = require 'q' path = require 'path' +TAG_LINE = "line:" +TAG_LINE_LENGTH = TAG_LINE.length + module.exports = class TagGenerator constructor: (@path, @scopeName) -> @@ -13,6 +16,18 @@ class TagGenerator name: sections.shift() file: sections.shift() } + + i = sections.length - 1 + + while i >= 0 + row = sections[i] + if row.indexOf(TAG_LINE) == 0 + row = row.substr(TAG_LINE_LENGTH) - 1 + break + else + row = -1 + --i + pattern = sections.join("\t") #match /^ and trailing $/; @@ -21,7 +36,7 @@ class TagGenerator tag.pattern = pattern.match(/^\/\^(.*)(\/;")/)?[1] if tag.pattern - tag.position = new Point(-1, tag.pattern.indexOf(tag.name)) + tag.position = new Point(row, tag.pattern.indexOf(tag.name)) else return null return tag @@ -58,7 +73,7 @@ class TagGenerator deferred = Q.defer() tags = [] command = path.resolve(__dirname, '..', 'vendor', "ctags-#{process.platform}") - args = ['--fields=+KS'] + args = ['--fields=+KSn'] if atom.config.get('atom-ctags.useEditorGrammarAsCtagsLanguage') if language = @getLanguage()