@@ -9,7 +9,7 @@ import Codec.Serialise qualified as Serialise
99import Control.Concurrent (threadDelay )
1010import Control.Exception (try )
1111import System.FilePath ((</>) , takeDirectory )
12- import Language.PureScript.Names (runModuleName , ProperName (runProperName ), runIdent )
12+ import Language.PureScript.Names (runModuleName , ProperName (runProperName ), runIdent , disqualify , Ident ( .. ) )
1313import Language.PureScript.Externs (ExternsFile (.. ), ExternsImport (.. ))
1414import Data.Foldable (for_ )
1515import Control.Monad.IO.Class (MonadIO (liftIO ))
@@ -31,21 +31,42 @@ import Language.PureScript.Docs.AsMarkdown (codeToString, declAsMarkdown, runDoc
3131import Codec.Serialise (serialise )
3232import Data.Aeson (encode )
3333import Debug.Trace qualified as Debug
34- import Language.PureScript.AST.Declarations (Module )
34+ import Language.PureScript.AST.Declarations (Module , Expr ( Var ), getModuleDeclarations )
3535import Language.PureScript.Ide.Filter.Declaration (DeclarationType (.. ))
3636import Data.Aeson qualified as Aeson
37+ import Language.PureScript.AST.Traversals (everywhereOnValuesM )
38+ import Protolude (identity )
3739
3840sqliteExtern :: (MonadIO m ) => FilePath -> Module -> Docs. Module -> ExternsFile -> m ()
3941sqliteExtern outputDir m docs extern = liftIO $ do
4042 conn <- SQLite. open db
4143
44+ -- Debug.traceM $ show m
45+
46+ let (doDecl, _, _) = everywhereOnValuesM (pure . identity) (\ expr -> case expr of
47+ Var ss i -> do
48+ let iv = disqualify i
49+ case iv of
50+ Ident t -> do
51+ withRetry $ SQLite. executeNamed conn
52+ " insert into asts (module_name, name, span) values (:module_name, :name, :span)"
53+ [ " :module_name" := runModuleName ( efModuleName extern )
54+ , " :name" := t
55+ , " :span" := Aeson. encode ss
56+ ]
57+ _ -> pure ()
58+ pure expr
59+ _ -> pure expr
60+ ) (pure . identity)
61+
4262 withRetry $ SQLite. execute_ conn " pragma foreign_keys = ON;"
4363
4464 withRetry $ SQLite. executeNamed conn
4565 " delete from modules where module_name = :module_name"
4666 [ " :module_name" := runModuleName ( efModuleName extern )
4767 ]
4868
69+
4970 withRetry $ SQLite. executeNamed conn
5071 " insert into modules (module_name, comment, extern, dec) values (:module_name, :docs, :extern, :dec)"
5172 [ " :module_name" := runModuleName ( efModuleName extern )
@@ -54,6 +75,8 @@ sqliteExtern outputDir m docs extern = liftIO $ do
5475 , " :dec" := show ( efExports extern )
5576 ]
5677
78+ for_ (getModuleDeclarations m) (\ d -> doDecl d)
79+
5780 for_ (efImports extern) (\ i -> do
5881 withRetry $ SQLite. executeNamed conn " insert into dependencies (module_name, dependency) values (:module_name, :dependency)"
5982 [ " :module_name" := runModuleName (efModuleName extern )
@@ -191,10 +214,21 @@ sqliteInit outputDir = liftIO $ do
191214 , " )"
192215 ]
193216
217+ withRetry $ SQLite. execute_ conn $ SQLite. Query $ Text. pack $ unlines
218+ [ " create table if not exists asts ("
219+ , " module_name text references modules(module_name) on delete cascade,"
220+ , " name text not null,"
221+ , " span text"
222+ , " )"
223+ ]
224+
194225 withRetry $ SQLite. execute_ conn " create index if not exists dm on declarations(module_name)"
195226 withRetry $ SQLite. execute_ conn " create index if not exists dn on declarations(name);"
227+
228+ withRetry $ SQLite. execute_ conn " create index if not exists asts_module_name_idx on asts(module_name);"
229+ withRetry $ SQLite. execute_ conn " create index if not exists asts_name_idx on asts(name);"
196230
197- withRetry $ SQLite. execute_ conn " create table if not exists ide_declarations (module_name text, name text, namespace text, declaration_type text, span blob, declaration blob)"
231+ withRetry $ SQLite. execute_ conn " create table if not exists ide_declarations (module_name text references modules(module_name) on delete cascade , name text, namespace text, declaration_type text, span blob, declaration blob)"
198232 SQLite. close conn
199233 where
200234 db = outputDir </> " cache.db"
0 commit comments