nixd
Loading...
Searching...
No Matches
WithToLet.h
Go to the documentation of this file.
1/// \file
2/// \brief Code action for converting `with` expressions to `let/inherit`.
3///
4/// Transforms: with lib; expr -> let inherit (lib) usedVars; in expr
5/// This makes variable sources explicit and improves code clarity.
6
7#pragma once
8
10
11#include <nixf/Sema/ParentMap.h>
13
14#include <llvm/ADT/StringRef.h>
15
16#include <string>
17#include <vector>
18
19namespace nixf {
20class Node;
21} // namespace nixf
22
23namespace nixd {
24
25/// \brief Add code action to convert `with` expression to `let/inherit`.
26///
27/// This action is offered when the cursor is on the `with` keyword.
28/// It transforms `with source; body` into `let inherit (source) vars; in body`
29/// where vars are all variables used from the with scope.
30///
31/// The action is NOT offered when:
32/// - The cursor is not on the `with` keyword
33/// - No variables are used from the with scope (unused with)
34/// - The with body is directly another with expression (nested with chains)
35void addWithToLetAction(const nixf::Node &N, const nixf::ParentMapAnalysis &PM,
36 const nixf::VariableLookupAnalysis &VLA,
37 const std::string &FileURI, llvm::StringRef Src,
38 std::vector<lspserver::CodeAction> &Actions);
39
40} // namespace nixd
ParentMap analysis.
Lookup variable names, from it's parent scope.
void addWithToLetAction(const nixf::Node &N, const nixf::ParentMapAnalysis &PM, const nixf::VariableLookupAnalysis &VLA, const std::string &FileURI, llvm::StringRef Src, std::vector< lspserver::CodeAction > &Actions)
Add code action to convert with expression to let/inherit.