Commit 91836d01 authored by Andrew Gibiansky's avatar Andrew Gibiansky

added :ext completion (again!), closes #168

parent 258a07d3
...@@ -37,7 +37,7 @@ ...@@ -37,7 +37,7 @@
"collapsed": false, "collapsed": false,
"input": [ "input": [
"import Control.Monad.Identity\n", "import Control.Monad.Identity\n",
"lkajsdflkj " ": "
], ],
"language": "python", "language": "python",
"metadata": {}, "metadata": {},
......
...@@ -52,6 +52,7 @@ data CompletionType ...@@ -52,6 +52,7 @@ data CompletionType
| HsFilePath String String | HsFilePath String String
| FilePath String String | FilePath String String
| KernelOption String | KernelOption String
| Extension String
deriving (Show, Eq) deriving (Show, Eq)
complete :: String -> Int -> Interpreter (String, [String]) complete :: String -> Int -> Interpreter (String, [String])
...@@ -95,24 +96,33 @@ complete line pos = do ...@@ -95,24 +96,33 @@ complete line pos = do
return $ filter (prefix `isPrefixOf`) moduleNames return $ filter (prefix `isPrefixOf`) moduleNames
DynFlag ext -> do DynFlag ext -> do
-- Possibly leave out the fLangFlags? The
-- -XUndecidableInstances vs. obsolete
-- -fallow-undecidable-instances.
let extName (name, _, _) = name let extName (name, _, _) = name
otherNames = ["-package","-Wall","-w"] ++
concatMap getSetName kernelOpts kernelOptNames = concatMap getSetName kernelOpts
fNames = map ("-f"++) (names ++ nonames) otherNames = ["-package","-Wall","-w"]
where
-- possibly leave out the fLangFlags? The fNames = map extName fFlags ++
-- -XUndecidableInstances vs. obsolete map extName fWarningFlags ++
-- -fallow-undecidable-instances map extName fLangFlags
names = map extName fFlags ++ fNoNames = map ("no"++) fNames
map extName fWarningFlags ++ fAllNames = map ("-f"++) (fNames ++ fNoNames)
map extName fLangFlags
nonames = map ("no"++) names xNames = map extName xFlags
xNoNames = map ("No" ++) xNames
xNames = map ("-X"++) (names ++ nonames) xAllNames = map ("-X"++) (xNames ++ xNoNames)
where
names = map extName xFlags allNames = xAllNames ++ otherNames ++ fAllNames
nonames = map ("No" ++) names
return $ filter (ext `isPrefixOf`) $ fNames ++ xNames ++ otherNames return $ filter (ext `isPrefixOf`) allNames
Extension ext -> do
let extName (name, _, _) = name
xNames = map extName xFlags
xNoNames = map ("No" ++) xNames
return $ filter (ext `isPrefixOf`) $ xNames ++ xNoNames
HsFilePath lineUpToCursor match -> completePathWithExtensions [".hs", ".lhs"] lineUpToCursor HsFilePath lineUpToCursor match -> completePathWithExtensions [".hs", ".lhs"] lineUpToCursor
...@@ -149,17 +159,18 @@ completionType :: String -- ^ The line on which the completion is bei ...@@ -149,17 +159,18 @@ completionType :: String -- ^ The line on which the completion is bei
completionType line loc target completionType line loc target
-- File and directory completions are special -- File and directory completions are special
| startswith ":!" stripped | startswith ":!" stripped
= case parseShell lineUpToCursor of = fileComplete FilePath
Right xs -> FilePath lineUpToCursor $ if endswith (last xs) lineUpToCursor then (last xs) else []
Left _ -> Empty
| startswith ":l" stripped | startswith ":l" stripped
= case parseShell lineUpToCursor of = fileComplete HsFilePath
Right xs -> HsFilePath lineUpToCursor $ if endswith (last xs) lineUpToCursor then (last xs) else []
Left _ -> Empty -- Complete :set, :opt, and :ext
| startswith ":s" stripped | startswith ":s" stripped
= DynFlag candidate = DynFlag candidate
| startswith ":o" stripped | startswith ":o" stripped
= KernelOption candidate = KernelOption candidate
| startswith ":e" stripped
= Extension candidate
-- Use target for other completions. -- Use target for other completions.
-- If it's empty, no completion. -- If it's empty, no completion.
| null target | null target
...@@ -178,6 +189,12 @@ completionType line loc target ...@@ -178,6 +189,12 @@ completionType line loc target
isModName = all isCapitalized (init target) isModName = all isCapitalized (init target)
isCapitalized = isUpper . head isCapitalized = isUpper . head
lineUpToCursor = take loc line lineUpToCursor = take loc line
fileComplete filePath = case parseShell lineUpToCursor of
Right xs -> filePath lineUpToCursor $
if endswith (last xs) lineUpToCursor
then last xs
else []
Left _ -> Empty
-- | Get the word under a given cursor location. -- | Get the word under a given cursor location.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment