12#include <boost/asio/post.hpp>
19 Callback<std::vector<TextEdit>> Reply) {
20 auto Action = [
this, Params, Reply = std::move(Reply)]()
mutable {
22 const std::string &Code = *Store.
getDraft(
File)->Contents;
24 std::vector<std::string> FormatCommand;
27 std::lock_guard G(ConfigLock);
31 if (FormatCommand.empty()) {
32 Reply(
error(
"formating command is empty, please set external formatter"));
37 std::vector<char *> Syscall;
38 Syscall.reserve(FormatCommand.size());
39 for (
const auto &Str : FormatCommand) {
41 Syscall.emplace_back(
const_cast<char *
>(Str.c_str()));
45 Syscall.emplace_back(
nullptr);
53 execvp(Syscall[0], Syscall.data());
58 const char *Start = Code.c_str();
59 const char *End = Code.c_str() + Code.size();
60 while (Start != End) {
61 if (
long Writen = write(In, Start, End - Start); Writen != -1) {
64 throw std::system_error(errno, std::generic_category());
71 waitpid(Child, &Exit, 0);
74 Reply(
error(
"formatting {0} command exited with {1}", FormatCommand[0],
83 auto Read = read(Out, Buf,
sizeof(Buf));
87 throw std::system_error(errno, std::generic_category());
89 Response.append(Buf,
Read);
92 TextEdit E{{{0, 0}, {INT_MAX, INT_MAX}}, Response};
93 Reply(std::vector{E});
96 boost::asio::post(Pool, std::move(Action));
std::optional< Draft > getDraft(PathRef File) const
Whether current platform treats paths case insensitively.
llvm::unique_function< void(llvm::Expected< T >)> Callback
llvm::Error error(std::error_code EC, const char *Fmt, Ts &&...Vals)
constexpr std::string_view Exit
int forkPiped(int &In, int &Out, int &Err)
fork this process and create some pipes connected to the new process.
URIForFile uri
The text document's URI.
llvm::StringRef file() const
Retrieves absolute path to the file.
struct nixd::Configuration::Formatting formatting