Permalink
Browse files

Added vim completion support for loadable component.

  • Loading branch information...
1 parent 98f1c6d commit b91285e9f4eac32c3cd9beb9c6c815f61d195579 @MarcWeber MarcWeber committed with Jan 29, 2009
Showing with 24 additions and 2 deletions.
  1. +11 −1 server/Scion/Server/Protocol/Vim.hs
  2. +13 −1 vim_runtime_path/ftplugin/haskell.vim
@@ -37,11 +37,12 @@ import qualified System.Log.Logger as HL
import qualified Data.ByteString.Char8 as S
import qualified Data.Map as M
+import Data.Maybe (isJust, Maybe(..))
import Data.List (intercalate, nub, isPrefixOf)
import Data.Time.Clock ( NominalDiffTime )
import DynFlags ( supportedLanguages, allFlags )
-import InteractiveEval ( getNamesInScope )
+import InteractiveEval ( getNamesInScope, getRdrNamesInScope )
import qualified Outputable as O
import GHC
import Exception (ghandle)
@@ -94,6 +95,7 @@ vimCommands =
-- basically its the same as cmdThingAtPoint
, cmdThingAtPointMoreInfo
-- , cmdDumpSources
+ , cmdListCabalTargets
]
------------------------------------------------------------------------------
@@ -306,7 +308,15 @@ cmdThingAtPointMoreInfo = VimCommand "cmdThingAtPointMoreInfo" $ \map' -> do
-- return ()
-- _ -> return ()
+-- only used to pass a completion list over to vim
+cmdListCabalTargets = VimCommand "cmdListCabalTargets" $ \_ -> do
+ cp <- currentCabalPackage
+ return $ toVim $
+ (if isJust (PD.library cp) then ["library"] else [] )
+ ++ map ( ("executable:" ++) . PD.exeName) (PD.executables cp)
+
-- ========== passing data is done using serialized vim types : ======
+--
data VimType = VList [VimType]
| VDict (M.Map VimType VimType)
@@ -44,6 +44,14 @@ fun! s:OpenCabalProject(...)
\)
endf
+fun! s:LoadComponentCompletion(A,L,P)
+ let beforeC= a:L[:a:P-1]
+ let word = matchstr(beforeC, '\zs\S*$')
+
+ let list = haskellcomplete#EvalScion({'request' : 'cmdListCabalTargets'})
+ return filter(list, 'v:val =~ '.string('^'.word))
+endf
+
" ===== you don't need any project for these: =============
command! -buffer ConnectionInfo
\ echo haskellcomplete#EvalScion({'request' : 'cmdConnectionInfo'})
@@ -68,7 +76,8 @@ command! -buffer -nargs=* -complete=file OpenCabalProject
\ call s:OpenCabalProject(<f-args>)
" arg either "library" or "executable:name"
-command! -buffer -nargs=1 LoadComponent
+command! -buffer -nargs=1 -complete=customlist,s:LoadComponentCompletion
+ \ LoadComponent
\ echo ScionResultToErrorList('load component finished: ','setqflist',haskellcomplete#EvalScion({'request' : 'cmdLoadComponent', 'component' : <q-args>}))
" list exposed
@@ -87,3 +96,6 @@ command! -buffer ThingAtPointExportedByHack
command! -buffer ListRdrNamesInScope
\ echo haskellcomplete#EvalScion({'request' : 'cmdListRdrNamesInScope'})
+
+command! -buffer ListCabalTargets
+ \ echo haskellcomplete#EvalScion({'request' : 'cmdListCabalTargets'})

0 comments on commit b91285e

Please sign in to comment.