12#include <boost/asio/post.hpp>
23struct RenameException : std::exception {};
25struct RenameWithException : RenameException {
27 return "cannot rename `with` defined variable";
31struct RenameBuiltinException : RenameException {
33 return "cannot rename builtin variable";
40 llvm::StringRef Src) {
46 throw RenameWithException();
49 throw RenameBuiltinException();
51 std::vector<TextEdit> Edits;
53 for (
const auto *
Use : Def.uses()) {
61 .range =
toLSPRange(Src, Def.syntax()->range()),
65 WE.
changes = std::map<std::string, std::vector<TextEdit>>{
66 {
URI.uri(), std::move(Edits)}};
75 NewText =
Params.newName,
this]()
mutable {
78 if (std::shared_ptr<nixf::Node> AST = getAST(*
TU,
Reply)) [[
likely]] {
81 Reply(
error(
"cannot find corresponding node on given position"));
84 const auto &
PM = *
TU->parentMap();
85 const auto &VLA = *
TU->variableLookup();
88 }
catch (std::exception &E) {
94 boost::asio::post(Pool, std::move(
Action));
97void Controller::onPrepareRename(
104 if (std::shared_ptr<nixf::Node> AST = getAST(*
TU,
Reply)) [[
likely]] {
108 error(
"cannot find corresponding node on given position"));
110 const auto &
PM = *
TU->parentMap();
111 const auto &VLA = *
TU->variableLookup();
115 }
catch (std::exception &E) {
121 boost::asio::post(Pool, std::move(
Action));
Convert between LSP and nixf types.
@ DS_With
From with <expr>;.
const Node * descend(PositionRange Range) const
Descendant node that contains the given range.
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)
bool fromJSON(const llvm::json::Value &Params, Configuration::Diagnostic &R, llvm::json::Path P)
nixf::Position toNixfPosition(const lspserver::Position &P)
const nixf::Definition & findDefinition(const nixf::Node &N, const nixf::ParentMapAnalysis &PMA, const nixf::VariableLookupAnalysis &VLA)
Heuristically find definition on some node.
lspserver::Range toLSPRange(llvm::StringRef Code, const nixf::LexerCursorRange &R)
std::optional< std::map< std::string, std::vector< TextEdit > > > changes
Holds changes to existing resources.