Skip to content
← Back

src/analysis/analyser.ghul

1
@@IF.dotnet()
2
3
namespace Analysis is
4
use System.Exception
5
use IO.Std
6
7
use Collections.Iterable
8
9
use Pair = Collections.KeyValuePair
10
11
use IoC
12
use Logging
13
use Source
14
use Compiler
15
16
trait CommandHandler is
17
handle(request: Protocol.Request, writer: IO.TextWriter)
18
si
19
20
trait SourceFileLookup is
21
file_names: Iterable[string]
22
find_source_file(file_name: string) -> SOURCE_FILE?
23
si
24
25
class ANALYSER is
26
_log: IO.TextWriter
27
_symbol_table: Semantic.SYMBOL_TABLE
28
_timers: TIMERS
29
30
_command_map: Collections.MAP[string,CommandHandler]
31
_despatcher: COMMAND_DESPATCHER
32
33
init(
34
compiler: COMPILER,
35
timers: TIMERS,
36
symbol_table: Semantic.SYMBOL_TABLE,
37
symbol_use_locations: Semantic.SYMBOL_USE_LOCATIONS,
38
symbol_definition_locations: Semantic.SYMBOL_DEFINITION_LOCATIONS,
39
completer: Syntax.Process.COMPLETER,
40
signature_help: Syntax.Process.SIGNATURE_HELP,
41
reader: IO.TextReader,
42
writer: IO.TextWriter,
43
library_files: Iterable[string],
44
build_flags: GLOBAL_BUILD_FLAGS,
45
watchdog: WATCHDOG
46
) is
47
_log = Std.error
48
_timers = timers
49
_symbol_table = symbol_table
50
51
_command_map = Collections.MAP[string,CommandHandler]()
52
53
// Report the whole counter vocabulary from the first STATS
54
// request, so a name that has not fired reads as zero rather
55
// than as absent - the difference between "this path was not
56
// taken" and "this build does not know that path".
57
WORK_COUNTERS.declare_all(_timers)
58
59
build_flags.want_compile_up_to_expressions = true
60
61
let file_edited_handler = FILE_EDITED_HANDLER(watchdog, timers, compiler, build_flags, library_files, symbol_table)
62
63
let edit_delta_handler = EDIT_DELTA_HANDLER(watchdog, file_edited_handler)
64
65
let compile_handler = COMPILE_HANDLER(watchdog, timers, compiler, file_edited_handler, build_flags)
66
67
let full_compiler = FULL_COMPILER(watchdog, compiler, file_edited_handler, timers)
68
69
let despatcher =
70
COMMAND_DESPATCHER(
71
REQUEST_READER(reader),
72
writer,
73
_timers,
74
_log,
75
watchdog,
76
full_compiler,
77
build_flags.want_analysis_stats,
78
build_flags.analysis_idle_timeout_seconds
79
)
80
81
_despatcher = despatcher
82
83
// Let a query that arrived mid-compile be answered at the
84
// next per-file boundary of the compile-expressions walk,
85
// rather than waiting for the whole compile.
86
compiler.on_file_boundary = () is despatcher.serve_pending_queries(); si
87
88
// Let an edit that arrives mid-compile cut that compile short,
89
// rather than have it run on computing diagnostics the edit
90
// has already made stale.
91
compile_handler.is_superseded = () -> bool => despatcher.is_superseded()
92
93
let hover_handler = HOVER_HANDLER(watchdog, timers, symbol_use_locations, full_compiler)
94
let hover_map_handler = HOVERMAP_HANDLER(watchdog, symbol_use_locations)
95
let semantic_tokens_handler = SEMANTICTOKENS_HANDLER(watchdog, symbol_use_locations, file_edited_handler, full_compiler)
96
let inlay_hints_handler = INLAY_HINTS_HANDLER(watchdog)
97
let definition_handler = DEFINITION_HANDLER(watchdog, symbol_use_locations, full_compiler)
98
let declaration_handler = DECLARATION_HANDLER(watchdog, symbol_use_locations, full_compiler)
99
let completion_handler = COMPLETION_HANDLER(watchdog, completer, file_edited_handler, full_compiler)
100
let signature_handler = SIGNATURE_HANDLER(watchdog, signature_help, file_edited_handler)
101
let symbols_handler = SYMBOLS_HANDLER(watchdog, symbol_definition_locations, file_edited_handler, full_compiler)
102
let references_handler = REFERENCES_HANDLER(watchdog, symbol_use_locations, full_compiler)
103
let implementation_handler = IMPLEMENTATION_HANDLER(watchdog, symbol_use_locations, full_compiler)
104
let type_definition_handler = TYPE_DEFINITION_HANDLER(watchdog, symbol_use_locations, full_compiler)
105
let rename_request_handler = RENAME_REQUEST_HANDLER(watchdog, symbol_use_locations, full_compiler)
106
let restart_handler = RESTART_HANDLER(watchdog)
107
let heap_check_handler = HEAP_CHECK_HANDLER(watchdog)
108
let add_references_handler = ADD_REFERENCES_HANDLER(compiler)
109
let stats_handler = STATS_HANDLER(timers)
110
let set_open_files_handler = SET_OPEN_FILES_HANDLER(compiler, file_edited_handler)
111
let format_handler = FORMAT_HANDLER(compiler, build_flags)
112
let format_range_handler = FORMATRANGE_HANDLER(compiler, build_flags)
113
let describe_type_handler = DESCRIBE_TYPE_HANDLER(watchdog, symbol_table, full_compiler)
114
let code_actions_handler = CODE_ACTIONS_HANDLER(watchdog, file_edited_handler)
115
116
_despatcher.add_handler(typeof Protocol.Request.EDIT, file_edited_handler)
117
_despatcher.add_handler(typeof Protocol.Request.EDIT_DELTA, edit_delta_handler)
118
_despatcher.add_handler(typeof Protocol.Request.SET_OPEN_FILES, set_open_files_handler)
119
_despatcher.add_handler(typeof Protocol.Request.COMPILE, compile_handler)
120
_despatcher.add_handler(typeof Protocol.Request.HOVER, hover_handler, true)
121
_despatcher.add_handler(typeof Protocol.Request.HOVER_MAP, hover_map_handler, true)
122
_despatcher.add_handler(typeof Protocol.Request.SEMANTIC_TOKENS, semantic_tokens_handler, true)
123
_despatcher.add_handler(typeof Protocol.Request.INLAY_HINTS, inlay_hints_handler, true)
124
_despatcher.add_handler(typeof Protocol.Request.DEFINITION, definition_handler, true)
125
_despatcher.add_handler(typeof Protocol.Request.DECLARATION, declaration_handler, true)
126
_despatcher.add_handler(typeof Protocol.Request.COMPLETE, completion_handler, true)
127
_despatcher.add_handler(typeof Protocol.Request.SIGNATURE, signature_handler, true)
128
_despatcher.add_handler(typeof Protocol.Request.SYMBOLS, symbols_handler, true)
129
_despatcher.add_handler(typeof Protocol.Request.REFERENCES, references_handler)
130
_despatcher.add_handler(typeof Protocol.Request.IMPLEMENTATION, implementation_handler)
131
_despatcher.add_handler(typeof Protocol.Request.TYPE_DEFINITION, type_definition_handler, true)
132
_despatcher.add_handler(typeof Protocol.Request.RENAME, rename_request_handler)
133
_despatcher.add_handler(typeof Protocol.Request.RESTART, restart_handler)
134
_despatcher.add_handler(typeof Protocol.Request.HEAP_CHECK, heap_check_handler)
135
_despatcher.add_handler(typeof Protocol.Request.ADD_REFERENCES, add_references_handler)
136
_despatcher.add_handler(typeof Protocol.Request.STATS, stats_handler, true)
137
_despatcher.add_handler(typeof Protocol.Request.FORMAT, format_handler)
138
_despatcher.add_handler(typeof Protocol.Request.FORMAT_RANGE, format_range_handler)
139
_despatcher.add_handler(typeof Protocol.Request.DESCRIBE_TYPE, describe_type_handler)
140
_despatcher.add_handler(typeof Protocol.Request.CODE_ACTIONS, code_actions_handler)
141
si
142
143
run() is
144
do
145
if !_despatcher.poll() then
146
_log.write_line("ghūl: exiting")
147
return
148
fi
149
od
150
si
151
si
152
si