def parse_location(srclocation): loc = symbols.Location(get_value(srclocation, 'file'), get_value(srclocation, 'project')) if loc.is_null(): loc = symbols.InstalledLocation( symbols.parse_package(get_value(srclocation, 'package')), parse_package_db(get_value(srclocation, 'db'))) if loc.is_null(): loc = symbols.OtherLocation(get_value(srclocation, 'source')) return loc if not loc.is_null() else None
def parse_location(srclocation): if srclocation is None: return None if 'file' in srclocation: return symbols.Location( get_value(srclocation, 'file'), get_value(srclocation, 'project'), ) elif 'package' in srclocation: return symbols.InstalledLocation( get_value(srclocation, 'name'), symbols.parse_package(get_value(srclocation, 'package')), ) elif 'source' in srclocation: return symbols.OtherLocation(get_value(srclocation, 'source')) else: raise RuntimeError("Can't parse location: {0}".format(srclocation))
def scope_modules(self, project_name, _filename, lookup='', search_type='prefix', **backend_args): def make_pkg(pkg): pkg_info = pkg.split('-', 2) pkg_name = pkg_info[0] if pkg_info: pkg_ver = pkg_info[1] else: pkg_ver = '<no version>' return symbols.Package(pkg_name, pkg_ver) backend = self.project_backends.get(project_name) modules, err = backend.command_backend( 'list -d') if backend is not None else ([], []) if Settings.COMPONENT_DEBUG.recv_messages or Settings.COMPONENT_DEBUG.all_messages: print('ghc-mod scope_modules: resp =\n{0}'.format(modules)) if not err: filtered_mods = [ symbols.Module( mod[1], [], [], {}, symbols.InstalledLocation( make_pkg(mod[0]), symbols.PackageDb(global_db=True))) for mod in (m.split() for m in modules if self.lookup_match(m[1], lookup, search_type)) ] if Settings.COMPONENT_DEBUG.recv_messages or Settings.COMPONENT_DEBUG.all_messages: print('ghc-mod scope_modules: filtered_mods\n{0}'.format( pprint.pformat(filtered_mods))) return self.dispatch_callbacks(filtered_mods, err, **backend_args)