29#include "slang/util/CommandLine.h"
31#include "../Utils/LSPUtils.h"
39using namespace llvm::lsp;
43 StringRef fileContents, int64_t version,
44 std::vector<llvm::lsp::Diagnostic> &diagnostics)
45 : context(context), contents(fileContents.str()) {
52 const llvm::lsp::URIForFile &uri, int64_t newVersion,
53 ArrayRef<llvm::lsp::TextDocumentContentChangeEvent> changes,
54 std::vector<llvm::lsp::Diagnostic> &diagnostics) {
57 if (failed(llvm::lsp::TextDocumentContentChangeEvent::applyTo(changes,
76 if (!
projectDriver->processCommandFiles(cmdFile,
false,
true)) {
83 slang::CommandLine unitCmdLine;
84 std::vector<std::string> includes;
85 unitCmdLine.add(
"-I,--include-directory,+incdir", includes,
"",
"",
86 slang::CommandLineFlags::CommaList);
87 std::vector<std::string> defines;
88 unitCmdLine.add(
"-D,--define-macro,+define", defines,
"");
90 std::optional<std::string> libraryName;
91 unitCmdLine.add(
"--library", libraryName,
"");
93 std::vector<std::string> files;
94 unitCmdLine.setPositional(
95 [&](std::string_view value) {
96 files.emplace_back(value);
101 slang::CommandLine::ParseOptions parseOpts;
102 parseOpts.expandEnvVars =
true;
103 parseOpts.ignoreProgramName =
true;
104 parseOpts.supportComments =
true;
105 parseOpts.ignoreDuplicates =
true;
107 slang::SmallVector<char> buffer;
108 if (
auto readEc = slang::OS::readFile(cmdFile, buffer)) {
111 std::string_view argStr(buffer.data(), buffer.size());
112 if (!unitCmdLine.parse(argStr, parseOpts)) {
116 includes.begin(), includes.end());
120 slang::ast::CompilationFlags::LintMode,
false);
122 slang::ast::CompilationFlags::DisableInstanceCaching,
false);
126 Twine(
"Failed to apply slang options on project "));
137 const llvm::lsp::URIForFile &uri, int64_t newVersion,
138 std::vector<llvm::lsp::Diagnostic> &diagnostics) {
139 std::shared_ptr<VerilogDocument> newDocument;
147 const llvm::lsp::URIForFile &uri, llvm::lsp::Position defPos,
148 std::vector<llvm::lsp::Location> &locations) {
150 doc->getLocationsOf(uri, defPos, locations);
154 const llvm::lsp::URIForFile &uri, llvm::lsp::Position pos,
155 std::vector<llvm::lsp::Location> &references) {
157 doc->findReferencesOf(uri, pos, references);
161 std::scoped_lock<std::shared_mutex> lk(
docMutex);
166 std::scoped_lock<std::shared_mutex> lk(
docMutex);
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.
std::unique_ptr< slang::driver::Driver > projectDriver
The project-scale driver.
std::shared_ptr< VerilogDocument > getDocument()
Return document for read access.
VerilogServerContext & context
void getLocationsOf(const llvm::lsp::URIForFile &uri, llvm::lsp::Position defPos, std::vector< llvm::lsp::Location > &locations)
Return position of definition of an object pointed to by pos.
void findReferencesOf(const llvm::lsp::URIForFile &uri, llvm::lsp::Position pos, std::vector< llvm::lsp::Location > &references)
Return all references to an object pointed to by pos.
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.
VerilogTextFile(VerilogServerContext &globalContext, const llvm::lsp::URIForFile &uri, llvm::StringRef fileContents, int64_t version, std::vector< llvm::lsp::Diagnostic > &diagnostics)
Initialize a new VerilogTextFile and its VerilogDocument.
std::shared_mutex contentMutex
A mutex to control updates of contents.
void initializeProjectDriver()
std::shared_mutex docMutex
A mutex to control updates of document; Acquire AFTER contentMutex.
std::vector< std::string > projectIncludeDirectories
std::shared_ptr< circt::lsp::VerilogDocument > document
The chunks of this file.
void setDocument(std::shared_ptr< VerilogDocument > newDoc)
Override document after update.
void error(Twine message)
const circt::lsp::VerilogServerOptions & options
const std::vector< std::string > & commandFiles
Additional list of command files that reference dependencies of the project.