Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Added vim module completion.

  • Loading branch information...
commit fd9079b48c4cd674ec6e6e4720e23afef4651240 1 parent 64e6e7e
@MarcWeber MarcWeber authored committed
View
18 lib/Scion/Utils.hs
@@ -23,6 +23,8 @@ import Outputable
import Control.Monad
import Data.Maybe ( fromMaybe )
+import Data.Char (isLower, isUpper)
+
thingsAroundPoint :: (Int, Int) -> [Located n] -> [Located n]
thingsAroundPoint pt ls = [ l | l <- ls, spans (getLoc l) pt ]
@@ -55,3 +57,19 @@ ifM :: Monad m => m Bool -> m a -> m a -> m a
ifM cm tm em = do
c <- cm
if c then tm else em
+
+-- an alternative to the broken Fuzzy module
+-- match sH simpleHTTP
+-- match siH simpleHTTP
+-- match sHTTP simpleHTTP
+-- match pSL putStrLn
+-- match lM liftM
+-- match DS Data.Set
+camelCaseMatch :: String -> String -> Bool
+camelCaseMatch (c:cs) (i:is)
+ | c == i = (camelCaseMatch cs $ dropWhile (\c' -> isLower c' || c' == '.') . dropWhile isUpper $ is)
+ || camelCaseMatch cs is -- to allow siH match simpleHTTP
+ | otherwise = False
+camelCaseMatch [] [] = True
+camelCaseMatch [] _ = False
+camelCaseMatch _ [] = False
View
16 server/Scion/Server/Protocol/Vim.hs
@@ -23,7 +23,7 @@ import Scion.Inspect ( prettyResult )
import Scion.Inspect.Find ( overlaps, findHsThing, pathToDeepest)
import Scion.Inspect.TypeOf ( typeOf )
import Scion.Configure (configureCabalProject)
-import Scion.Utils ( unqualifiedForModule )
+import Scion.Utils ( unqualifiedForModule, camelCaseMatch )
import Scion.Session (preprocessPackage, currentCabalPackage, loadComponent,
backgroundTypecheckFile, unload, setGHCVerbosity, addCmdLineFlags)
import FastString (fsLit, unpackFS)
@@ -37,7 +37,7 @@ import qualified System.Log.Logger as HL
import qualified Data.ByteString.Char8 as S
import qualified Data.Map as M
-import Data.List (intercalate, nub)
+import Data.List (intercalate, nub, isPrefixOf)
import Data.Time.Clock ( NominalDiffTime )
import DynFlags ( supportedLanguages, allFlags )
@@ -89,6 +89,7 @@ vimCommands =
, cmdForceUnload
, cmdAddCmdLineFlag
, cmdThingAtPoint
+ , cmdModuleCompletion
-- for testing. I'd like to get the module which is exporting the thing one day..
-- basically its the same as cmdThingAtPoint
, cmdThingAtPointMoreInfo
@@ -248,6 +249,17 @@ cmdThingAtPoint = VimCommand "cmdThingAtPoint" $ \map' -> do
_ -> return (Just (O.showSDocDebug (O.ppr x O.$$ O.ppr xs )))
_ -> return Nothing
+-- module completion
+cmdModuleCompletion = VimCommand "cmdModuleCompletion" $ \map' -> do
+ short <- requireArg map' "short"
+ camelCase <- lookupAndReadFail map' "camelCase"
+ mod_names <- allExposedModules
+ let modules = map (O.showSDoc . O.ppr) mod_names
+ let filterFunc = if camelCase
+ then \c s -> isPrefixOf c s || camelCaseMatch c s
+ else isPrefixOf
+ return $ toVim $ filter (filterFunc short) modules
+
cmdThingAtPointMoreInfo = VimCommand "cmdThingAtPointMoreInfo" $ \map' -> do
file <- requireArg map' "file"
line <- lookupAndReadFail map' "line"
View
25 vim_runtime_path/autoload/haskellcomplete.vim
@@ -37,12 +37,25 @@ endfunction
if !exists('g:haskellcompleteAll')
let g:haskellcompleteAll='' " '' or '-all' '-all' means complete from the set of all function exported by all modules found in all used packages
endif
-"function! haskellcomplete#CompleteIdentifier(findstart, base)
-" return haskellcomplete#CompleteWhat(a:findstart, a:base, 'identifier'.g:haskellcompleteAll)
-"endfunction
-"function! haskellcomplete#CompleteModule(findstart, base)
-" return haskellcomplete#CompleteWhat(a:findstart, a:base, 'module')
-"endfunction
+
+fun! haskellcomplete#CompletModule(findstart, base)
+ if a:findstart
+ let [bc,ac] = haskellcomplete#BcAc()
+ return len(bc)-len(matchstr(bc,'\S*$'))
+ else
+ let [bc,ac] = haskellcomplete#BcAc()
+ let addImport = bc !~ 'import\s\+\S*$'
+ let matches = haskellcomplete#EvalScion(
+ \ { 'request' : 'cmdModuleCompletion'
+ \ , 'camelCase' : 'True'
+ \ , 'short' : a:base
+ \ })
+ if addImport
+ call map(matches, string('import ').'.v:val')
+ endif
+ return matches
+ endif
+endf
" example: echo haskellcomplete#EvalScion({'request' : 'cmdConnectionInfo', 'file' : 'test.hs'})
function! haskellcomplete#EvalScion(request)
Please sign in to comment.
Something went wrong with that request. Please try again.