Appearance
| 1 | namespace Analysis is | |
| 2 | use System.Exception; | |
| 3 | use IO.Std; | |
| 4 | ||
| 5 | use Collections.Iterable; | |
| 6 | ||
| 7 | use Pair = Collections.KeyValuePair; | |
| 8 | ||
| 9 | use IoC; | |
| 10 | use Logging; | |
| 11 | use Source; | |
| 12 | use Compiler; | |
| 13 | ||
| 14 | trait CommandHandler is | |
| 15 | handle(request: Protocol.Request, writer: IO.TextWriter); | |
| 16 | si | |
| 17 | ||
| 18 | trait SourceFileLookup is | |
| 19 | file_names: Iterable[string]; | |
| 20 | find_source_file(file_name: string) -> SOURCE_FILE?; | |
| 21 | si | |
| 22 | ||
| 23 | class ANALYSER is | |
| 24 | _log: IO.TextWriter; | |
| 25 | _symbol_table: Semantic.SYMBOL_TABLE; | |
| 26 | _compiler: COMPILER; | |
| 27 | _timers: TIMERS; | |
| 28 | ||
| 29 | _command_map: Collections.MAP[string,CommandHandler]; | |
| 30 | _despatcher: COMMAND_DESPATCHER; | |
| 31 | ||
| 32 | init( | |
| 33 | compiler: COMPILER, | |
| 34 | timers: TIMERS, | |
| 35 | symbol_table: Semantic.SYMBOL_TABLE, | |
| 36 | symbol_use_locations: Semantic.SYMBOL_USE_LOCATIONS, | |
| 37 | symbol_definition_locations: Semantic.SYMBOL_DEFINITION_LOCATIONS, | |
| 38 | completer: Syntax.Process.COMPLETER, | |
| 39 | signature_help: Syntax.Process.SIGNATURE_HELP, | |
| 40 | reader: IO.TextReader, | |
| 41 | writer: IO.TextWriter, | |
| 42 | library_files: Iterable[string], | |
| 43 | build_flags: GLOBAL_BUILD_FLAGS, | |
| 44 | watchdog: WATCHDOG | |
| 45 | ) is | |
| 46 | _log = Std.error; | |
| 47 | _timers = timers; | |
| 48 | _symbol_table = symbol_table; | |
| 49 | ||
| 50 | _command_map = Collections.MAP[string,CommandHandler](); | |
| 51 | ||
| 52 | // Report the whole counter vocabulary from the first STATS | |
| 53 | // request, so a name that has not fired reads as zero rather | |
| 54 | // than as absent - the difference between "this path was not | |
| 55 | // taken" and "this build does not know that path". | |
| 56 | WORK_COUNTERS.declare_all(_timers); | |
| 57 | ||
| 58 | _despatcher = COMMAND_DESPATCHER(reader, writer, _timers, _log, watchdog, build_flags.want_analysis_stats); | |
| 59 | ||
| 60 | build_flags.want_compile_up_to_expressions = true; | |
| 61 | ||
| 62 | let file_edited_handler = FILE_EDITED_HANDLER(watchdog, timers, compiler, build_flags, library_files, symbol_table); | |
| 63 | ||
| 64 | let compile_handler = COMPILE_HANDLER(watchdog, timers, compiler, file_edited_handler, build_flags); | |
| 65 | ||
| 66 | let full_compiler = FULL_COMPILER(watchdog, compiler, file_edited_handler, timers); | |
| 67 | ||
| 68 | let hover_handler = HOVER_HANDLER(watchdog, timers, symbol_use_locations, full_compiler); | |
| 69 | let hover_map_handler = HOVERMAP_HANDLER(watchdog, symbol_use_locations); | |
| 70 | let semantic_tokens_handler = SEMANTICTOKENS_HANDLER(watchdog, symbol_use_locations, file_edited_handler, full_compiler); | |
| 71 | let inlay_hints_handler = INLAY_HINTS_HANDLER(watchdog); | |
| 72 | let definition_handler = DEFINITION_HANDLER(watchdog, symbol_use_locations, full_compiler); | |
| 73 | let declaration_handler = DECLARATION_HANDLER(watchdog, symbol_use_locations, full_compiler); | |
| 74 | let completion_handler = COMPLETION_HANDLER(watchdog, completer, file_edited_handler, full_compiler); | |
| 75 | let signature_handler = SIGNATURE_HANDLER(watchdog, signature_help, file_edited_handler); | |
| 76 | let symbols_handler = SYMBOLS_HANDLER(watchdog, symbol_definition_locations, file_edited_handler, full_compiler); | |
| 77 | let references_handler = REFERENCES_HANDLER(watchdog, symbol_use_locations, full_compiler); | |
| 78 | let implementation_handler = IMPLEMENTATION_HANDLER(watchdog, symbol_use_locations, full_compiler); | |
| 79 | let type_definition_handler = TYPE_DEFINITION_HANDLER(watchdog, symbol_use_locations, full_compiler); | |
| 80 | let rename_request_handler = RENAME_REQUEST_HANDLER(watchdog, symbol_use_locations, full_compiler); | |
| 81 | let restart_handler = RESTART_HANDLER(watchdog); | |
| 82 | let heap_check_handler = HEAP_CHECK_HANDLER(watchdog); | |
| 83 | let stats_handler = STATS_HANDLER(timers); | |
| 84 | let set_open_files_handler = SET_OPEN_FILES_HANDLER(compiler); | |
| 85 | let format_handler = FORMAT_HANDLER(compiler, build_flags); | |
| 86 | let format_range_handler = FORMATRANGE_HANDLER(compiler, build_flags); | |
| 87 | let describe_type_handler = DESCRIBE_TYPE_HANDLER(watchdog, symbol_table, full_compiler); | |
| 88 | ||
| 89 | _despatcher.add_handler(typeof Protocol.Request.EDIT, file_edited_handler); | |
| 90 | _despatcher.add_handler(typeof Protocol.Request.SET_OPEN_FILES, set_open_files_handler); | |
| 91 | _despatcher.add_handler(typeof Protocol.Request.COMPILE, compile_handler); | |
| 92 | _despatcher.add_handler(typeof Protocol.Request.HOVER, hover_handler); | |
| 93 | _despatcher.add_handler(typeof Protocol.Request.HOVER_MAP, hover_map_handler); | |
| 94 | _despatcher.add_handler(typeof Protocol.Request.SEMANTIC_TOKENS, semantic_tokens_handler); | |
| 95 | _despatcher.add_handler(typeof Protocol.Request.INLAY_HINTS, inlay_hints_handler); | |
| 96 | _despatcher.add_handler(typeof Protocol.Request.DEFINITION, definition_handler); | |
| 97 | _despatcher.add_handler(typeof Protocol.Request.DECLARATION, declaration_handler); | |
| 98 | _despatcher.add_handler(typeof Protocol.Request.COMPLETE, completion_handler); | |
| 99 | _despatcher.add_handler(typeof Protocol.Request.SIGNATURE, signature_handler); | |
| 100 | _despatcher.add_handler(typeof Protocol.Request.SYMBOLS, symbols_handler); | |
| 101 | _despatcher.add_handler(typeof Protocol.Request.REFERENCES, references_handler); | |
| 102 | _despatcher.add_handler(typeof Protocol.Request.IMPLEMENTATION, implementation_handler); | |
| 103 | _despatcher.add_handler(typeof Protocol.Request.TYPE_DEFINITION, type_definition_handler); | |
| 104 | _despatcher.add_handler(typeof Protocol.Request.RENAME, rename_request_handler); | |
| 105 | _despatcher.add_handler(typeof Protocol.Request.RESTART, restart_handler); | |
| 106 | _despatcher.add_handler(typeof Protocol.Request.HEAP_CHECK, heap_check_handler); | |
| 107 | _despatcher.add_handler(typeof Protocol.Request.STATS, stats_handler); | |
| 108 | _despatcher.add_handler(typeof Protocol.Request.FORMAT, format_handler); | |
| 109 | _despatcher.add_handler(typeof Protocol.Request.FORMAT_RANGE, format_range_handler); | |
| 110 | _despatcher.add_handler(typeof Protocol.Request.DESCRIBE_TYPE, describe_type_handler); | |
| 111 | si | |
| 112 | ||
| 113 | run() is | |
| 114 | do | |
| 115 | if !_despatcher.poll() then | |
| 116 | _log.write_line("ghūl: exiting"); | |
| 117 | return; | |
| 118 | fi | |
| 119 | od | |
| 120 | si | |
| 121 | si | |
| 122 | si |