Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Collecting more info in ModuleInspector

  • Loading branch information...
commit b9886d35af6da2cbc2c13ae8dd1c898f5f3fb619 1 parent bce6f9f
@mvoidex mvoidex authored
Showing with 46 additions and 21 deletions.
  1. +23 −14 ModuleInspector.hs
  2. +11 −4 autocomplete.py
  3. +12 −3 symbols.py
View
37 ModuleInspector.hs
@@ -46,18 +46,23 @@ instance Json.ToJSON ImportInfo where
-- | Information about a single type or function declaration.
data DeclarationInfo = DeclarationInfo
{ _declLocation :: H.SrcLoc
+ , _declarationWhat :: String
, _nameOfDeclaration :: String
- , _typeInfo :: String
+ , _functionType :: Maybe String
+ , _typeContext :: Maybe [String]
+ , _typeArgs :: Maybe [String]
}
deriving (Show)
instance Json.ToJSON DeclarationInfo where
- toJSON (DeclarationInfo (H.SrcLoc _ l c) name typeInfo) = Json.object
- [ "info" .= typeInfo
- , "identifier" .= name
- , "line" .= l
- , "column" .= c
- ]
+ toJSON (DeclarationInfo (H.SrcLoc _ l c) what name funType ctx args) = Json.object [
+ "line" .= l,
+ "column" .= c,
+ "what" .= what,
+ "name" .= name,
+ "type" .= funType,
+ "context" .= ctx,
+ "args" .= args]
-- | Process a single file's contents.
analyzeModule :: String -> Either String ModuleInfo
@@ -69,7 +74,7 @@ analyzeModule source = case H.parseFileContents source of
{ _moduleName = moduleName
, _exportList = Nothing
, _imports = map infoOfImport imports
- , _declarations = concatMap nameOfDecl declarations
+ , _declarations = concatMap declInfo declarations
}
-- | Get module name for import
@@ -79,17 +84,21 @@ infoOfImport d = ImportInfo (mname (H.importModule d)) (H.importQualified d) (fm
-- | Get the relevant information about of a top-level declaration.
-- Return Nothing if the declaration is not interesting.
-nameOfDecl :: H.Decl -> [DeclarationInfo]
-nameOfDecl decl = case decl of
+declInfo :: H.Decl -> [DeclarationInfo]
+declInfo decl = case decl of
H.TypeSig loc names typeSignature -> map
(\n -> DeclarationInfo
loc
+ "function"
(identOfName n)
- (":: " ++ H.prettyPrint typeSignature))
+ (Just $ H.prettyPrint typeSignature)
+ Nothing
+ Nothing)
names
- H.TypeDecl loc n _ _ -> [DeclarationInfo loc (identOfName n) "(type)"]
- H.DataDecl loc _ _ n _ _ _ -> [DeclarationInfo loc (identOfName n) "(data)"]
- H.ClassDecl loc _ n _ _ _ -> [DeclarationInfo loc (identOfName n) "(class)"]
+ H.TypeDecl loc n args _ -> [DeclarationInfo loc "type" (identOfName n) Nothing Nothing (Just $ map H.prettyPrint args)]
+ H.DataDecl loc _ ctx n args _ _ -> [DeclarationInfo loc "data" (identOfName n) Nothing (Just $ map H.prettyPrint ctx) (Just $ map H.prettyPrint args)]
+ H.GDataDecl loc _ ctx n args _ _ _ -> [DeclarationInfo loc "data" (identOfName n) Nothing (Just $ map H.prettyPrint ctx) (Just $ map H.prettyPrint args)]
+ H.ClassDecl loc ctx n args _ _ -> [DeclarationInfo loc "class" (identOfName n) Nothing (Just $ map H.prettyPrint ctx) (Just $ map H.prettyPrint args)]
_ -> []
identOfName :: H.Name -> String
View
15 autocomplete.py
@@ -752,10 +752,17 @@ def make_import(import_info):
import_list = new_info['exportList'] if ('exportList' in new_info and new_info['exportList'] is not None) else []
new_module = symbols.Module(new_info['moduleName'], import_list, module_imports, {}, filename)
for d in new_info['declarations']:
- # TODO: Get specific declaration info by 'info' member?
- new_decl = symbols.Declaration(d['identifier'])
- new_decl.location = symbols.Location(filename, d['line'], d['column'])
- new_module.add_declaration(new_decl)
+ location = symbols.Location(filename, d['line'], d['column'])
+ if d['what'] == 'function':
+ new_module.add_declaration(symbols.Function(d['name'], d['type'], None, location))
+ elif d['what'] == 'type':
+ new_module.add_declaration(symbols.Type(d['name'], d['context'], d['args'], None, location))
+ elif d['what'] == 'data':
+ new_module.add_declaration(symbols.Data(d['name'], d['context'], d['args'], None, location))
+ elif d['what'] == 'class':
+ new_module.add_declaration(symbols.Class(d['name'], d['context'], d['args'], None, location))
+ else:
+ new_module.add_declaration(symbols.Declaration(d['name'], 'declaration', None, location))
autocompletion.database.add_file(filename, new_module)
View
15 symbols.py
@@ -129,7 +129,16 @@ def suggest(self):
return ('{0}\t{1}'.format(self.name, ' '.join(self.args)), self.snippet())
def brief(self):
- return ' '.join([self.name] + self.args)
+ brief_parts = []
+ if self.context:
+ if len(self.context) == 1:
+ brief_parts.append('{0} =>'.format(self.context[0]))
+ else:
+ brief_parts.append('({0}) =>'.format(', '.join(self.context)))
+ brief_parts.append(self.name)
+ if self.args:
+ brief_parts.append(' '.join(self.args))
+ return ' '.join(brief_parts)
class Type(TypeBase):
"""
@@ -143,14 +152,14 @@ class Data(TypeBase):
Haskell data declaration
"""
def __init__(self, name, context, args, docs = None, location = None, module = None):
- super(Type, self).__init__(name, 'data', context, args, docs, location, module)
+ super(Data, self).__init__(name, 'data', context, args, docs, location, module)
class Class(Declaration):
"""
Haskell class declaration
"""
def __init__(self, name, context, args, docs = None, location = None, module = None):
- super(Type, self).__init__(name, 'class', context, args, docs, location, module)
+ super(Class, self).__init__(name, 'class', context, args, docs, location, module)
def update_with(l, r, default_value, f):
"""
Please sign in to comment.
Something went wrong with that request. Please try again.