nixd
Toggle main menu visibility
Loading...
Searching...
No Matches
nixd
lib
Controller
CodeActions
ExtractToFile.h
Go to the documentation of this file.
1
/// \file
2
/// \brief Code action for extracting expressions to separate files.
3
///
4
/// Allows users to select any Nix expression and extract it to a new file,
5
/// automatically generating an import statement with appropriate argument
6
/// passing for free variables.
7
8
#pragma once
9
10
#include <
lspserver/Protocol.h
>
11
12
#include <
nixf/Sema/ParentMap.h
>
13
#include <
nixf/Sema/VariableLookup.h
>
14
15
#include <llvm/ADT/StringRef.h>
16
17
#include <string>
18
#include <vector>
19
20
namespace
nixf
{
21
class
Node
;
22
}
// namespace nixf
23
24
namespace
nixd
{
25
26
/// \brief Add extract-to-file action for selected expressions.
27
///
28
/// This action is offered when the cursor is on any valid Nix expression.
29
/// It creates a new file with the expression content and replaces the original
30
/// expression with an import statement. If the expression contains free
31
/// variables (variables used but not defined within the expression), they are
32
/// wrapped in a lambda in the new file.
33
///
34
/// Example transformation:
35
/// Original: { buildInputs = [ pkgs.foo pkgs.bar ]; }
36
/// New file (buildInputs.nix): { pkgs }: [ pkgs.foo pkgs.bar ]
37
/// Replaced: { buildInputs = import ./buildInputs.nix { inherit pkgs; }; }
38
void
addExtractToFileAction
(
const
nixf::Node &N,
39
const
nixf::ParentMapAnalysis &PM,
40
const
nixf::VariableLookupAnalysis &VLA,
41
const
std::string &FileURI, llvm::StringRef Src,
42
std::vector<lspserver::CodeAction> &Actions);
43
44
}
// namespace nixd
ParentMap.h
ParentMap analysis.
VariableLookup.h
Lookup variable names, from it's parent scope.
nixf::Node
Definition
Basic.h:12
Protocol.h
nixd
Definition
CommandLine/Configuration.h:9
nixd::addExtractToFileAction
void addExtractToFileAction(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 extract-to-file action for selected expressions.
Definition
ExtractToFile.cpp:322
nixf
Definition
Diagnostic.h:19
Generated by
1.17.0