git.iko.soy/rowtype-yoga/purescript-native
on golang help sign in
Minor refactoring of completion context mechanism.

Hide the file prefix inside the FilePath constructor for CompletionContext. This lets us avoid passing it unnecessarily to getCompletion.

commit430b4e2ff2cf2f32efebd6101ea638b8e9fb193d authorVladimir Korablin <vkorablin@gmail.com> dateMon 29 Dec 2014, 22:23 (12 years ago) parentdadcd51
1 file changed+16−16
psci/Main.hs+16−16
psci/Main.hs+16−16
@@ -185,19 +185,19 @@ quitMessage = "See ya!"
185185
186186-- Haskeline completions
187187
188−data CompletionContext = Command String | FilePath | Module | Identifier | Fixed [String] | Multiple [CompletionContext]
188+data CompletionContext = Command String | FilePath String | Module | Identifier | Fixed [String] | Multiple [CompletionContext]
189189 deriving (Show)
190190
191191-- |
192192-- Decide what kind of completion we need based on input.
193−completionContext :: String -> Maybe CompletionContext
194−completionContext cmd@"" = Just $ Multiple [Command cmd, Identifier]
195−completionContext cmd@(':' : _ )
193+completionContext :: String -> String -> Maybe CompletionContext
194+completionContext cmd@"" _ = Just $ Multiple [Command cmd, Identifier]
195+completionContext cmd@(':' : _ ) _
196196 | cmd `elem` C.commands || cmd == ":" = Just $ Command cmd
197−completionContext (':' : c : _) = case c of
197+completionContext (':' : c : _) word = case c of
198198 'i' -> Just Module
199199 'b' -> Just Module
200− 'm' -> Just FilePath
200+ 'm' -> Just $ FilePath word
201201 'q' -> Nothing
202202 'r' -> Nothing
203203 '?' -> Nothing
@@ -205,7 +205,7 @@ completionContext (':' : c : _) = case c of
205205 't' -> Just Identifier
206206 'k' -> Just Identifier
207207 _ -> Nothing
208−completionContext _ = Just Identifier
208+completionContext _ _ = Just Identifier
209209
210210-- |
211211-- Loads module, function, and file completions.
@@ -215,22 +215,22 @@ completion = completeWordWithPrev Nothing " \t\n\r" findCompletions
215215 where
216216 findCompletions :: String -> String -> StateT PSCiState IO [Completion]
217217 findCompletions prev word = do
218− let ctx = completionContext $ (dropWhile isSpace (reverse prev)) ++ word
218+ let ctx = completionContext ((dropWhile isSpace (reverse prev)) ++ word) word
219219 completions <- case ctx of
220220 Nothing -> return []
221221 (Just c) -> (mapMaybe $ either (\cand -> if word `isPrefixOf` cand
222222 then Just $ simpleCompletion cand
223223 else Nothing) Just)
224− <$> getCompletion c word
224+ <$> getCompletion c
225225 return $ sortBy sorter completions
226226
227− getCompletion :: CompletionContext -> String -> StateT PSCiState IO [Either String Completion]
228− getCompletion (Command s) _ = return $ (map Left) $ nub $ filter (isPrefixOf s) C.commands
229− getCompletion FilePath f = (map Right) <$> listFiles f
230− getCompletion Module _ = (map Left) <$> getModuleNames
231− getCompletion Identifier _ = (map Left) <$> getIdentNames
232− getCompletion (Fixed list) _ = return $ (map Left) list
233− getCompletion (Multiple contexts) f = concat <$> mapM (flip getCompletion $ f) contexts
227+ getCompletion :: CompletionContext -> StateT PSCiState IO [Either String Completion]
228+ getCompletion (Command s) = return $ (map Left) $ nub $ filter (isPrefixOf s) C.commands
229+ getCompletion (FilePath f) = (map Right) <$> listFiles f
230+ getCompletion Module = (map Left) <$> getModuleNames
231+ getCompletion Identifier = (map Left) <$> getIdentNames
232+ getCompletion (Fixed list) = return $ (map Left) list
233+ getCompletion (Multiple contexts) = concat <$> mapM getCompletion contexts
234234
235235 getLoadedModules :: StateT PSCiState IO [P.Module]
236236 getLoadedModules = map snd . psciLoadedModules <$> get