From ba84c8884fe8975998d1fd7749524dd18ab8f325 Mon Sep 17 00:00:00 2001 From: Yingchi Long Date: Sat, 27 Apr 2024 10:24:12 +0800 Subject: [PATCH 1/2] nixd: introduce `--semantic-tokens=true/false` to toggle the feature --- nixd/lib/Controller/LifeTime.cpp | 74 +++++++++++++++++--------------- 1 file changed, 40 insertions(+), 34 deletions(-) diff --git a/nixd/lib/Controller/LifeTime.cpp b/nixd/lib/Controller/LifeTime.cpp index 4354f6478..f2025f683 100644 --- a/nixd/lib/Controller/LifeTime.cpp +++ b/nixd/lib/Controller/LifeTime.cpp @@ -9,6 +9,8 @@ #include "nixd/Controller/Controller.h" #include "nixd/Eval/Launch.h" +#include + using namespace nixd; using namespace util; using namespace llvm::json; @@ -30,6 +32,10 @@ opt DefaultNixOSOptionsExpr{ "= (import ) ++ [ ({...}: { " "nixpkgs.hostPlatform = builtins.currentSystem;} ) ] ; })).options")}; +opt 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()) { @@ -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{ @@ -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{ From 17e143e9f176f11c81e9ac267f169cb11f6b4fbb Mon Sep 17 00:00:00 2001 From: Yingchi Long Date: Sat, 27 Apr 2024 10:41:53 +0800 Subject: [PATCH 2/2] docs: add a tip to tell users they can disable that --- nixd/docs/features.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/nixd/docs/features.md b/nixd/docs/features.md index d4da4c519..9476df0df 100644 --- a/nixd/docs/features.md +++ b/nixd/docs/features.md @@ -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.