]> git.wincent.com - docvim.git/commitdiff
Get @command annotation working
authorGreg Hurrell <greg@hurrell.net>
Tue, 7 Jun 2016 07:16:46 +0000 (00:16 -0700)
committerGreg Hurrell <greg@hurrell.net>
Tue, 7 Jun 2016 07:17:13 +0000 (00:17 -0700)
lib/Docvim/AST.hs
lib/Docvim/Parse.hs
lib/Docvim/Printer/Vim.hs
lib/Docvim/Visitor.hs
lib/Docvim/Visitor/Command.hs
tests/fixtures/parser/command.golden [new file with mode: 0644]
tests/fixtures/parser/command.vim [new file with mode: 0644]
tests/fixtures/parser/integration-ferret-plugin.golden
tests/fixtures/vim/integration-ferret-plugin.golden

index 4940382f9a0828366ff0649264d188f96cc0bcca..0863b3aa965439632f412384d9d63f2f69b3f3a5 100644 (file)
@@ -62,9 +62,7 @@ data Node
           | IndentAnnotation
           | DedentAnnotation
           | CommandsAnnotation
-          -- TODO: may need more here, command name, for example
-          -- :Ack {blah}                        *:Ack*
-          | CommandAnnotation Usage
+          | CommandAnnotation Name (Maybe Parameters)
           | FooterAnnotation
           | MappingsAnnotation
           -- TODO: need more here, like default value?
@@ -97,7 +95,7 @@ type Default = String
 type Description = String
 type Name = String
 type Type = String
-type Usage = String
+type Parameters = String
 
 -- | Walks an AST node calling the supplied visitor function.
 --
index 10592d3f4707bbba04394eb77df384d25ba70095..36f0cb0c0ebfcc41ed19bcb270e2c70f2052d1a9 100644 (file)
@@ -464,7 +464,9 @@ annotation = char '@' *> annotationName
              , plugin
              ]
 
-    command           = string "command" >> ws >> CommandAnnotation <$> ((:) <$> char ':' <*> many1 (noneOf "\n"))
+    command           = string "command" >> ws >> CommandAnnotation <$> commandName <*> commandParameters
+    commandName       = char ':' *> many1 alphaNum <* optional ws
+    commandParameters = optionMaybe $ many1 (noneOf "\n")
 
     function          = string "function" >> ws >> FunctionAnnotation <$> word <* optional ws
 
index 0eb3989f4c4cb729a47163053497ec017051d610..bbde31f60498c81e3e4845a781040135022ea785 100644 (file)
@@ -131,6 +131,7 @@ node n = case n of
   Blockquote b               -> blockquote b >>= nl >>= nl
   BreakTag                   -> breaktag
   Code c                     -> append $ "`" ++ c ++ "`"
+  CommandAnnotation {}       -> command n
   CommandsAnnotation         -> heading "commands"
   DocBlock d                 -> nodes d
   Fenced f                   -> fenced f
@@ -153,8 +154,8 @@ node n = case n of
   -- TODO: if there is no OptionsAnnotation but there are OptionAnnotations, we
   -- need to insert a `heading "options"` before the first option (ditto for
   -- functions, mappings, commands)
-  OptionsAnnotation          -> heading "options"
   OptionAnnotation {}        -> option n
+  OptionsAnnotation          -> heading "options"
   Paragraph p                -> nodes p >>= nl >>= nl
   Plaintext p                -> plaintext p
   -- TODO: this should be order-independent and always appear at the top.
@@ -195,6 +196,18 @@ listitem l = do
   where
     customLineBreak = "\n  "
 
+command :: Node -> Env
+command (CommandAnnotation name params) = do
+  lhs <- append $ concat [":", name, " ", fromMaybe "" params]
+  ws <- append " "
+  target <- linkTargets [":" ++ name] False
+  trailing <- append "\n"
+  return $ concat [lhs, ws, target, trailing]
+-- TODO indent what follows until next annotation...
+-- will require us to hoist it up inside CommandAnnotation
+-- (and do similar for other sections)
+-- once that is done, drop the extra newline above
+
 option :: Node -> Env
 option (OptionAnnotation n t d) = do
   targets <- linkTargets [n] True
index c02f3c35240f44f3bee7056a2f15d3f15aeee006..aa48785900c1962d41c58560cebdcdf96ff9d911 100644 (file)
@@ -13,7 +13,7 @@ import qualified Data.DList as DList
 -- | Returns True if a node marks the end of a region/block/section.
 endSection :: Node -> Bool
 endSection = \case
-  CommandAnnotation    -> True
+  CommandAnnotation {}   -> True
   CommandsAnnotation     -> True
   FooterAnnotation       -> True
   FunctionAnnotation _   -> True
index f1772c2e273bdb5ca338bfe4ad58e472f03becb9..212767c8d25eb1354697af868bd37bee819f6737 100644 (file)
@@ -12,5 +12,5 @@ extractCommand :: Alternative f => [Node] -> (f [Node], [Node])
 extractCommand = extractBlocks f
   where
     f = \case
-      CommandAnnotation _ -> Just endSection
-      _                   -> Nothing
+      CommandAnnotation {} -> Just endSection
+      _                    -> Nothing
diff --git a/tests/fixtures/parser/command.golden b/tests/fixtures/parser/command.golden
new file mode 100644 (file)
index 0000000..df07892
--- /dev/null
@@ -0,0 +1,34 @@
+Project
+  [ Project [ Unit [ DocBlock [] ] ]
+  , CommandAnnotation "Ack" (Just "{pattern} {options}")
+  , Paragraph [ Plaintext "Info." ]
+  , CommandAnnotation "Qargs" Nothing
+  , Paragraph
+      [ Plaintext "No"
+      , Whitespace
+      , Plaintext "params"
+      , Whitespace
+      , Plaintext "on"
+      , Whitespace
+      , Plaintext "that"
+      , Whitespace
+      , Plaintext "one."
+      ]
+  , Paragraph
+      [ Plaintext "TODO:"
+      , Whitespace
+      , Plaintext "Infer"
+      , Whitespace
+      , Plaintext "info"
+      , Whitespace
+      , Plaintext "based"
+      , Whitespace
+      , Plaintext "on"
+      , Whitespace
+      , Plaintext "following"
+      , Whitespace
+      , Plaintext "VimL"
+      , Whitespace
+      , Plaintext "nodes."
+      ]
+  ]
diff --git a/tests/fixtures/parser/command.vim b/tests/fixtures/parser/command.vim
new file mode 100644 (file)
index 0000000..ea2e5e7
--- /dev/null
@@ -0,0 +1,10 @@
+""
+" @command :Ack {pattern} {options}
+"
+" Info.
+"
+" @command :Qargs
+"
+" No params on that one.
+"
+" TODO: Infer info based on following VimL nodes.
index cd635a04549ba8013c17639424d592a1ffc13812..1ff85e1785200e8a5ec718c297dac200a3200bf8 100644 (file)
@@ -911,7 +911,7 @@ Project
           , UnletStatement { unletBang = False , unletBody = "s:cpoptions" }
           ]
       ]
-  , CommandAnnotation ":Ack {pattern} {options}"
+  , CommandAnnotation "Ack" (Just "{pattern} {options}")
   , Paragraph
       [ Plaintext "Searches"
       , Whitespace
@@ -1346,7 +1346,7 @@ Project
       , Whitespace
       , Plaintext "cursor."
       ]
-  , CommandAnnotation ":Lack {pattern} {options}"
+  , CommandAnnotation "Lack" (Just "{pattern} {options}")
   , Paragraph
       [ Plaintext "Just"
       , Whitespace
@@ -1437,7 +1437,7 @@ Project
       , Link "location-list"
       , Plaintext "."
       ]
-  , CommandAnnotation ":Acks /{pattern}/{replacement}/"
+  , CommandAnnotation "Acks" (Just "/{pattern}/{replacement}/")
   , Paragraph
       [ Plaintext "Takes"
       , Whitespace
@@ -1566,7 +1566,7 @@ Project
       , Plaintext "directory:"
       ]
   , Fenced [ ":Ack foo" , ":Acks /foo/bar/" ]
-  , CommandAnnotation ":Qargs"
+  , CommandAnnotation "Qargs" Nothing
   , Paragraph
       [ Plaintext "This"
       , Whitespace
index 4c60922ec39bada6845997e3d30f4264d4bede34..fde57c0bdcdebd5914163d8f8a2a5504f7489c1f 100644 (file)
@@ -75,6 +75,8 @@ To generate help tags under Pathogen, you can do so from inside Vim with:
 >
     :call pathogen#helptags()
 <
+:Ack {pattern} {options}                                                  *:Ack*
+
 Searches for {pattern} in all the files under the current directory (see
 |:pwd|), unless otherwise overridden via {options}, and displays the results
 in the |quickfix| listing.
@@ -106,6 +108,8 @@ enter |Cmdline-mode| with `:Ack` inserted on the |Cmdline|. Likewise <leader>s
 (|<Plug>(FerretAckWord)|) is a shortcut for running |:Ack| with the word
 currently under the cursor.
 
+:Lack {pattern} {options}                                                *:Lack*
+
 Just like |:Ack|, but instead of using the |quickfix| listing, which is global
 across an entire Vim instance, it uses the |location-list|, which is a
 per-window construct.
@@ -113,6 +117,8 @@ per-window construct.
 Note that |:Lack| always runs synchronously via |:cexpr|, because dispatch.vim
 doesn't currently support the |location-list|.
 
+:Acks /{pattern}/{replacement}/                                          *:Acks*
+
 Takes all of the files currently in the |quickfix| listing and performs a
 substitution of all instances of {pattern} (a standard Vim search |pattern|)
 by {replacement}.
@@ -125,6 +131,8 @@ directory:
     :Ack foo
     :Acks /foo/bar/
 <
+:Qargs                                                                  *:Qargs*
+
 This is a utility function that is used by the |:Acks| command but is also
 generally useful enough to warrant being exposed publicly.