29#include "slang/util/CommandLine.h"
38using namespace llvm::lsp;
42 StringRef fileContents, int64_t
version,
43 std::vector<llvm::lsp::Diagnostic> &diagnostics)
51 const llvm::lsp::URIForFile &uri, int64_t newVersion,
52 ArrayRef<llvm::lsp::TextDocumentContentChangeEvent> changes,
53 std::vector<llvm::lsp::Diagnostic> &diagnostics) {
56 if (failed(llvm::lsp::TextDocumentContentChangeEvent::applyTo(changes,
60 return llvm::failure();
64 return llvm::success();
68 if (
context.options.commandFiles.empty())
74 for (
const std::string &cmdFile :
context.options.commandFiles) {
75 if (!
projectDriver->processCommandFiles(cmdFile,
false,
true)) {
82 slang::CommandLine unitCmdLine;
83 std::vector<std::string> includes;
84 unitCmdLine.add(
"-I,--include-directory,+incdir", includes,
"",
"",
85 slang::CommandLineFlags::CommaList);
86 std::vector<std::string> defines;
87 unitCmdLine.add(
"-D,--define-macro,+define", defines,
"");
89 std::optional<std::string> libraryName;
90 unitCmdLine.add(
"--library", libraryName,
"");
92 std::vector<std::string> files;
93 unitCmdLine.setPositional(
94 [&](std::string_view value) {
95 files.emplace_back(value);
100 slang::CommandLine::ParseOptions parseOpts;
101 parseOpts.expandEnvVars =
true;
102 parseOpts.ignoreProgramName =
true;
103 parseOpts.supportComments =
true;
104 parseOpts.ignoreDuplicates =
true;
106 slang::SmallVector<char> buffer;
107 if (
auto readEc = slang::OS::readFile(cmdFile, buffer)) {
110 std::string_view argStr(buffer.data(), buffer.size());
111 if (!unitCmdLine.parse(argStr, parseOpts)) {
115 includes.begin(), includes.end());
119 slang::ast::CompilationFlags::LintMode,
false);
121 slang::ast::CompilationFlags::DisableInstanceCaching,
false);
125 Twine(
"Failed to apply slang options on project "));
136 const llvm::lsp::URIForFile &uri, int64_t newVersion,
137 std::vector<llvm::lsp::Diagnostic> &diagnostics) {
138 std::shared_ptr<VerilogDocument> newDocument;
146 const llvm::lsp::URIForFile &uri, llvm::lsp::Position defPos,
147 std::vector<llvm::lsp::Location> &locations) {
149 doc->getLocationsOf(uri, defPos, locations);
153 const llvm::lsp::URIForFile &uri, llvm::lsp::Position pos,
154 std::vector<llvm::lsp::Location> &references) {
156 doc->findReferencesOf(uri, pos, references);
160 std::scoped_lock<std::shared_mutex> lk(
docMutex);
165 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
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.
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.
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)