forked from SublimeHaskell/SublimeHaskell
-
Notifications
You must be signed in to change notification settings - Fork 1
/
haskell_docs.py
31 lines (28 loc) · 1.13 KB
/
haskell_docs.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import re
import os
import sublime
import sublime_plugin
if int(sublime.version()) < 3000:
from sublime_haskell_common import *
else:
from SublimeHaskell.sublime_haskell_common import *
def haskell_docs(module, name):
"""
Returns info for name as multiline string
"""
try:
(exit_code, stdout, stderr) = call_and_wait(["haskell-docs", module, name])
stdout = crlf2lf(stdout)
if exit_code == 0:
ambigousRe = '^Ambiguous module, belongs to more than one package: (.*)$'
continueRe = '^Continuing anyway... $'
cantFindRe = '^Couldn\'t find name ``{0}\'\' in Haddock interface: (.*)$'.format(name)
packageRe = '^Package: (.*)$'
ignoreRe = '({0})|({1})|({2})|({3})'.format(ambigousRe, continueRe, cantFindRe, packageRe)
# Remove debug messages
result = list(filter(lambda l: not re.match(ignoreRe, l), stdout.splitlines()))
return '\n'.join(result)
except OSError as e:
if e.errno == errno.ENOENT:
log("haskell-docs not found, no docs available, try 'cabal install haskell-docs'")
return None