forked from SublimeHaskell/SublimeHaskell
-
Notifications
You must be signed in to change notification settings - Fork 0
/
util.py
66 lines (57 loc) · 2.07 KB
/
util.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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# -*- coding: UTF-8 -*-
import sublime
if int(sublime.version()) < 3000:
import ghci
import ghcmod
import haskell_docs
import hdevtools
import sublime_haskell_common as common
else:
import SublimeHaskell.ghci as ghci
import SublimeHaskell.ghcmod as ghcmod
import SublimeHaskell.haskell_docs as haskell_docs
import SublimeHaskell.hdevtools as hdevtools
import SublimeHaskell.sublime_haskell_common as common
def symbol_info(filename, module_name, symbol_name, cabal = None, no_ghci = False):
result = None
if hdevtools.hdevtools_enabled():
result = hdevtools.hdevtools_info(filename, symbol_name, cabal = cabal)
if not result and ghcmod.ghcmod_enabled():
result = ghcmod.ghcmod_info(filename, module_name, symbol_name, cabal = cabal)
if not result and not filename and not no_ghci:
result = ghci.ghci_info(module_name, symbol_name, cabal = cabal)
return result
def load_docs(decl):
"""
Tries to load docs for decl
"""
if decl.docs is None:
decl.docs = haskell_docs.haskell_docs(decl.module.name, decl.name)
def refine_type(decl, no_ghci = True):
"""
Refine type for sources decl
"""
if decl.location:
if decl.what == 'function' and not decl.type:
info = symbol_info(decl.location.filename, decl.module.name, decl.name, None, no_ghci = no_ghci)
if info:
decl.type = info.type
def refine_decl(decl):
"""
Refine decl information.
"""
# Symbol from cabal, try to load detailed info with ghci
if not decl.location:
load_docs(decl)
if decl.what == 'declaration':
decl_detailed = ghci.ghci_info(decl.module.name, decl.name)
if decl_detailed:
decl.__dict__.update(decl_detailed.__dict__)
# Symbol from sources, concrete type if it's not specified
else:
refine_type(decl, False)
def browse_module(module_name, cabal = None):
"""
Returns symbols.Module with all declarations
"""
return ghcmod.ghcmod_browse_module(module_name, cabal = cabal)