23#include <boost/asio/post.hpp>
34std::optional<std::string> resolveExprPath(
const std::string &BasePath,
37 namespace fs = std::filesystem;
39 fs::path
Path = fs::absolute((BasePath)).remove_filename().append(
ExprPath);
41 if (!fs::exists(
Path))
44 if (fs::is_directory(
Path))
45 return Path.append(
"default.nix");
50void dfs(
const Node *N,
const std::string &BasePath,
51 std::vector<DocumentLink> &Links, llvm::StringRef Src) {
56 case Node::NK_ExprPath: {
59 if (
Path.parts().isLiteral()) {
61 if (
auto Link = resolveExprPath(BasePath,
Path.parts().literal())) {
75 dfs(Ch, BasePath, Links, Src);
81void Controller::onDocumentLink(
84 using CheckTy = std::vector<DocumentLink>;
86 Reply = std::move(Reply),
this]()
mutable {
87 return Reply([&]() -> llvm::Expected<CheckTy> {
92 std::vector<DocumentLink> Links;
93 dfs(AST.get(),
File, Links, TU->src());
97 boost::asio::post(Pool, std::move(Action));
#define CheckDefault(x)
Variant of CheckReturn, but returns default constructed CheckTy
Convert between LSP and nixf types.
LexerCursorRange range() const
virtual ChildVector children() const =0
Whether current platform treats paths case insensitively.
llvm::unique_function< void(llvm::Expected< T >)> Callback
lspserver::Range toLSPRange(llvm::StringRef Code, const nixf::LexerCursorRange &R)
Parameters for the document link request.
TextDocumentIdentifier textDocument
The document to provide document links for.
URIForFile uri
The text document's URI.
static URIForFile canonicalize(llvm::StringRef AbsPath, llvm::StringRef TUPath)
llvm::StringRef file() const
Retrieves absolute path to the file.