Skip to content

Commit

Permalink
nixd: introduce --semantic-tokens=true/false to toggle the feature (#…
Browse files Browse the repository at this point in the history
…470)

Recently @GaetanLepage reported these tokens looks very strange on some
color theme, in vim.

Introduce a CLI flag that completely disable this feature at all.
Because changing color theme might be non-trivial.
  • Loading branch information
inclyc authored Apr 27, 2024
2 parents e1f6f71 + 17e143e commit 7251541
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 34 deletions.
3 changes: 3 additions & 0 deletions nixd/docs/features.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ However, types in nix language is pretty different from standard LSP types.
So, as a result, attrnames, selection, variables are colored as different integers,
but the colors may, or may not rendered properly in your editor.

> [!TIP]
> `--semantic-tokens=false` to disable the feature.
#### Attribute name coloring

Colors may be different for attribute path creating nested attribute set between the path just "select"s into it.
Expand Down
74 changes: 40 additions & 34 deletions nixd/lib/Controller/LifeTime.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
#include "nixd/Controller/Controller.h"
#include "nixd/Eval/Launch.h"

#include <llvm/Support/CommandLine.h>

using namespace nixd;
using namespace util;
using namespace llvm::json;
Expand All @@ -30,6 +32,10 @@ opt<std::string> DefaultNixOSOptionsExpr{
"= (import <nixpkgs/nixos/modules/module-list.nix>) ++ [ ({...}: { "
"nixpkgs.hostPlatform = builtins.currentSystem;} ) ] ; })).options")};

opt<bool> EnableSemanticTokens{"semantic-tokens",
desc("Enable/Disable semantic tokens"),
init(true), cat(NixdCategory)};

// Here we try to wrap nixpkgs, nixos options in a single emtpy attrset in test.
std::string getDefaultNixpkgsExpr() {
if (LitTest && !DefaultNixpkgsExpr.getNumOccurrences()) {
Expand Down Expand Up @@ -95,40 +101,6 @@ void Controller::
{"definitionProvider", true},
{"documentLinkProvider", Object{}},
{"documentSymbolProvider", true},
{
"semanticTokensProvider",
Object{
{
"legend",
Object{
{"tokenTypes",
Array{
"function", // function
"string", // string
"number", // number
"type", // select
"keyword", // builtin
"variable", // constant
"interface", // fromWith
"variable", // variable
"regexp", // null
"macro", // bool
"method", // attrname
"regexp", // lambdaArg
"regexp", // lambdaFormal
}},
{"tokenModifiers",
Array{
"static", // builtin
"abstract", // deprecated
"async", // dynamic
}},
},
},
{"range", false},
{"full", true},
},
},
{"inlayHintProvider", true},
{"completionProvider",
Object{
Expand All @@ -145,6 +117,40 @@ void Controller::
}}},
};

if (EnableSemanticTokens) {
ServerCaps["semanticTokensProvider"] = Object{
{
"legend",
Object{
{"tokenTypes",
Array{
"function", // function
"string", // string
"number", // number
"type", // select
"keyword", // builtin
"variable", // constant
"interface", // fromWith
"variable", // variable
"regexp", // null
"macro", // bool
"method", // attrname
"regexp", // lambdaArg
"regexp", // lambdaFormal
}},
{"tokenModifiers",
Array{
"static", // builtin
"abstract", // deprecated
"async", // dynamic
}},
},
},
{"range", false},
{"full", true},
};
}

Object Result{{
{"serverInfo",
Object{
Expand Down

0 comments on commit 7251541

Please sign in to comment.