10#include <boost/asio/post.hpp>
11#include <llvm/ADT/StringRef.h>
27 return "(anonymous lambda)";
28 return Lambda.arg()->id()->name();
54 if (
Var.id().name() ==
"true" ||
Var.id().name() ==
"false") {
55 Sym.kind = SymbolKind::Boolean;
56 Sym.detail =
"builtin boolean";
60 if (
Var.id().name() ==
"null") {
61 Sym.kind = SymbolKind::Null;
68 if (
Result.Kind == ResultKind::Defined)
69 Sym.kind = SymbolKind::Constant;
70 else if (
Result.Kind == ResultKind::FromWith)
71 Sym.kind = SymbolKind::Variable;
73 Sym.deprecated =
true;
77 if (
Result.Def->isBuiltin())
78 Sym.kind = SymbolKind::Event;
86 switch (AST->
kind()) {
88 case Node::NK_ExprString: {
91 .
name =
Str.isLiteral() ?
Str.literal() :
"(dynamic string)",
93 .kind = SymbolKind::String,
102 case Node::NK_ExprInt: {
103 const auto &Int =
static_cast<const ExprInt &
>(*AST);
105 .
name = std::to_string(Int.value()),
107 .kind = SymbolKind::Number,
110 .selectionRange =
toLSPRange(Src, Int.range()),
116 case Node::NK_ExprFloat: {
117 const auto &Float =
static_cast<const ExprFloat &
>(*AST);
119 .
name = std::to_string(Float.value()),
121 .kind = SymbolKind::Number,
124 .selectionRange =
toLSPRange(Src, Float.range()),
130 case Node::NK_AttrName: {
131 const auto &
AN =
static_cast<const AttrName &
>(*AST);
133 .
name =
AN.isStatic() ?
AN.staticName() :
"(dynamic attribute name)",
134 .detail =
"attribute name",
135 .kind = SymbolKind::Property,
144 case Node::NK_ExprVar: {
145 const auto &
Var =
static_cast<const ExprVar &
>(*AST);
148 .detail =
"identifier",
149 .kind = SymbolKind::Variable,
159 case Node::NK_ExprLambda: {
160 std::vector<DocumentSymbol>
Children;
166 .kind = SymbolKind::Function,
175 case Node::NK_ExprList: {
176 std::vector<DocumentSymbol>
Children;
178 for (
const Node *
Ch : AST->children())
182 .
name =
"{anonymous}",
184 .kind = SymbolKind::Array,
193 case Node::NK_ExprAttrs: {
195 for (
const auto &[Name,
Attr] : SA.staticAttrs()) {
198 std::vector<DocumentSymbol>
Children;
202 .detail =
"attribute",
203 .kind = SymbolKind::Field,
212 std::vector<DocumentSymbol>
Children;
215 .
name =
"${dynamic attribute}",
216 .detail =
"attribute",
217 .kind = SymbolKind::Field,
229 for (
const Node *
Ch : AST->children())
241 if (std::shared_ptr<NixTU>
TU = getTU(
URI.file().str(),
Reply)) {
242 if (std::shared_ptr<Node> AST = getAST(*
TU,
Reply)) {
243 std::vector<DocumentSymbol>
Symbols;
249 boost::asio::post(Pool, std::move(
Action));
Convert between LSP and nixf types.
Lookup variable names, from it's parent scope.
const SemaAttrs & sema() const
std::string_view src(std::string_view Src) const
Attribute set after deduplication.
LookupResult query(const ExprVar &Var) const
Query the which name/with binds to specific varaible.
Whether current platform treats paths case insensitively.
llvm::unique_function< void(llvm::Expected< T >)> Callback
bool fromJSON(const llvm::json::Value &Params, Configuration::Diagnostic &R, llvm::json::Path P)
lspserver::Position toLSPPosition(llvm::StringRef Code, const nixf::LexerCursor &P)
lspserver::Range toLSPRange(llvm::StringRef Code, const nixf::LexerCursorRange &R)
std::string name
The name of this symbol.