Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

nixd/lib/Controller: disable semantic tokens feature during init #616

Merged
merged 2 commits into from
Nov 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion nixd/docs/features.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,16 @@ Screenshots:

### Semantic Tokens

> [!WARNING]
> This feature is experimental and not enabled by default.

[nixd language server](https://github.com/nix-community/nixd) tries to make some tokens looks different by sending your editor some integers.
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.
> `--semantic-tokens=true` to enable the feature.

#### Attribute name coloring

Expand Down
2 changes: 1 addition & 1 deletion nixd/lib/Controller/LifeTime.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ opt<std::string> DefaultNixOSOptionsExpr{

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

// Here we try to wrap nixpkgs, nixos options in a single emtpy attrset in test.
std::string getDefaultNixpkgsExpr() {
Expand Down
26 changes: 0 additions & 26 deletions nixd/tools/nixd/test/initialize.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,32 +49,6 @@ CHECK-NEXT: "referencesProvider": true,
CHECK-NEXT: "renameProvider": {
CHECK-NEXT: "prepareProvider": true
CHECK-NEXT: },
CHECK-NEXT: "semanticTokensProvider": {
CHECK-NEXT: "full": true,
CHECK-NEXT: "legend": {
CHECK-NEXT: "tokenModifiers": [
CHECK-NEXT: "static",
CHECK-NEXT: "abstract",
CHECK-NEXT: "async"
CHECK-NEXT: ],
CHECK-NEXT: "tokenTypes": [
CHECK-NEXT: "function",
CHECK-NEXT: "string",
CHECK-NEXT: "number",
CHECK-NEXT: "type",
CHECK-NEXT: "keyword",
CHECK-NEXT: "variable",
CHECK-NEXT: "interface",
CHECK-NEXT: "variable",
CHECK-NEXT: "regexp",
CHECK-NEXT: "macro",
CHECK-NEXT: "method",
CHECK-NEXT: "regexp",
CHECK-NEXT: "regexp"
CHECK-NEXT: ]
CHECK-NEXT: },
CHECK-NEXT: "range": false
CHECK-NEXT: },
CHECK-NEXT: "textDocumentSync": {
CHECK-NEXT: "change": 2,
CHECK-NEXT: "openClose": true,
Expand Down
107 changes: 107 additions & 0 deletions nixd/tools/nixd/test/semantic-tokens/initialize.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
# RUN: nixd --lit-test --semantic-tokens=true < %s | FileCheck %s

Check basic handshake with the server, i.e. "initialize"

<-- initialize(0)

```json
{
"jsonrpc":"2.0",
"id":0,
"method":"initialize",
"params":{
"processId":123,
"rootPath":"",
"capabilities":{ },
"trace":"off"
}
}
```

<-- reply:initialize(0)

```
CHECK: {
CHECK-NEXT: "id": 0,
CHECK-NEXT: "jsonrpc": "2.0",
CHECK-NEXT: "result": {
CHECK-NEXT: "capabilities": {
CHECK-NEXT: "codeActionProvider": {
CHECK-NEXT: "codeActionKinds": [
CHECK-NEXT: "quickfix"
CHECK-NEXT: ],
CHECK-NEXT: "resolveProvider": false
CHECK-NEXT: },
CHECK-NEXT: "completionProvider": {
CHECK-NEXT: "resolveProvider": true,
CHECK-NEXT: "triggerCharacters": [
CHECK-NEXT: "."
CHECK-NEXT: ]
CHECK-NEXT: },
CHECK-NEXT: "definitionProvider": true,
CHECK-NEXT: "documentFormattingProvider": true,
CHECK-NEXT: "documentHighlightProvider": true,
CHECK-NEXT: "documentLinkProvider": {},
CHECK-NEXT: "documentSymbolProvider": true,
CHECK-NEXT: "hoverProvider": true,
CHECK-NEXT: "inlayHintProvider": true,
CHECK-NEXT: "referencesProvider": true,
CHECK-NEXT: "renameProvider": {
CHECK-NEXT: "prepareProvider": true
CHECK-NEXT: },
CHECK-NEXT: "semanticTokensProvider": {
CHECK-NEXT: "full": true,
CHECK-NEXT: "legend": {
CHECK-NEXT: "tokenModifiers": [
CHECK-NEXT: "static",
CHECK-NEXT: "abstract",
CHECK-NEXT: "async"
CHECK-NEXT: ],
CHECK-NEXT: "tokenTypes": [
CHECK-NEXT: "function",
CHECK-NEXT: "string",
CHECK-NEXT: "number",
CHECK-NEXT: "type",
CHECK-NEXT: "keyword",
CHECK-NEXT: "variable",
CHECK-NEXT: "interface",
CHECK-NEXT: "variable",
CHECK-NEXT: "regexp",
CHECK-NEXT: "macro",
CHECK-NEXT: "method",
CHECK-NEXT: "regexp",
CHECK-NEXT: "regexp"
CHECK-NEXT: ]
CHECK-NEXT: },
CHECK-NEXT: "range": false
CHECK-NEXT: },
CHECK-NEXT: "textDocumentSync": {
CHECK-NEXT: "change": 2,
CHECK-NEXT: "openClose": true,
CHECK-NEXT: "save": true
CHECK-NEXT: }
CHECK-NEXT: }
CHECK-NEXT: "serverInfo": {
CHECK-NEXT: "name": "nixd",
CHECK-NEXT: "version": {{.*}}
CHECK-NEXT: }
CHECK-NEXT: }
CHECK-NEXT: }
```

<-- initialized

```json
{
"jsonrpc":"2.0",
"method":"initialized",
"params":{

}
}
```


```json
{"jsonrpc":"2.0","method":"exit"}
```
Loading