Skip to content

Commit

Permalink
Added vim completion support for loadable component.
Browse files Browse the repository at this point in the history
  • Loading branch information
MarcWeber authored and nominolo committed May 25, 2009
1 parent 98f1c6d commit b91285e
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
12 changes: 11 additions & 1 deletion server/Scion/Server/Protocol/Vim.hs
Expand Up @@ -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)
Expand Down Expand Up @@ -94,6 +95,7 @@ vimCommands =
-- basically its the same as cmdThingAtPoint
, cmdThingAtPointMoreInfo
-- , cmdDumpSources
, cmdListCabalTargets
]

------------------------------------------------------------------------------
Expand Down Expand Up @@ -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)
Expand Down
14 changes: 13 additions & 1 deletion vim_runtime_path/ftplugin/haskell.vim
Expand Up @@ -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'})
Expand All @@ -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
Expand All @@ -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.