Commit Graph

117 Commits

Author SHA1 Message Date
Robin Krahl
0c38bf9606
Remove suffix from duplicate members
We use the HTML ID of a member element to get its name.  If there are
multiple members with the same type and name (e. g. from a Deref
implementation), the ID has a suffix to make it unique.  Previosuly, we
just interpreted this suffix as part of the name.  With this patch, we
strip the suffix and only use the actual name.
2020-09-17 17:04:53 +02:00
Robin Krahl
642bec6687
Release v0.3.0
This minor release adds support for Rust 1.46.0 and significantly
improves the test suite.
2020-09-11 21:58:29 +02:00
Robin Krahl
c97ac33dc9
Add test case for Index::find
As we only support the new search index format introduced in April 2020,
the test is only run for Rust >= 1.44.0.
2020-09-11 21:11:07 +02:00
Robin Krahl
77a9163bb1
Add test case for Parser::find_member 2020-09-11 20:55:23 +02:00
Robin Krahl
229b1bdd5c
Add test suite for Rust 1.46.0 2020-09-11 20:30:19 +02:00
Robin Krahl
71280ddb16
Refactor member lookup
Up to rustdoc version 1.45.2, the code element containing the definition
of a member always had the ID "<name>.v".  This ID has been dropped in
rustdoc 1.46.0.  Therefore we now look for members by searching for the
heading which has the id "<ty>.<name>" (for all possible types).
2020-09-11 20:30:12 +02:00
Robin Krahl
628377c83b
Refactor test suite to check multiple versions
This patch refactors the test suite:
- Instead of always generating the documentation with the available
  rustdoc version, we now store generated documentation for all
  supported rustdoc versions in the test/html directory.
- Instead of using one snapshot per test case, we now use one snapshot
  per test case and rustdoc version.
2020-09-11 20:30:05 +02:00
Robin Krahl
5b2003b979
Respect item type in documentation lookup
Sometimes, there might be multiple items with the same name, for example
std::u8 is both a module and a primitive.  Previously, we could not
determine which one Source::load_doc would return.  With this patch, we
add the ty parameter that can be used to filter by the item type.
2020-08-18 22:30:55 +02:00
Robin Krahl
c672a65d59
Add item type to the IndexItem struct
Previously, we only used the name and the description to represent index
items.  Therefore we consider e. g. the std::u8 module and the std::u8
primitive to be the same.  With this patch, we also take the item type
into account when comparing index items.
2020-08-18 21:55:00 +02:00
Robin Krahl
8e97ad269b
Store member groups in BTreeMap
With this patch, we change the type of the Doc::groups field to
BTreeMap<ItemType, Vec<MemberGroup>>.  This makes it clearer and easier
to read.  We also reorder the ItemType module so that the output order
of the member groups is not changed by this patch.
2020-08-17 13:53:41 +02:00
Robin Krahl
e74ef86ebe
Move ItemType u8 representations into index module
Previosuly, we used the u8 values for the ItemType variants used in the
search index as the discriminant.  But as the ID used in the search
index is an implementation detail of the index parser, this patch moves
the mapping to the index module.
2020-08-17 13:42:10 +02:00
Robin Krahl
861a2e8861
Wrap code snippets in Code struct
In commit 729414cbfe16324379ac0b886ba65349bbf44ff6, we introduced the
Text struct that wraps HTML and plain text to make it clear what data we
store in the fields of the Doc and Example structs.  This patch adds the
Code struct that stores a plain-text representation of code snippets to
make the structs even clearer and to make it easier to transition to
plain-text-only code, e. g. provided by the new JSON backend.
2020-08-17 12:01:23 +02:00
Robin Krahl
fefac9f2fc
Move doc::ItemType::group_id to the parser module
Previously, the doc::ItemType::group_id method returned the ID of the
section for the item type in the HTML documentation files.  This patch
refactors the method into the get_item_group_id function in the parser
module as it is an implementation detail of the HTML parser.
2020-08-17 11:45:46 +02:00
Robin Krahl
ebc9c58838
Remove doc::ItemType::class method
We only query the item class for two variants.  It is easier to hardcode
this two classes instead of providing all available classes.
2020-08-17 11:40:33 +02:00
Robin Krahl
473b091fca
Move parser utility methods into submodule
This patch introduces the parser::util mod with utility methods for HTML
parsing.  These utility methods are members of the new NodeRefExt trait
that is implemented for kuchiki::NodeRef and kuchiki::NodeDataRef<T>.
2020-08-17 11:31:47 +02:00
Robin Krahl
1e9da34694
Refactor Parser::parse_item_doc
This patch simplifies the Parser::parse_item_doc function by collecting
all members before pushing them into the member groups.
2020-08-17 11:08:09 +02:00
Robin Krahl
93575ab452
Move public parser interface into Parser struct
To avoid parsing the same file multiple times under some circumstances,
we introduce the Parser struct that stores the document node and
provides the public interface of the parser module.
2020-08-17 11:08:03 +02:00
Robin Krahl
d1c171c385
Refactor documentation lookup into source
Previously, the Crate, Item and Doc struct made assumptions about the
structure of the documentation source by calling the parser directly.
This works with our current setup with only one documentation format and
one documentation source.  But as we intend to add other formats in the
future, we refactor the documentation lookup into the source module
where the format and the source can be taken into account.
2020-08-15 00:18:20 +02:00
Robin Krahl
76845785ee
Release v0.2.0
This minor release adds support for syntax highlighting of code snippets
and for configuration files.
2020-08-11 10:31:03 +02:00
Robin Krahl
3affe94234
Update installation instructions
This patch updates the installation instructions with information on the
AUR packgage and on the tarball downloads.
2020-08-11 09:59:43 +02:00
Robin Krahl
28c025fd4f
Add --width and --max-width options
This patch adds the --width option to select a fixed output width and
the --max-width to set a maximum output width if the width is
dynamically set using the terminal size.
2020-08-11 09:42:21 +02:00
Robin Krahl
1a518d7509
Add integration tests
This patch adds an integration test suite using the insta crate for
snapshot testing.  The test suite is tested for all supported Rust
versions and should always succeed for the MSRV (currently 1.40.0) and
the current stable Rust version.

However there are some minor changes in the configuration format between
Rust versions, so tests that don’t work on all supported Rust versions
are marked with the ignore attribute.  But even the ignored tests should
work on the stable Rust release.
2020-08-11 09:31:20 +02:00
Robin Krahl
17e407d6b1
Improve line breaks for code
kuchiki’s NodeRef::text_contents() implementation does not take into
account the value of the display attribute or line breaks caused by br
elements.  Therefore we have to implement our own converter that
produces readable output for the HTML code generated by rustdoc.
2020-08-11 01:08:00 +02:00
Robin Krahl
7d1bf00d31
Show links in item description
In commit 81c9cf53d6, I accidentally
disabled the links when rendering the item description.  This patch
fixes this mistake.
2020-08-11 01:02:00 +02:00
Robin Krahl
a6b2d570b3
Add --config-file option to set custom config file
This patch adds the --config-file option that allows the user to specify
a custom configuration file (or to disable reading configuration files
if the option is set to "-").
2020-08-10 23:49:13 +02:00
Robin Krahl
e5ee4df73b
Add support for configuration files
With this patch, we load defaults for the command-line arguments from
the configuration file located in the user configuration directory
according to the XDG Base Directory Specification.
2020-08-10 23:37:26 +02:00
Robin Krahl
3a20d662c5
Move command-line arguments into args module
This patch crates the args module, renames the Opt struct to Args and
moves it to the new args module.  This makes the main.rs file easier to
read and allows us to add more details to the Args struct in the future.
2020-08-10 23:07:57 +02:00
Robin Krahl
c48711f3cf
Add --no-syntax-highlight and --theme options
This patch adds two new command-line options for the rich text viewer:
--no-syntax-highlight and --theme.  --no-syntax-highlight disables the
syntax highlighting for code snippets.  --theme selects a color theme
for the syntax highlighting.
2020-08-10 21:46:23 +02:00
Robin Krahl
a37d7e0d6a
Pass viewer args to viewer implementations
This patch adds the ViewerArgs struct to the Opt struct that contains
the viewer-specific arguments.  It also adds a ViewerArgs argument to
the methods of the Viewer trait so that viewers can access these
arguments.

We also refactor the TextViewer implementations so that we can pass the
viewer arguments to the Printer constructor.

Currently, there are no viewer arguments, but we will add them in
upcoming patches.
2020-08-10 21:19:09 +02:00
Robin Krahl
81c9cf53d6
Print definitions as code instead of HTML
Previously, we renderer item and member definitions as HTML.  With this
patch, we print them as code so that they can be highlighted in the rich
text output.
2020-08-10 19:46:24 +02:00
Robin Krahl
dc7b5b1eca
Add syntax highlighting for code snippets
This patch uses syntect to add syntax highlighting for code snippets in
the rich text output.  Currently, this only applies to the examples
printed with the -e/--examples option.
2020-08-10 19:41:12 +02:00
Robin Krahl
d16f45e023
Wrap HTML and plain text in Text struct
This patch adds the Text struct to the doc module that is a wrapper for
a string that is available as HTML or as plain text.  This makes it
clearer what data is stored in the Doc and Example structs and what the
viewers should do with this data.
2020-08-10 19:28:19 +02:00
Robin Krahl
44028e228a
Release v0.1.3
This patch release adds support for documentation generated with Rust
1.45.0 and fixes some minor bugs in the documentation parser.  It also
adds the documentation downloaded using rustup to the default sources.
2020-07-28 14:59:12 +02:00
Robin Krahl
44fe71d5bb
Rewrap example in readme to 80 columns
This makes it easier to read the example e. g. on crates.io.
2020-07-28 14:57:52 +02:00
Robin Krahl
754e0eecae
Fix list of methods for Rust 1.45
As described in the previous commit, Rust 1.45 changed the ID of the
methods subheading from "methods" to "implementations".  The last patch
fixed this for the trait implementations, this patch updates the method
group parser with the new IDs.
2020-07-27 16:17:36 +02:00
Robin Krahl
ef8f6fa365
Fix trait implementation list for Rust 1.45
In older Rust versions, trait implementations were listed under the
heading with the id "implementations" and in the div with the id
"implementations-list".  Since Rust 1.45, the method heading has the id
"implementations" and the trait implementations have the ids
"trait-implementations" and "trait-implementations-list".

This patch updates the parser with these new IDs while also checking the
old IDs for older documentation.
2020-07-27 16:17:17 +02:00
Robin Krahl
3c06846a30
Sort implementations alphabetically
For consistency and easier testing, we sort the implementation items
alphabetically by their name and their definitions.
2020-07-27 16:16:56 +02:00
Robin Krahl
ae0a741d5a
Extract description of module items as HTML
Previously, we only showed plain text versions of the item descriptions
in the module overview due to a formatting issue.  As this issue
disappeared, we can now use the HTML version of the description.
2020-07-26 12:14:08 +02:00
Robin Krahl
6ca9d90e46
Fix group and ID for typdef items
This patch fixes the group and ID stored in the ItemType enum for the
ItemType::Typedef variant so that typedefs show up in the module
summary.
2020-07-26 12:10:21 +02:00
Robin Krahl
cbc4965902
Show definition for type defs
As in the previous commit, we have to use the selector "pre.typedef"
instead of ".docblock.type-decl" to select the definition for type defs.
2020-07-26 11:51:54 +02:00
Robin Krahl
f0245bada3
Show definition for constants
Similar to the fix for functions in 1a242e5, we have to use a different
selector to query the definition for constants, "pre.const" instead of
".docblock.type-decl".
2020-07-26 11:19:54 +02:00
Robin Krahl
19398e340c
Remove spurious members from module documentation
With this patch, we require that the identifier element for a member in
the module documentation is a direct child of the table cell.  This
fixes problems with spurious member elements if there are more elements
in the table cell, e. g. stability annotations.
2020-07-26 11:04:13 +02:00
Robin Krahl
bc3f1552ef
Fix definition for methods in documentation parser
This patch changes the documentation parser for methods to use the first
code child of the subheading as the definition instead of the first
child.  This fixes a problems when there is additional information in
the subheading, for example about the relevant traits.
2020-07-26 11:03:19 +02:00
Robin Krahl
64dd5a55ae
Use rustc --print sysroot for default sources
Previously, we were used /usr/share/doc/rust{,-doc}/html as a default
source, assuming that it would contain the standard library
documentation.  This is true if the user installed the Rust
documentation manually or using a package manager.  If they use rustup
instead, the documentation is placed in a subdirectory of ~/.rustup.

With this patch, we call `rustc --print sysroot` to determine the
installation directory of the currently activated Rust toolchain –
either the system Rust installation or a Rust installation managed by
rustup.  We then use `$(sysroot)/share/doc/…` as a default path for the
standard library documentation (with /usr as a fallback if the call to
rustc does not return a valid path).
2020-07-25 19:06:27 +02:00
Robin Krahl
4d7c7d4eab
Release v0.1.2
This patch release adds basic logging output and a new `-e`/`--examples`
option to extract only the examples from the documentation.  It also
fixes a bug when displaying the documentation for a function.
2020-07-25 13:29:14 +02:00
Robin Krahl
45a1a3d1f5
Add top-level heading to changelog 2020-07-25 13:24:11 +02:00
Robin Krahl
e9aafd4650
Add more log messages
As I noticed when trying to debug an issue with a very large HTML file,
we still need more log messages that indicate what is currently going on
in rusty-man.  This patch adds some more log messages.
2020-07-25 13:22:32 +02:00
Robin Krahl
34857816e1
Add -e/--example option to only show examples
As requested here [0], this patch adds a new -e/--example option that
extracts the examples from the documentation string instead of printing
the full documentation for an item.  Syntax highlighting will be added
in the future.

[0] https://old.reddit.com/r/rust/comments/hx16j0/rustyman_a_commandline_viewer_for_rustdoc/fz3utjf/
2020-07-25 12:58:52 +02:00
Robin Krahl
1a242e5474
Fix definition selector for functions
Previosuly, we always used the selector ".docblock.type-decl" to select
the definition for an item.  But this did not work for functions.
Therefore we change the selector to "pre.fn" for functions.
2020-07-25 12:23:29 +02:00
Robin Krahl
221c345e1c
Add changelog entry for logging functionality
We introduced basic logging in commit e69e4af but didn’t update the
changelog.  This patch adds the missing changelog entry.
2020-07-25 11:44:57 +02:00