Skip to content

Commit

Permalink
Added experimental cmdThingAtPointMoreInfo.
Browse files Browse the repository at this point in the history
To returns info about the module exporting the thing in a hacky way.
  • Loading branch information
MarcWeber authored and nominolo committed May 25, 2009
1 parent 2a7fdf3 commit 64e6e7e
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
35 changes: 35 additions & 0 deletions server/Scion/Server/Protocol/Vim.hs
Expand Up @@ -64,6 +64,7 @@ import Text.ParserCombinators.Parsec
import Text.ParserCombinators.Parsec.Char import Text.ParserCombinators.Parsec.Char


import Text.ParserCombinators.ReadP (skipSpaces) import Text.ParserCombinators.ReadP (skipSpaces)
import qualified Data.Set as Set


log = HL.logM __FILE__ log = HL.logM __FILE__
logInfo = log HL.INFO logInfo = log HL.INFO
Expand All @@ -88,6 +89,9 @@ vimCommands =
, cmdForceUnload , cmdForceUnload
, cmdAddCmdLineFlag , cmdAddCmdLineFlag
, cmdThingAtPoint , cmdThingAtPoint
-- for testing. I'd like to get the module which is exporting the thing one day..
-- basically its the same as cmdThingAtPoint
, cmdThingAtPointMoreInfo
-- , cmdDumpSources -- , cmdDumpSources
] ]


Expand Down Expand Up @@ -244,6 +248,37 @@ cmdThingAtPoint = VimCommand "cmdThingAtPoint" $ \map' -> do
_ -> return (Just (O.showSDocDebug (O.ppr x O.$$ O.ppr xs ))) _ -> return (Just (O.showSDocDebug (O.ppr x O.$$ O.ppr xs )))
_ -> return Nothing _ -> return Nothing


cmdThingAtPointMoreInfo = VimCommand "cmdThingAtPointMoreInfo" $ \map' -> do
file <- requireArg map' "file"
line <- lookupAndReadFail map' "line"
col <- lookupAndReadFail map' "col"
liftM toVim $ cmd file line col
where
-- TODO remove this code duplication !
cmd fname line col = do
let loc = srcLocSpan $ mkSrcLoc (fsLit fname) line col
tc_res <- gets bgTcCache
case tc_res of
Just (Typechecked tcm) -> do
--let Just (src, _, _, _, _) = renamedSource tcm
let src = typecheckedSource tcm
--let in_range = const True
let in_range = overlaps loc
let r = findHsThing in_range src
return (Just (O.showSDoc (O.ppr $ Set.toList r)))
-- unqual <- unqualifiedForModule tcm
-- case pathToDeepest r of
-- Nothing -> return (Just "no info")
-- Just (x,xs) ->
-- --return $ Just (O.showSDoc (O.ppr x O.$$ O.ppr xs))
-- case typeOf (x,xs) of
-- Just t ->
-- return $ Just $ O.showSDocForUser unqual
-- (prettyResult x O.<+> O.dcolon O.<+>
-- pprTypeForUser True t)
-- _ -> return (Just (O.showSDocDebug (O.ppr x O.$$ O.ppr xs )))
_ -> return Nothing

-- cmdDumpSources = VimCommand "cmdDumpSources" $ \map -> do -- cmdDumpSources = VimCommand "cmdDumpSources" $ \map -> do
-- liftM toVim $ do -- liftM toVim $ do
-- tc_res <- gets bgTcCache -- tc_res <- gets bgTcCache
Expand Down
6 changes: 6 additions & 0 deletions vim_runtime_path/ftplugin/haskell.vim
Expand Up @@ -78,6 +78,12 @@ command! -buffer -nargs=* -complete=file BackgroundTypecheckFile
\ call s:BackgroundTypecheckFile(<f-args>) \ call s:BackgroundTypecheckFile(<f-args>)
command! -buffer ThingAtPoint command! -buffer ThingAtPoint
\ echo haskellcomplete#EvalScion({'request' : 'cmdThingAtPoint', 'file' : expand('%:p'), 'line' : line('.').'', 'col' : col('.').''}) \ echo haskellcomplete#EvalScion({'request' : 'cmdThingAtPoint', 'file' : expand('%:p'), 'line' : line('.').'', 'col' : col('.').''})
command! -buffer ThingAtPointExportedByHack
\ echo filter(
\ split(haskellcomplete#EvalScion({'request' : 'cmdThingAtPointMoreInfo'
\, 'file' : expand('%:p')
\, 'line' : line('.').'', 'col' : col('.').''})['Just'],"\n")
\ , 'v:val =~ '.string(expand('<cword>').' ='))[0]


command! -buffer ListRdrNamesInScope command! -buffer ListRdrNamesInScope
\ echo haskellcomplete#EvalScion({'request' : 'cmdListRdrNamesInScope'}) \ echo haskellcomplete#EvalScion({'request' : 'cmdListRdrNamesInScope'})

0 comments on commit 64e6e7e

Please sign in to comment.