@@ -9,7 +9,7 @@ import Codec.Serialise qualified as Serialise
9
9
import Control.Concurrent (threadDelay )
10
10
import Control.Exception (try )
11
11
import System.FilePath ((</>) , takeDirectory )
12
- import Language.PureScript.Names (runModuleName , ProperName (runProperName ), runIdent )
12
+ import Language.PureScript.Names (runModuleName , ProperName (runProperName ), runIdent , disqualify , Ident ( .. ) )
13
13
import Language.PureScript.Externs (ExternsFile (.. ), ExternsImport (.. ))
14
14
import Data.Foldable (for_ )
15
15
import Control.Monad.IO.Class (MonadIO (liftIO ))
@@ -31,21 +31,42 @@ import Language.PureScript.Docs.AsMarkdown (codeToString, declAsMarkdown, runDoc
31
31
import Codec.Serialise (serialise )
32
32
import Data.Aeson (encode )
33
33
import Debug.Trace qualified as Debug
34
- import Language.PureScript.AST.Declarations (Module )
34
+ import Language.PureScript.AST.Declarations (Module , Expr ( Var ), getModuleDeclarations )
35
35
import Language.PureScript.Ide.Filter.Declaration (DeclarationType (.. ))
36
36
import Data.Aeson qualified as Aeson
37
+ import Language.PureScript.AST.Traversals (everywhereOnValuesM )
38
+ import Protolude (identity )
37
39
38
40
sqliteExtern :: (MonadIO m ) => FilePath -> Module -> Docs. Module -> ExternsFile -> m ()
39
41
sqliteExtern outputDir m docs extern = liftIO $ do
40
42
conn <- SQLite. open db
41
43
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
+
42
62
withRetry $ SQLite. execute_ conn " pragma foreign_keys = ON;"
43
63
44
64
withRetry $ SQLite. executeNamed conn
45
65
" delete from modules where module_name = :module_name"
46
66
[ " :module_name" := runModuleName ( efModuleName extern )
47
67
]
48
68
69
+
49
70
withRetry $ SQLite. executeNamed conn
50
71
" insert into modules (module_name, comment, extern, dec) values (:module_name, :docs, :extern, :dec)"
51
72
[ " :module_name" := runModuleName ( efModuleName extern )
@@ -54,6 +75,8 @@ sqliteExtern outputDir m docs extern = liftIO $ do
54
75
, " :dec" := show ( efExports extern )
55
76
]
56
77
78
+ for_ (getModuleDeclarations m) (\ d -> doDecl d)
79
+
57
80
for_ (efImports extern) (\ i -> do
58
81
withRetry $ SQLite. executeNamed conn " insert into dependencies (module_name, dependency) values (:module_name, :dependency)"
59
82
[ " :module_name" := runModuleName (efModuleName extern )
@@ -191,10 +214,21 @@ sqliteInit outputDir = liftIO $ do
191
214
, " )"
192
215
]
193
216
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
+
194
225
withRetry $ SQLite. execute_ conn " create index if not exists dm on declarations(module_name)"
195
226
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);"
196
230
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)"
198
232
SQLite. close conn
199
233
where
200
234
db = outputDir </> " cache.db"
0 commit comments