-
Notifications
You must be signed in to change notification settings - Fork 124
External tool support #1756
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
External tool support #1756
Conversation
ae32955
to
f3bfb4c
Compare
Nice to see this coming together. I have some initial thoughts at a high level, happy to share if you're ready for that. |
Sure, high level thoughts would be great! |
This is all pretty half baked and I only glanced through what you have, so you may have implemented some of this and I didn't see it.
|
dartdoc:
tools:
drill:
command: ['bin/drill.dart']
description: 'Makes a hole'
hammer:
macos: ['/bin/sh', '-c', 'echo']
linux: ['/bin/sh', '-c', 'echo']
windows: ['C:\\Windows\\System32\\cmd.exe', '/c', 'echo']
description: 'Works on everything' Creating that with the dartdoc options structure seems complicated though: I'm not sure how well it handles things that have different types (e.g. a map with lists of strings OR strings as values).
|
Multiplatform and complicated structures: I just added the ability to convert YamlMaps to arbitrary structures in DartdocOptions, and that may make it easier. See the implementation of the categories option from #1754. I don't have a strong opinion on the structure, other than what I see in your example seems close but not quite. I'll think about it. Restrictions: Yeah, I wasn't clear. I meant the ability to have tools disabled entirely, and to restrict tools to a subdirectory of the package. Comment references: I am not certain but I think we may still do some checks around the analyzer data for comment references, and use them as a last resort for resolution. Adding tests particularly around the case where a tool directive changes the relative offset of an existing comment reference, adding a comment reference as part of a tool directive, and adding a comment reference as part of a tool directive when the comment otherwise has no references would be good tests. |
A "disabled" tool just doesn't appear in the map. We could have a I hadn't thought about restricting tools to a subdir: do you mean that the executable can only appear in a subdir? Or that it is basically chrooted to a subdir? I think that since the map is explicit about the executable, that restricting it to come from a subdir is redundant. chroot-style restrictions won't work on Windows, and I don't know any other good way to restrict access to a process. Comment references: So you're worried about changing the offsets to references? Tools doesn't do anything different from the |
I was more talking about a way to disable tools from the command line. But maybe it's not as important as I thought given the other considerations you mentioned. As for restricting which tools get run, I suppose it is rather redundant. Restricting tool access to a subdirectory doesn't stop that tool from forking off something arbitrary either. Good point on examples. The main thing I am curious about then is adding (and removing?) comment references. |
a7a01a9
to
5c970c9
Compare
@jcollins-g, How do I update the docs that failed to compare in this build? I've run |
@gspencergoog There's currently no way to do that without using the stable version of the SDK. I use a script to switch versions so I can do it quickly. Basically, switch to dart 2, run pub get and then pub run grinder update-test-package-docs, and that will update the right version. |
88283d1
to
3a5b586
Compare
OK, I think this is ready for more detailed review. I've modified the options structure to be what I outlined above: thanks for that Categories work, @jcollins-g that really made it work well! I tried to think of better ways to organize it, and I think it works as-is. I did include a "description" field, although I don't really know what to use that for yet. Maybe it should just be removed. |
I was out sick two days, but I will try to get to this review today. Sorry for the delay. |
No worries. I just realized that I haven't gone back through and removed unnecessary type annotations, as is the dartdoc style. No need to bother commenting on those, I'll do that. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think adding a the tests I mentioned would be great.
Also, a blurb about the tool directive in README.md seems like a good idea to me.
@@ -110,6 +110,103 @@ class CategoryConfiguration { | |||
} | |||
} | |||
|
|||
class ToolDefinition { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would be nice if there were some brief docs for the new classes, at least
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
.map((String mapKey, String mapValue) => new MapEntry<String, String>( | ||
mapKey, pathContext.canonicalize(resolveTildePath(mapValue)))) | ||
.cast<String, String>() as T; | ||
.map<String, String>((String key, String value) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ah yes, better
test("can invoke a tool", () { | ||
expect(invokeTool.documentation, contains('## `Yes it is!`')); | ||
}); | ||
test(r"can invoke a tool with no $INPUT or args", () { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would like to see tests of cases where a comment reference is added/removed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, I added that, but I'm not sure how to verify that the link was actually recognized and linked.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, I've updated the README too. PTAL. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM after last test tweak
test("can invoke a tool", () { | ||
expect(invokeTool.documentation, contains('## `Yes it is!`')); | ||
}); | ||
test(r"can invoke a tool with no $INPUT or args", () { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, last test tweak is in. @jcollins-g Feel free to commit this. |
This adds the ability to invoke external tools on the text between the
{@tool ...}
and{@end-tool}
directives. The available tools are defined in thedartdoc_options.yaml
file, under atools:
section that maps tool names to executable locations. If a tool executable ends in ".dart", then the tool will be invoked with the dart executable automatically.For example, if the "sort" tool was mapped to "/bin/sort" (on Unix), then the following input:
would result in output something like:
Fruit