1 // Copyright 2019 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #include <fstream>
6 #include <iostream>
7 #include <sstream>
8 
9 #include "src/torque/ls/globals.h"
10 #include "src/torque/ls/message-handler.h"
11 #include "src/torque/ls/message-pipe.h"
12 #include "src/torque/server-data.h"
13 #include "src/torque/source-positions.h"
14 
15 namespace v8 {
16 namespace internal {
17 namespace torque {
18 namespace ls {
19 
WrappedMain(int argc, const char** argv)20 int WrappedMain(int argc, const char** argv) {
21   Logger::Scope log_scope;
22   TorqueFileList::Scope files_scope;
23   LanguageServerData::Scope server_data_scope;
24   SourceFileMap::Scope source_file_map_scope("");
25   DiagnosticsFiles::Scope diagnostics_files_scope;
26 
27   for (int i = 1; i < argc; ++i) {
28     if (!strcmp("-l", argv[i])) {
29       Logger::Enable(argv[++i]);
30       break;
31     }
32   }
33 
34   while (true) {
35     JsonValue message = ReadMessage();
36 
37     // TODO(szuend): We should probably offload the actual message handling
38     //               (even the parsing) to a background thread, so we can
39     //               keep receiving messages. We might also receive
40     //               $/cancelRequests or contet updates, that require restarts.
41     HandleMessage(std::move(message), &WriteMessage);
42   }
43 }
44 
45 }  // namespace ls
46 }  // namespace torque
47 }  // namespace internal
48 }  // namespace v8
49 
main(int argc, const char** argv)50 int main(int argc, const char** argv) {
51   return v8::internal::torque::ls::WrappedMain(argc, argv);
52 }
53