18#include <boost/asio/post.hpp>
48struct RawSemanticToken {
51 return Pos <
Other.Pos;
55 unsigned TokenModifiers;
58class SemanticTokenBuilder {
64 std::vector<RawSemanticToken> Raw;
70 : VLA(VLA), Src(Src) {}
72 unsigned TokenModifiers) {
74 Raw.emplace_back(RawSemanticToken{P, Length, TokenType, TokenModifiers});
77 void add(
const Node &
N,
unsigned TokenType,
unsigned TokenModifiers) {
85 return N.range().lCur().line() !=
N.range().rCur().line();
89 return N.range().rCur().offset() -
N.range().lCur().offset();
100 if (
Var.id().name() ==
"true" ||
Var.id().name() ==
"false") {
105 if (
Var.id().name() ==
"null") {
116 if (
Result.Kind == ResultKind::Defined) {
120 if (
Result.Kind == ResultKind::FromWith) {
130 dfs(
Select.defaultExpr());
133 for (
const std::shared_ptr<nixf::AttrName> &Name :
Select.path()->names()) {
146 for (
const auto &[Name,
Attr] : SA.staticAttrs()) {
152 if (
Attr.fromInherit())
157 for (
const auto &
Attr : SA.dynamicAttrs()) {
167 for (
const auto &[_,
Formal] : Arg.formals()->dedup()) {
181 void dfs(
const Node *AST) {
184 switch (AST->
kind()) {
185 case Node::NK_ExprLambda: {
190 case Node::NK_ExprString: {
195 case Node::NK_ExprVar: {
196 const auto &
Var =
static_cast<const ExprVar &
>(*AST);
200 case Node::NK_ExprSelect: {
205 case Node::NK_ExprAttrs: {
211 for (
const Node *
Ch : AST->children()) {
217 std::vector<SemanticToken>
finish() {
218 std::vector<SemanticToken>
Tokens;
219 std::sort(Raw.begin(), Raw.end());
221 for (
auto Elm : Raw) {
240 if (std::shared_ptr<NixTU>
TU = getTU(
URI.file().str(),
Reply)) {
241 if (std::shared_ptr<Node> AST = getAST(*
TU,
Reply)) {
242 SemanticTokenBuilder
Builder(*
TU->variableLookup(),
TU->src());
248 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
Formals * formals() const
A point in the source file.
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 operator<(const CompletionItem &, const CompletionItem &)
bool fromJSON(const llvm::json::Value &Params, Configuration::Diagnostic &R, llvm::json::Path P)
lspserver::Position toLSPPosition(llvm::StringRef Code, const nixf::LexerCursor &P)
Body of textDocument/semanticTokens/full request.
A versioned set of tokens.
std::vector< SemanticToken > tokens
The actual tokens.