diff --git a/server/Scion/Server/Protocol/Vim.hs b/server/Scion/Server/Protocol/Vim.hs index 9bc236b..f329576 100644 --- a/server/Scion/Server/Protocol/Vim.hs +++ b/server/Scion/Server/Protocol/Vim.hs @@ -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) diff --git a/vim_runtime_path/ftplugin/haskell.vim b/vim_runtime_path/ftplugin/haskell.vim index 9a78a5d..fa1d7ea 100644 --- a/vim_runtime_path/ftplugin/haskell.vim +++ b/vim_runtime_path/ftplugin/haskell.vim @@ -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() " 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' : })) " 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'})