git.iko.soy/rowtype-yoga/purescript-native
on golang help sign in
Minor refactoring of completion context mechanism.
430b4e2Vladimir Korablin
psci/Main.hs+16−16
@@ -185,19 +185,19 @@ quitMessage = "See ya!"
185
185
186-- Haskeline completions
186-- Haskeline completions
187
187
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]
189 deriving (Show)
189 deriving (Show)
190
190
191-- |
191-- |
192-- Decide what kind of completion we need based on input.
192-- Decide what kind of completion we need based on input.
193−completionContext :: String -> Maybe CompletionContext
193+completionContext :: String -> String -> Maybe CompletionContext
194−completionContext cmd@"" = Just $ Multiple [Command cmd, Identifier]
194+completionContext cmd@"" _ = Just $ Multiple [Command cmd, Identifier]
195−completionContext cmd@(':' : _ )
195+completionContext cmd@(':' : _ ) _
196 | cmd `elem` C.commands || cmd == ":" = Just $ Command cmd
196 | cmd `elem` C.commands || cmd == ":" = Just $ Command cmd
197−completionContext (':' : c : _) = case c of
197+completionContext (':' : c : _) word = case c of
198 'i' -> Just Module
198 'i' -> Just Module
199 'b' -> Just Module
199 'b' -> Just Module
200− 'm' -> Just FilePath
200+ 'm' -> Just $ FilePath word
201 'q' -> Nothing
201 'q' -> Nothing
202 'r' -> Nothing
202 'r' -> Nothing
203 '?' -> Nothing
203 '?' -> Nothing
@@ -205,7 +205,7 @@ completionContext (':' : c : _) = case c of
205 't' -> Just Identifier
205 't' -> Just Identifier
206 'k' -> Just Identifier
206 'k' -> Just Identifier
207 _ -> Nothing
207 _ -> Nothing
208−completionContext _ = Just Identifier
208+completionContext _ _ = Just Identifier
209
209
210-- |
210-- |
211-- Loads module, function, and file completions.
211-- Loads module, function, and file completions.
@@ -215,22 +215,22 @@ completion = completeWordWithPrev Nothing " \t\n\r" findCompletions
215 where
215 where
216 findCompletions :: String -> String -> StateT PSCiState IO [Completion]
216 findCompletions :: String -> String -> StateT PSCiState IO [Completion]
217 findCompletions prev word = do
217 findCompletions prev word = do
218− let ctx = completionContext $ (dropWhile isSpace (reverse prev)) ++ word
218+ let ctx = completionContext ((dropWhile isSpace (reverse prev)) ++ word) word
219 completions <- case ctx of
219 completions <- case ctx of
220 Nothing -> return []
220 Nothing -> return []
221 (Just c) -> (mapMaybe $ either (\cand -> if word `isPrefixOf` cand
221 (Just c) -> (mapMaybe $ either (\cand -> if word `isPrefixOf` cand
222 then Just $ simpleCompletion cand
222 then Just $ simpleCompletion cand
223 else Nothing) Just)
223 else Nothing) Just)
224− <$> getCompletion c word
224+ <$> getCompletion c
225 return $ sortBy sorter completions
225 return $ sortBy sorter completions
226
226
227− getCompletion :: CompletionContext -> String -> StateT PSCiState IO [Either String Completion]
227+ getCompletion :: CompletionContext -> StateT PSCiState IO [Either String Completion]
228− getCompletion (Command s) _ = return $ (map Left) $ nub $ filter (isPrefixOf s) C.commands
228+ getCompletion (Command s) = return $ (map Left) $ nub $ filter (isPrefixOf s) C.commands
229− getCompletion FilePath f = (map Right) <$> listFiles f
229+ getCompletion (FilePath f) = (map Right) <$> listFiles f
230− getCompletion Module _ = (map Left) <$> getModuleNames
230+ getCompletion Module = (map Left) <$> getModuleNames
231− getCompletion Identifier _ = (map Left) <$> getIdentNames
231+ getCompletion Identifier = (map Left) <$> getIdentNames
232− getCompletion (Fixed list) _ = return $ (map Left) list
232+ getCompletion (Fixed list) = return $ (map Left) list
233− getCompletion (Multiple contexts) f = concat <$> mapM (flip getCompletion $ f) contexts
233+ getCompletion (Multiple contexts) = concat <$> mapM getCompletion contexts
234
234
235 getLoadedModules :: StateT PSCiState IO [P.Module]
235 getLoadedModules :: StateT PSCiState IO [P.Module]
236 getLoadedModules = map snd . psciLoadedModules <$> get
236 getLoadedModules = map snd . psciLoadedModules <$> get