From d798bd6bd9c1f4375ed01a886e4375ee02fbe67c Mon Sep 17 00:00:00 2001 From: Patrick Thomson Date: Tue, 10 Mar 2020 20:39:04 -0400 Subject: [PATCH] Slice out the line associated with a tag. --- cli/src/tests/tags_test.rs | 1 + tags/src/lib.rs | 7 ++++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/cli/src/tests/tags_test.rs b/cli/src/tests/tags_test.rs index dac0a90a..9b4042d3 100644 --- a/cli/src/tests/tags_test.rs +++ b/cli/src/tests/tags_test.rs @@ -56,5 +56,6 @@ fn test_tags_python() { ); assert_eq!(tags[0].docs.as_ref().unwrap(), "Data about a customer"); + assert_eq!(tags[0].line, "class Customer:"); assert_eq!(tags[1].docs.as_ref().unwrap(), "Get the customer's age"); } diff --git a/tags/src/lib.rs b/tags/src/lib.rs index e90352a0..afb7e376 100644 --- a/tags/src/lib.rs +++ b/tags/src/lib.rs @@ -224,6 +224,11 @@ where let config = &self.config; let tag_from_node = |node: Node, kind: TagKind| -> Option { let name = str::from_utf8(&source[name_node?.byte_range()]).ok()?; + let mut line_range = node.byte_range(); + if line_range.len() > 180 { + line_range.end = line_range.start + 180; + } + let line = str::from_utf8(&source[line_range]).ok()?.lines().next()?; let docs = doc_node .and_then(|n| str::from_utf8(&source[n.byte_range()]).ok()) .map(|s| { @@ -235,7 +240,7 @@ where }); Some(Tag { name, - line: "TODO", + line, loc: loc_for_node(node), kind: kind, docs,