forked from atom/symbols-view
-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
go-to-declaration support column catch crag command stderr use -R instead of (fs-plus).traverseTreeSync better log search tag limit max
- Loading branch information
1 parent
26eb10b
commit 4e4df47
Showing
5 changed files
with
80 additions
and
83 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,93 +1,66 @@ | ||
|
||
TagGenerator = require './tag-generator' | ||
fs = require 'fs-plus' | ||
minimatch = require "minimatch" | ||
|
||
{Point} = require "atom" | ||
matchOpt = {matchBase: true} | ||
|
||
module.exports = | ||
activate: (build) -> | ||
activate: () -> | ||
@cachedTags = {} | ||
|
||
if build | ||
@rebuild() | ||
|
||
deactivate: -> | ||
@cachedTags = null | ||
|
||
#options = { partialMatch: true } | ||
#options = { partialMatch: true, maxItems } | ||
findTags: (prefix, options) -> | ||
tags = [] | ||
empty = true | ||
for key, value of @cachedTags | ||
tags.push (value.filter (x) -> | ||
if options and options.partialMatch == true | ||
return x.name.indexOf(prefix) == 0 | ||
else | ||
return x.name == prefix | ||
)... | ||
empty = false | ||
for tag in value | ||
if options?.partialMatch and tag.name.indexOf(prefix) == 0 | ||
tags.push tag | ||
else if tag.name == prefix | ||
tags.push tag | ||
return tags if options?.maxItems and tags.length == options.maxItems | ||
|
||
#TODO: prompt in editor | ||
console.warn("[atom-ctags:findTags] tags empty, did you RebuildTags?") if empty | ||
return tags | ||
|
||
# Private: Checks whether the file is blacklisted | ||
# | ||
# Returns {Boolean} that defines whether the file is blacklisted | ||
FileBlacklisted: (blacklist, f, opt) -> | ||
for blacklistGlob in blacklist | ||
if minimatch(f, blacklistGlob, opt) | ||
return true | ||
return false | ||
|
||
listTreeSync: (rootPath) -> | ||
blacklist = (atom.config.get("atom-ctags.fileBlacklist") or "") | ||
.split "," | ||
.map (s) -> s.trim() | ||
|
||
opt = {matchBase: true} | ||
paths = [] | ||
|
||
onPath = (filePath) => | ||
if @FileBlacklisted(blacklist, filePath, opt) | ||
return false | ||
paths.push(filePath) | ||
return true | ||
|
||
onDirectory = (dirPath) => | ||
return not @FileBlacklisted(blacklist, dirPath, opt) | ||
|
||
fs.traverseTreeSync(rootPath, onPath, onDirectory) | ||
return paths | ||
|
||
rebuild: -> | ||
|
||
list = @listTreeSync(atom.project.getPath()) | ||
@generateTags(f) for f in list | ||
|
||
getScopeName: -> atom.workspace.getActiveEditor()?.getGrammar()?.scopeName | ||
|
||
getTagLine: (tag) -> | ||
return unless tag.pattern | ||
file = atom.project.resolve(tag.file) | ||
return unless fs.isFileSync(file) | ||
if not fs.isFileSync(file) | ||
console.error "[atom-ctags:getTagLine] @#{tag.file}@ not exist?" | ||
return | ||
|
||
debug = [] | ||
for line, index in fs.readFileSync(file, 'utf8').split('\n') | ||
if line.indexOf(tag.pattern) == 0 | ||
return new Point(index, 0) | ||
tag.position.row = index | ||
return true | ||
|
||
console.error "[atom-ctags:getTagLine] @#{tag.pattern}@ not find in @#{tag.file}@?" | ||
return true | ||
|
||
generateTags:(filePath, callback) -> | ||
new TagGenerator(filePath, @getScopeName()).generate().done (matches) => | ||
tags = [] | ||
for match in matches | ||
match.position = @getTagLine(match) | ||
if match.position | ||
tags.push(match) | ||
generateTags:(path, callback) -> | ||
delete @cachedTags[path] | ||
|
||
@cachedTags[filePath] = tags | ||
if callback | ||
callback(tags) | ||
scopeName = atom.workspace.getActiveEditor()?.getGrammar()?.scopeName | ||
new TagGenerator(path, scopeName).generate().done (tags) => | ||
ret = [] if callback | ||
for tag in tags | ||
if @getTagLine(tag) | ||
ret.push tag if callback | ||
data = @cachedTags[tag.file] | ||
if not data | ||
data = [] | ||
@cachedTags[tag.file] = data | ||
data.push tag | ||
|
||
callback?(ret) | ||
|
||
getOrCreateTags: (filePath, callback) -> | ||
tags = @cachedTags[filePath] | ||
if tags | ||
if callback | ||
callback(tags) | ||
return | ||
generateTags(filePath, callback) | ||
return callback?(tags) if tags | ||
@generateTags(filePath, callback) |
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