Permalink
Browse files

Several fixes, fixed import completion, fixed ghc-mod default cwd

  • Loading branch information...
1 parent 4233973 commit 8e4a96561d553597909dd18b7347137e5b13fb9d @mvoidex mvoidex committed Mar 23, 2013
Showing with 38 additions and 25 deletions.
  1. +23 −8 autocomplete.py
  2. +5 −5 cache.py
  3. +10 −12 sublime_haskell_common.py
View
@@ -11,13 +11,15 @@
import symbols
import cache
import util
+ from ghci import ghci_info
from haskell_docs import haskell_docs
from hdevtools import start_hdevtools, stop_hdevtools
else:
from SublimeHaskell.sublime_haskell_common import *
import SublimeHaskell.symbols as symbols
import SublimeHaskell.cache as cache
import SublimeHaskell.util as util
+ from SublimeHaskell.ghci import ghci_info
from SublimeHaskell.haskell_docs import haskell_docs
from SublimeHaskell.hdevtools import start_hdevtools, stop_hdevtools
@@ -142,6 +144,7 @@ def get_completions(self, view, prefix, locations):
"Get all the completions that apply to the current file."
current_file_name = view.file_name()
+ self.current_filename = current_file_name
# Contents of the line under the first cursor
line_contents = get_line_contents(view, locations[0])
@@ -253,12 +256,24 @@ def module_next_name(mname):
return list(set((module_next_name(m) + '\t(module)', module_next_name(m)) for m in module_list if m.startswith(qualified_prefix)))
def get_current_module_completions(self):
+ completions = []
+
+ cabal = current_cabal()
+
+ with self.database.cabal_modules as cabal_modules:
+ if cabal in cabal_modules:
+ completions.extend(list(cabal_modules[cabal].keys()))
+
+ if self.current_filename:
+ (project_path, _) = get_cabal_project_dir_and_name_of_file(self.current_filename)
+ if project_path:
+ completions.extend([m.name for m in self.database.get_project_modules(project_path)])
+
with self.module_completions as module_completions:
- cabal = current_cabal()
- if cabal not in module_completions:
- # TODO: update modules info!
- return set()
- return module_completions[cabal].copy()
+ if cabal in module_completions:
+ completions.extend(module_completions[cabal])
+
+ return set(completions)
autocompletion = AutoCompletion()
@@ -276,7 +291,7 @@ def can_complete_qualified_symbol(info):
if is_import_list:
return module_name in autocompletion.get_current_module_completions()
else:
- return list(filter(lambda m: m.startswith(module_name), autocompletion.get_current_module_completions()) != [])
+ return list(filter(lambda m: m.startswith(module_name), autocompletion.get_current_module_completions())) != []
class SublimeHaskellComplete(sublime_plugin.TextCommand):
""" Shows autocompletion popup """
@@ -419,8 +434,8 @@ def run(self, edit, filename = None, module_name = None, decl = None):
import_list.extend(files[current_file_name].imports.keys())
if module_word:
- # Full qualified name, just call to info
- info = util.symbol_info(module_word, ident)
+ # Full qualified name, just call to ghci_info
+ info = ghci_info(module_word, ident)
if info:
self.show_symbol_info(info)
return
View
@@ -92,11 +92,11 @@ def dump_cabal_cache(database, cabal_name = None):
with open(cabal_json, 'w') as f:
f.write(formatted_json)
-def dump_project_cache(database, project_name):
+def dump_project_cache(database, project_path):
formatted_json = None
- project_modules = database.get_project_modules(project_name)
+ project_modules = database.get_project_modules(project_path)
with database.files:
- project_json = os.path.join(PROJECTS_CACHE_PATH, escape_path(project_name) + '.json')
+ project_json = os.path.join(PROJECTS_CACHE_PATH, escape_path(project_path) + '.json')
formatted_json = encode_json(project_modules, indent = 2)
with open(project_json, 'w') as f:
f.write(formatted_json)
@@ -115,9 +115,9 @@ def load_cabal_cache(database, cabal_name = None):
for m in cabal_modules.values():
database.add_module(m, cabal_name)
-def load_project_cache(database, project_name):
+def load_project_cache(database, project_path):
formatted_json = None
- project_json = os.path.join(PROJECTS_CACHE_PATH, escape_path(project_name) + '.json')
+ project_json = os.path.join(PROJECTS_CACHE_PATH, escape_path(project_path) + '.json')
if os.path.exists(project_json):
with open(project_json, 'r') as f:
formatted_json = f.read()
View
@@ -344,7 +344,8 @@ def get_source_dir(filename):
Get root of hs-source-dirs for filename in project
"""
if not filename:
- return os.getcwd()
+ return os.path.expanduser('~')
+ # return os.getcwd()
(cabal_dir, project_name) = get_cabal_project_dir_and_name_of_file(filename)
if not cabal_dir:
@@ -377,27 +378,28 @@ def get_cwd(filename = None):
cwd = (get_cabal_project_dir_of_file(filename) or os.path.dirname(filename)) if filename else os.getcwd()
return cwd
-def get_ghc_opts(filename = None):
+def get_ghc_opts(filename = None, add_package_db = True):
"""
Gets ghc_opts, used in several tools, as list with extra '-package-db' option and '-i' option if filename passed
"""
ghc_opts = get_setting_async('ghc_opts')
if not ghc_opts:
ghc_opts = []
- package_db = ghci_package_db()
- if package_db:
- ghc_opts.append('-package-db {0}'.format(package_db))
+ if add_package_db:
+ package_db = ghci_package_db()
+ if package_db:
+ ghc_opts.append('-package-db {0}'.format(package_db))
if filename:
ghc_opts.append('-i {0}'.format(get_source_dir(filename)))
return ghc_opts
-def get_ghc_opts_args(filename = None):
+def get_ghc_opts_args(filename = None, add_package_db = True):
"""
Same as ghc_opts, but uses '-g' option for each option
"""
- opts = get_ghc_opts(filename)
+ opts = get_ghc_opts(filename, add_package_db)
args = []
for opt in opts:
args.extend(["-g", opt])
@@ -409,11 +411,7 @@ def call_ghcmod_and_wait(arg_list, filename=None, cabal = None):
Shows a sublime error message if ghc-mod is not available.
"""
- ghc_opts = get_setting_async('ghc_opts')
- ghc_opts_args = []
- if ghc_opts:
- for opt in ghc_opts:
- ghc_opts_args.extend(["-g", opt])
+ ghc_opts_args = get_ghc_opts_args(filename, add_package_db = False)
try:
command = attach_cabal_sandbox(['ghc-mod'] + arg_list + ghc_opts_args, cabal)

0 comments on commit 8e4a965

Please sign in to comment.