1+ # -----------------------------------------------------------------------
2+ # This file is part of MoonScript
3+ #
4+ # MoonSript is free software: you can redistribute it and/or modify
5+ # it under the terms of the GNU General Public License as published by
6+ # the Free Software Foundation, either version 3 of the License, or
7+ # (at your option) any later version.
8+ #
9+ # MoonSript is distributed in the hope that it will be useful,
10+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
11+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+ # GNU General Public License for more details.
13+ #
14+ # You should have received a copy of the GNU General Public License
15+ # along with MoonSript. If not, see <https://www.gnu.org/licenses/>.
16+ #
17+ # Copyright (C) 2025 Krisna Pranav, MoonScript Developers
18+ # -----------------------------------------------------------------------
19+
20+ module MoonScript
21+ class Workspace
22+ getter result: TypeChecker | Error = Error .new(:uninitialized_workspace )
23+
24+ @cache : Hash (String , Ast | Error ) = {} of String => Ast | Error
25+
26+ @listener : Proc (TypeChecker | Error , Nil ) | Nil
27+
28+ def initialize (* , @listener : Proc (TypeChecker | Error , Nil ) | Nil , @include_tests : Bool , dot_env: String , @format : Bool , @check : Check , @path : String )
29+ @dot_env = File .basename(dot_env)
30+
31+ (@watcher = Watcher .new(&- > update(Array (String ), Symbol )))
32+ .tap { reset }
33+ .watch
34+ end
35+
36+ def update (contents: String , path: String ) : Nil
37+ @cache [path] = Parser .parse?(contents, path)
38+ end
39+
40+ def delete (path: String ) : Nil
41+ @cache .delete(path)
42+ end
43+ end
44+ end
0 commit comments