Giter VIP home page Giter VIP logo

docvim's Introduction

docvim: a documentation generator for Vim plug-ins

docvim is a documentation generator for Vim plug-ins, written in Haskell.

Quickstart

# Print Markdown-formatted help documentation for files in current directory
docvim

# Write Markdown README + Vim help text file for $PLUGIN
docvim -c ~/code/$PLUGIN ~/code/$PLUGIN/doc/$PLUGIN.txt ~/code/$PLUGIN/README.md

Usage

docvim - a documentation generator for Vim plug-ins

Usage: docvim [--version] [OUTFILES...] [-d|--debug] [-c|--directory DIRECTORY]
              [-v|--verbose]
  Generate documentation for a Vim plug-in

Available options:
  -h,--help                Show this help text
  --version                Print version information
  OUTFILES...              Target file(s) for generated output (default:
                           standard output)
  -d,--debug               Print debug information during processing
  -c,--directory DIRECTORY Change to DIRECTORY before processing (default: ".")
  -v,--verbose             Be verbose during processing

Installation

# Stack:
stack install docvim

# Cabal:
cabal install docvim

Syntax

""
" Docblocks start with a pair of double quotes, followed
" by standard Vim comments (with a double quote prefix)
" containing Markdown-like text and optional annotations
" that look like this:
"
" ```
" @command :Ack {pattern} {options}
" ```

Supported Markdown features

# Top-level heading

## Sub-heading

--- (Horizontal dividers)

> Blockquote

`inline code`

```
fenced codeblocks (leading space syntax not supported)
```

![alt text](http://example.com/image.jpg)
(becomes a link in vimdoc, but an image in markdown)

- Lists.

Unsupported Markdown syntax

*foo* (emphasis; turns into Vim doc targets instead)

*,+ (list syntax; just use - instead)

<html> (we don't want ambiguity with things like <leader> and so on)

Annotations

  • @command
  • @commands
  • @dedent
  • @footer
  • @function
  • @functions
  • @indent
  • @mapping
  • @mappings
  • @option
  • @options
  • @plugin

Development

Convenience wrappers

bin/accept  # Accept current "golden" test output.
bin/docvim  # Run the docvim executable.
bin/golden  # Run just the "golden" tests.
bin/haddock # Produce Haddock documentation.
bin/lint    # Run the linter.
bin/tasty   # Run just the Tasty tests.
bin/test    # Run all tests, including lints.

These are wrappers for the explicit invocations described below.

Set-up

You can set-up a development environment using Stack (recommended) or Cabal:

# Stack:
brew install stack
stack build

# Cabal:
brew install cabal-install
cabal sandbox init
cabal install --only-dependencies --enable-tests
cabal build

Running

Run using stack exec (or cabal run) and passing in docvim-specific OPTIONS:

# Stack:
stack exec docvim [OPTIONS]

# Cabal:
cabal run -- [OPTIONS]

You can also run the modules from inside the REPL:

# Stack:
stack repl
> pp "let l:test=1" -- pretty-prints AST

# Cabal:
cabal repl
> import Text.Docvim.Parse
> pp "let l:test=1" -- pretty-prints AST

Building

stack build --file-watch

Building and viewing the code-level documentation

# Stack:
stack haddock
open .stack-work/dist/x86_64-osx/Cabal-1.22.5.0/doc/html/docvim/index.html

# Cabal:
cabal haddock --executables
open dist/doc/html/docvim/docvim/index.html

Testing

# Stack:
stack test        # Runs all test suites, including linting.
stack test :tasty # Runs just the Tasty test suite.

# Cabal:
cabal test       # Runs all test suites, including linting.
cabal test tasty # Runs just the Tasty test suite.

Updating "golden" files

# Stack:
stack test --test-arguments=--accept          # Runs all test suites.
stack test :tasty --test-arguments=--accept   # Runs just the Tasty test suite.

# Cabal:
cabal test --test-options=---accept           # Runs all test suites.
cabal test tasty --test-options=---accept     # Runs just the Tasty test suite.

Linting

# Stack:
stack test              # Runs linter as part of overall set of suites.
stack test :hlint       # Runs linter alone.

# Cabal:
cabal install hlint     # (First-time only).
cabal test              # Runs linter as part of overall set of suites.
cabal test hlint        # Runs linter alone.

hlint src               # If you have HLint installed under $PATH.

Release process

vim docvim.cabal # Update version number in two places.
vim CHANGELOG.md # Update, er, changelog.
git commit -p # git tag, git push --follow-tags etc...
bin/sdist
bin/upload

Links

Examples of plug-ins using docvim

FAQ

Why a new tool and not an existing one like Vimdoc?

  • I wanted to target multiple output formats (Vim help files and Markdown).
  • I wanted total control over the presentation of the output.
  • It's fun to build new things from scratch.
  • The project is a great fit for my learn-me-a-Haskell goal this year.

Why is it called "docvim"?

"Vimdoc" was the first name that occurred to me when I started this project, but:

So, in a remarkable flash of profound creativity, I settled on "docvim" instead, which right now yields this pleasing search result:

Did you mean: dacvim

docvim's People

Contributors

wincent avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

docvim's Issues

Prune "empty" paths in AST

Due to extraction, we can wind up with an AST fragment that looks like this:

Project
  [ Project [ Unit [ DocBlock [] ] , DocBlock [] ]
  , CommandsAnnotation
  , CommandAnnotation "Ack" (Just "{pattern} {options}")
  , Paragraph [ Plaintext "Info." ]
  , CommandAnnotation "Qargs" Nothing
...

Would be nice to get rid of the empty DocBlocks, and in turn the empty Unit, and the empty Project, so the above would reduce to:

Project
  , CommandsAnnotation
  , CommandAnnotation "Ack" (Just "{pattern} {options}")
  , Paragraph [ Plaintext "Info." ]
  , CommandAnnotation "Qargs" Nothing
...

Fix off-by-one with right-aligned text

Example:

                                                                      *g:Bar*
|g:Bar|                                               string (default: none)

There are actually two or three issues here:

  1. First line is one char too far to the right (or second line is too far to the left).
  2. Two | will get concealed at line 2 at render time, which means that the suffix needs to be pushed to the right by two to compensate.
  3. Similarly, both * get concealed in line 1, so they should be compensated for in the wrapping calculation.

Auto-gen based on VimL AST nodes

Instead of (something like):

""
" @function ...
"
" blah
function a#b()

Be able to write (something like):

""
" blah
function a#b()

Ditto for @option, @command and @mapping.

<Leader> gets eaten in Markdown output

Given source like this:

" Shortcut mappings are provided to start an |:Ack| search (<leader>a) or to
" search for the word currently under the cursor (<leader>s).

We output Vim doc:

Shortcut mappings are provided to start an |:Ack| search (<leader>a) or to
search for the word currently under the cursor (<leader>s).

And markdown:

Shortcut mappings are provided to start an <strong>[`:Ack`](#user-content-ack)</strong> search (<leader>a) or to search for the word currently under the cursor (<leader>s).

When that Markdown gets HTML-ified on GitHub, it shows up as:

<p>Shortcut mappings are provided to start an <strong><a href="#user-content-ack"><code>:Ack</code></a></strong> search (a) or to search for the word currently under the cursor (s).</p>

GitLab does the same, stripping the unrecognized tag right out as part of sanitization. Bitbucket does not, but it is a mess in other ways.

So, we should deal with this using either a whitelist of HTML tags that we'll let through, and escape everything else.

Fix bit-rot in stack build

It's been years since last update and couldn't install this easily on new machine, as described here:

git clone ...
cd docvim
brew install stack # didn't have stack on this machine
stack build # build fails
stack install docvim # install fails
cabal install docvim # install fails
cabal v2-build # victory!

After that I could do the actual doc-gen with:

./dist-newstyle/build/x86_64-osx/ghc-8.4.4/docvim-0.3.2.1/x/docvim/build/docvim/docvim \
  -c ~/code/pinnacle \
  -v \
  ~/code/pinnacle/doc/pinnacle.txt \
  ~/code/pinnacle/README.md

Of course, I am way out of touch with how all this works... ๐Ÿคฆโ€โ™‚๏ธ

tasty test fails in Stackage Nightly build

I haven't tried locally yet but when trying to run the tasty test in Stackage Nightly for docvim-0.3.1.1:

> /tmp/stackage-build8/docvim-0.3.1.1$ dist/build/tasty/tasty
tasty: tests/fixtures/parser: getDirectoryContents: does not exist (No such file or directory)

Autolinking doesn't always work in Markdown output

I just noticed in the Ferret docs (https://github.com/wincent/ferret) only some of the things that could be internal links are getting linked (eg. |:Ack| gets linked but |g:FerretExecutableArguments| does not). I wonder if this is because those come from different files and the symbol table is not global (ie. it's per file) or we have some kind of order dependency. It's been too long and I can't remember the implementation details right now.

`rust` branch tracking issue

Just some known things I want to get to:

  • Implement histogram diff.
  • Implement optimizations for Myers diff (it's still used as a fallback for the histogram diff, so should be fast).
  • Implement fast hashing function and precompute hashes before calling internal diffing functions.
  • Try to reduce repetitive casts usize โ†”๏ธŽ isize that are all over the place.
  • Improve snapshot diff output (for example, not currently printing hunk headers or limiting context lines).
  • Finish Lua parser.
  • Make pretty lexer/parser errors (ie. transform kind: UnexpectedToken, position: 14 into something human-useful).
  • Make Vimscript lexer + parser.
  • Make output pretty-printer.
  • Implement benchmarks.
  • Clean up tire-fire that is the RingBuffer implementation.

Make real integration tests

Want to be able to point at a folder full of files and get a Markdown (and a plaintext) output string out of it.

Build failure with optparse-applicative 0.13

Preprocessing library docvim-0.3.2.1...
[ 1 of 25] Compiling Paths_docvim     ( dist/build/autogen/Paths_docvim.hs, dist/build/Paths_docvim.o )
[ 2 of 25] Compiling Text.Docvim.ReadDir ( lib/Text/Docvim/ReadDir.hs, dist/build/Text/Docvim/ReadDir.o )
[ 3 of 25] Compiling Text.Docvim.Options ( lib/Text/Docvim/Options.hs, dist/build/Text/Docvim/Options.o )

lib/Text/Docvim/Options.hs:18:3: error:
    โ€ข Variable not in scope:
        (<>) :: Mod f11 a10 -> Mod f12 a11 -> Mod ArgumentFields String
    โ€ข Perhaps you meant one of these:
        โ€˜<|>โ€™ (imported from Options.Applicative),
        โ€˜<*>โ€™ (imported from Options.Applicative),
        โ€˜*>โ€™ (imported from Options.Applicative)

lib/Text/Docvim/Options.hs:24:3: error:
    โ€ข Variable not in scope:
        (<>) :: Mod f9 a8 -> Mod f10 a9 -> Mod OptionFields (a -> a)
    โ€ข Perhaps you meant one of these:
        โ€˜<|>โ€™ (imported from Options.Applicative),
        โ€˜<*>โ€™ (imported from Options.Applicative),
        โ€˜*>โ€™ (imported from Options.Applicative)

lib/Text/Docvim/Options.hs:29:3: error:
    โ€ข Variable not in scope: (<>) :: Parser Bool -> Mod f7 a6 -> t5
    โ€ข Perhaps you meant one of these:
        โ€˜<|>โ€™ (imported from Options.Applicative),
        โ€˜<*>โ€™ (imported from Options.Applicative),
        โ€˜*>โ€™ (imported from Options.Applicative)

lib/Text/Docvim/Options.hs:30:3: error:
    โ€ข Variable not in scope: (<>) :: t5 -> Mod f8 a7 -> Parser Bool
    โ€ข Perhaps you meant one of these:
        โ€˜<|>โ€™ (imported from Options.Applicative),
        โ€˜<*>โ€™ (imported from Options.Applicative),
        โ€˜*>โ€™ (imported from Options.Applicative)

Consider auto-inferring indent/dedent

Option A: auto-infer

" # Website
"
" The official Loupe source code repo is at:
"
"   http://git.wincent.com/loupe.git
"
" A mirror exists at:
"
"  https://github.com/wincent/loupe
"
" Official releases are listed at:
"
"   http://www.vim.org/scripts/script.php?script_id=5215
"

Option B: explicit

" # Website
"
" The official Loupe source code repo is at:
"
" @indent
"   http://git.wincent.com/loupe.git
" @dedent
"
" A mirror exists at:
"
" @indent
"  https://github.com/wincent/loupe
" @dedent
"
" Official releases are listed at:
"
" @indent
"   http://www.vim.org/scripts/script.php?script_id=5215
" @dedent
"

Option C: use lists instead

" # Website
"
" The official Loupe source code repo is at:
"
" - http://git.wincent.com/loupe.git
"
" A mirror exists at:
"
" - https://github.com/wincent/loupe
"
" Official releases are listed at:
"
" - http://www.vim.org/scripts/script.php?script_id=5215
"

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.