-
Notifications
You must be signed in to change notification settings - Fork 212
/
verilog-language-server.h
97 lines (74 loc) · 3.49 KB
/
verilog-language-server.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
// Copyright 2021-2022 The Verible Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#ifndef VERILOG_TOOLS_LS_LS_WRAPPER_H
#define VERILOG_TOOLS_LS_LS_WRAPPER_H
#include <string>
#include "absl/status/status.h"
#include "absl/strings/string_view.h"
#include "common/lsp/json-rpc-dispatcher.h"
#include "common/lsp/lsp-protocol.h"
#include "common/lsp/lsp-text-buffer.h"
#include "common/lsp/message-stream-splitter.h"
#include "verilog/tools/ls/lsp-parse-buffer.h"
#include "verilog/tools/ls/symbol-table-handler.h"
namespace verilog {
// TODO add support for changing workspace
// TODO reset symbol table on workspace change?
// Class implementing the Language Server for Verilog
class VerilogLanguageServer {
public:
using ReadFun = verible::lsp::MessageStreamSplitter::ReadFun;
using WriteFun = verible::lsp::JsonRpcDispatcher::WriteFun;
// Constructor preparing the callbacks for Language Server requests
explicit VerilogLanguageServer(const WriteFun &write_fun);
// Reads single request and responds to it (public to mock in tests).
absl::Status Step(const ReadFun &read_fun);
// Runs the Language Server, calling "read_fun" until we receive shutdown.
absl::Status Run(const ReadFun &read_fun);
// Prints statistics of the current Language Server session.
void PrintStatistics() const;
// A flag that sets inclusion of variables into documentSymbol requests
bool include_variables = true;
private:
// Creates callbacks for requests from Language Server Client
void SetRequestHandlers();
// The "initialize" method requests server capabilities.
verible::lsp::InitializeResult InitializeRequestHandler(
const verible::lsp::InitializeParams ¶ms);
// Returns language server capabilities in textDocument/initialize response
// format
verible::lsp::InitializeResult GetCapabilities();
// sets up the VerilogProject structure for symbol table, sets listeners for
// updating VerilogProject views for edited files
// if "project_root" is an empty string, set to either current directory
// or directory containing verible.filelist
void ConfigureProject(absl::string_view project_root);
// Publish a diagnostic sent to the server.
void SendDiagnostics(const std::string &uri,
const verilog::BufferTracker &buffer_tracker);
// Stream splitter splits the input stream into messages (header/body).
verible::lsp::MessageStreamSplitter stream_splitter_;
// Parser for JSON messages from LS client
verible::lsp::JsonRpcDispatcher dispatcher_;
// Object for keeping track of updates in opened buffers on client's side
verible::lsp::BufferCollection text_buffers_;
// Tracks changes in buffers from BufferCollection and parses their contents
verilog::BufferTrackerContainer parsed_buffers_;
// Handles requests relying on the symbol table
verilog::SymbolTableHandler symbol_table_handler_;
// A flag for indicating "shutdown" request
bool shutdown_requested_ = false;
};
} // namespace verilog
#endif // VERILOG_TOOLS_LS_LS_WRAPPER_H