CIRCT 22.0.0git
Loading...
Searching...
No Matches
VerilogTextFile.h
Go to the documentation of this file.
1//===----------------------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9// VerilogTextFile.h
10//
11// This header declares VerilogTextFile, a lightweight LSP-facing wrapper
12// around VerilogDocument that represents an open, editable Verilog source
13// buffer in the CIRCT Verilog LSP server.
14//
15// VerilogTextFile owns the current text contents and version (as tracked by
16// the LSP client) and rebuilds its VerilogDocument whenever the file is
17// opened or updated. It also forwards language queries (e.g. “go to
18// definition”, “find references”) to the underlying VerilogDocument, which
19// performs Slang-based parsing, indexing, and location translation.
20//
21//===----------------------------------------------------------------------===//
22
23#ifndef LIB_CIRCT_TOOLS_CIRCT_VERILOG_LSP_SERVER_VERILOGTEXTFILE_H_
24#define LIB_CIRCT_TOOLS_CIRCT_VERILOG_LSP_SERVER_VERILOGTEXTFILE_H_
25
26#include "llvm/Support/LSP/Protocol.h"
27
28#include "VerilogDocument.h"
29
30namespace circt {
31namespace lsp {
32
33struct VerilogServerContext;
34
35/// This class represents a text file containing one or more Verilog
36/// documents.
38public:
40 const llvm::lsp::URIForFile &uri,
41 llvm::StringRef fileContents, int64_t version,
42 std::vector<llvm::lsp::Diagnostic> &diagnostics);
43
44 /// Return the current version of this text file.
45 int64_t getVersion() const { return version; }
46
47 /// Update the file to the new version using the provided set of content
48 /// changes. Returns failure if the update was unsuccessful.
49 llvm::LogicalResult
50 update(const llvm::lsp::URIForFile &uri, int64_t newVersion,
51 llvm::ArrayRef<llvm::lsp::TextDocumentContentChangeEvent> changes,
52 std::vector<llvm::lsp::Diagnostic> &diagnostics);
53
54 void getLocationsOf(const llvm::lsp::URIForFile &uri,
55 llvm::lsp::Position defPos,
56 std::vector<llvm::lsp::Location> &locations);
57
58 void findReferencesOf(const llvm::lsp::URIForFile &uri,
59 llvm::lsp::Position pos,
60 std::vector<llvm::lsp::Location> &references);
61
62private:
63 /// Initialize the text file from the given file contents.
64 void initialize(const llvm::lsp::URIForFile &uri, int64_t newVersion,
65 std::vector<llvm::lsp::Diagnostic> &diagnostics);
66
68
69 /// The full string contents of the file.
70 std::string contents;
71
72 /// The version of this file.
73 int64_t version = 0;
74
75 /// The chunks of this file. The order of these chunks is the order in which
76 /// they appear in the text file.
77 std::unique_ptr<circt::lsp::VerilogDocument> document;
78};
79
80} // namespace lsp
81} // namespace circt
82
83#endif
This class represents a text file containing one or more Verilog documents.
void initialize(const llvm::lsp::URIForFile &uri, int64_t newVersion, std::vector< llvm::lsp::Diagnostic > &diagnostics)
Initialize the text file from the given file contents.
int64_t getVersion() const
Return the current version of this text file.
VerilogServerContext & context
void getLocationsOf(const llvm::lsp::URIForFile &uri, llvm::lsp::Position defPos, std::vector< llvm::lsp::Location > &locations)
void findReferencesOf(const llvm::lsp::URIForFile &uri, llvm::lsp::Position pos, std::vector< llvm::lsp::Location > &references)
std::string contents
The full string contents of the file.
int64_t version
The version of this file.
llvm::LogicalResult update(const llvm::lsp::URIForFile &uri, int64_t newVersion, llvm::ArrayRef< llvm::lsp::TextDocumentContentChangeEvent > changes, std::vector< llvm::lsp::Diagnostic > &diagnostics)
Update the file to the new version using the provided set of content changes.
std::unique_ptr< circt::lsp::VerilogDocument > document
The chunks of this file.
The InstanceGraph op interface, see InstanceGraphInterface.td for more details.