From 6b51f2ed4cbc82088407f3dd3ca0b7dd8f25555d Mon Sep 17 00:00:00 2001 From: John Castronuovo Date: Sat, 5 Sep 2020 13:32:35 +0200 Subject: [PATCH 1/6] feat(project): add option for create separate tags for working directory project --- bin/tags.dart | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/bin/tags.dart b/bin/tags.dart index 904d8d4..96b5700 100644 --- a/bin/tags.dart +++ b/bin/tags.dart @@ -135,6 +135,8 @@ class Ctags { ]); } + final project = options['project'] as String; + // import, export, part, part of, library directives await Future.forEach(unit.directives, (Directive d) async { String tag, importDirective, display; @@ -147,12 +149,15 @@ class Ctags { if (display.contains('dart:')) { tag = 'D'; + } else if (project != null && display.contains('package:$project')) { + tag = 'R'; } else if (display.contains('package:')) { tag = 'U'; } else { // local tag = 'L'; } + importDirective = 'directive:import'; } else if (d is ExportDirective) { tag = 't'; @@ -507,8 +512,10 @@ class Ctags { void main([List args]) { final parser = ArgParser(); + parser.addOption('output', abbr: 'o', help: 'Output file for tags (default: stdout)', valueHelp: 'FILE'); + parser.addOption('project', abbr: 'p', help: 'add separate category for project import directives'); parser.addFlag('follow-links', help: 'Follow symbolic links (default: false)', negatable: false); parser.addFlag('include-hidden', @@ -520,12 +527,15 @@ void main([List args]) { parser.addFlag('skip-sort', help: 'Skip sorting the output (default: false)', negatable: false); parser.addFlag('help', abbr: 'h', help: 'Show this help', negatable: false); + final options = parser.parse(args); + if (options['help'] as bool) { print( 'Usage:\n\tdart_ctags [OPTIONS] [FILES...]\n\tpub global run dart_ctags:tags [OPTIONS] [FILES...]\n'); print(parser.usage); exit(0); } + Ctags(options).generate(); } From 03abe1a9f4f00511ac5701b6940b65f6f97f6e92 Mon Sep 17 00:00:00 2001 From: John Castronuovo Date: Sat, 5 Sep 2020 13:34:04 +0200 Subject: [PATCH 2/6] chore(pubspec): bump to 1.2.2 and rm quiver dep --- pubspec.yaml | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/pubspec.yaml b/pubspec.yaml index 0f0e8d8..6ea3a1e 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,15 +1,14 @@ homepage: https://github.com/nerdrew/dart-ctags description: ctags compatible tag file generator for dart code name: dart_ctags -version: 1.2.1 +version: 1.2.2 environment: sdk: ">=2.0.0 <3.0.0" executables: dart_ctags: tags dependencies: - analyzer: ^0.40.0 + analyzer: ^0.40.2 path: ^1.7.0 - quiver: ^2.1.3 args: ^1.6.0 dev_dependencies: pedantic: ^1.9.2 From 4504b943f77fc7bfabbee0cd60a63f70c035368c Mon Sep 17 00:00:00 2001 From: John Castronuovo Date: Wed, 9 Sep 2020 11:53:24 +0200 Subject: [PATCH 3/6] feat(imports): trim dart: or package: for display string --- bin/tags.dart | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/bin/tags.dart b/bin/tags.dart index 96b5700..8646985 100644 --- a/bin/tags.dart +++ b/bin/tags.dart @@ -149,9 +149,12 @@ class Ctags { if (display.contains('dart:')) { tag = 'D'; + display = display.substring('dart:'.length + 1); } else if (project != null && display.contains('package:$project')) { + display = display.substring('package:$project/'.length + 1); tag = 'R'; } else if (display.contains('package:')) { + display = display.substring('package:'.length + 1); tag = 'U'; } else { // local @@ -515,7 +518,8 @@ void main([List args]) { parser.addOption('output', abbr: 'o', help: 'Output file for tags (default: stdout)', valueHelp: 'FILE'); - parser.addOption('project', abbr: 'p', help: 'add separate category for project import directives'); + parser.addOption('project', + abbr: 'p', help: 'add separate category for project import directives'); parser.addFlag('follow-links', help: 'Follow symbolic links (default: false)', negatable: false); parser.addFlag('include-hidden', From 05f5085b286f297affaf4c29d4521ab9e8e7caab Mon Sep 17 00:00:00 2001 From: John Castronuovo Date: Tue, 6 Oct 2020 20:36:48 +0200 Subject: [PATCH 4/6] refactor(tags): update relative path tag to V --- bin/tags.dart | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bin/tags.dart b/bin/tags.dart index 8646985..a8282e8 100644 --- a/bin/tags.dart +++ b/bin/tags.dart @@ -157,8 +157,8 @@ class Ctags { display = display.substring('package:'.length + 1); tag = 'U'; } else { - // local - tag = 'L'; + // relative + tag = 'V'; } importDirective = 'directive:import'; From 2f22248905a1e0428f7475143f231d1818aa4840 Mon Sep 17 00:00:00 2001 From: John Castronuovo Date: Fri, 12 Mar 2021 17:28:00 +0100 Subject: [PATCH 5/6] chore(pubspec): update deps --- pubspec.yaml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/pubspec.yaml b/pubspec.yaml index 6ea3a1e..d6781cb 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,14 +1,14 @@ homepage: https://github.com/nerdrew/dart-ctags description: ctags compatible tag file generator for dart code name: dart_ctags -version: 1.2.2 +version: 1.2.3 environment: sdk: ">=2.0.0 <3.0.0" executables: dart_ctags: tags dependencies: - analyzer: ^0.40.2 - path: ^1.7.0 - args: ^1.6.0 + analyzer: ^1.1.0 + path: ^1.8.0 + args: ^2.0.0 dev_dependencies: - pedantic: ^1.9.2 + pedantic: ^1.11.0 From 6b8cf4333941c0793826d576eb2d583d427a849c Mon Sep 17 00:00:00 2001 From: John Castronuovo Date: Fri, 12 Mar 2021 17:28:14 +0100 Subject: [PATCH 6/6] feat(tags): add tags for Extension declarations --- bin/tags.dart | 72 ++++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 57 insertions(+), 15 deletions(-) diff --git a/bin/tags.dart b/bin/tags.dart index a8282e8..818121f 100644 --- a/bin/tags.dart +++ b/bin/tags.dart @@ -57,8 +57,7 @@ class Ctags { '!_TAG_FILE_SORTED\t1\t/0=unsorted, 1=sorted, 2=foldcase/' ]; - Future.wait(dirs.map(addFileSystemEntity)) - .then((Iterable>> files) { + Future.wait(dirs.map(addFileSystemEntity)).then((Iterable>> files) { files.forEach((Iterable> file) { file.forEach((Iterable fileLines) => lines.addAll(fileLines)); }); @@ -89,8 +88,7 @@ class Ctags { }).toList()); } else if (type == FileSystemEntityType.file) { return Future.value([await parseFile(File(name))]); - } else if (type == FileSystemEntityType.link && - options['follow-links'] as bool) { + } else if (type == FileSystemEntityType.link && options['follow-links'] as bool) { return addFileSystemEntity(Link(name).targetSync()); } else { return Future.value([]); @@ -114,8 +112,7 @@ class Ctags { ParseStringResult result; CompilationUnit unit; try { - result = - an.parseFile(path: file.path, featureSet: FeatureSet.fromEnableFlags([])); + result = an.parseFile(path: file.path, featureSet: FeatureSet.fromEnableFlags([])); unit = result.unit; } catch (e) { print('ERROR: unable to generate tags for ${file.path}'); @@ -177,8 +174,7 @@ class Ctags { } else if (d is PartOfDirective) { tag = 'p'; display = d.childEntities - .where((element) => - '$element' != 'part' && '$element' != 'of' && '$element' != ';') + .where((element) => '$element' != 'part' && '$element' != 'of' && '$element' != ';') .join(' ') .trim(); } else if (d is LibraryDirective) { @@ -295,6 +291,56 @@ class Ctags { ]); } }); + } else if (declaration is ExtensionDeclaration) { + lines.add([ + '${declaration.name.name} on ${declaration.extendedType}', + path.relative(file.path, from: root), + '/${klass.matchAsPrefix(declaration.toSource())[0]}/;"', + 'X', + 'access:${declaration.name?.name[0] == '_' ? 'private' : 'public'}', + options['line-numbers'] as bool + ? 'line:${unit.lineInfo.getLocation(declaration.offset).lineNumber}' + : '', + 'type:extension', + ]); + + declaration.members.forEach((member) { + if (member is MethodDeclaration) { + var tag = 'm'; + if (member.isStatic) { + tag = 'M'; + } + // better if static is least preferred + if (member.isOperator) { + tag = 'o'; + } + if (member.isGetter) { + tag = 'g'; + } + if (member.isSetter) { + tag = 's'; + } + if (member.isAbstract) { + tag = 'a'; + } + + var memberSource = member.toSource(); + + lines.add([ + member.name.name, + path.relative(file.path, from: root), + '/${method.matchAsPrefix(memberSource)[0]}/;"', + tag, + 'access:${member.name.name[0] == '_' ? 'private' : 'public'}', + options['line-numbers'] as bool + ? 'line:${unit.lineInfo.getLocation(member.offset).lineNumber}' + : '', + 'extension:${declaration.name.name} on ${declaration.extendedType}', + 'signature:${tag == 'g' ? '' : member.parameters.toString()}', + 'type:${member.returnType.toString()}' + ]); + } + }); } else if (declaration is FunctionDeclaration) { lines.add([ declaration.name.name, @@ -520,16 +566,12 @@ void main([List args]) { abbr: 'o', help: 'Output file for tags (default: stdout)', valueHelp: 'FILE'); parser.addOption('project', abbr: 'p', help: 'add separate category for project import directives'); - parser.addFlag('follow-links', - help: 'Follow symbolic links (default: false)', negatable: false); + parser.addFlag('follow-links', help: 'Follow symbolic links (default: false)', negatable: false); parser.addFlag('include-hidden', help: 'Include hidden directories (default: false)', negatable: false); parser.addFlag('line-numbers', - abbr: 'l', - help: 'Add line numbers to extension fields (default: false)', - negatable: false); - parser.addFlag('skip-sort', - help: 'Skip sorting the output (default: false)', negatable: false); + abbr: 'l', help: 'Add line numbers to extension fields (default: false)', negatable: false); + parser.addFlag('skip-sort', help: 'Skip sorting the output (default: false)', negatable: false); parser.addFlag('help', abbr: 'h', help: 'Show this help', negatable: false); final options = parser.parse(args);