Skip to content
This repository has been archived by the owner on Jan 25, 2024. It is now read-only.

autocompletion is not working in vscode: no suggestions #103

Open
milahu opened this issue Oct 4, 2022 · 1 comment
Open

autocompletion is not working in vscode: no suggestions #103

milahu opened this issue Oct 4, 2022 · 1 comment
Labels
bug Something isn't working

Comments

@milahu
Copy link
Contributor

milahu commented Oct 4, 2022

Describe the bug

vscode says "no suggestions"

autocomplete works for javascript files, so i blame rnix-lsp

Steps to reproduce

edit this nix file

# autocomplete
let pkgs = {
  hello = "echo hello";
  a.b.c = "hello nested";
}; in pkgs.
#12345678901
#          ^ 4:11 = cursor
#         ^ write a dot, press Ctrl+Space

response from rnix-lsp looks ok

jsonrpc: request + response
{
  "jsonrpc": "2.0",
  "id": 4,
  "method": "textDocument/completion",
  "params": {
    "textDocument": {
      "uri": "file:///tmp/test-lsp.nix"
    },
    "position": {
      "line": 4,
      "character": 11
    },
    "context": {
      "triggerKind": 1
    }
  }
}
{
  "jsonrpc": "2.0",
  "id": 4,
  "result": [
    {
      "deprecated": false,
      "detail": "Attribute",
      "label": "hello",
      "textEdit": {
        "newText": "hello",
        "range": {
          "end": {
            "character": 10,
            "line": 4
          },
          "start": {
            "character": 6,
            "line": 4
          }
        }
      }
    },
    {
      "deprecated": false,
      "detail": "Attribute",
      "label": "a",
      "textEdit": {
        "newText": "a",
        "range": {
          "end": {
            "character": 10,
            "line": 4
          },
          "start": {
            "character": 6,
            "line": 4
          }
        }
      }
    }
  ]
}

jsonrpc traffic was captured with

rnix-lsp-wrapper.sh
#! /bin/sh

# rnix-lsp-wrapper.sh

cd "$(dirname "$0")"

tee -a rnix-lsp.in.txt |
./rnix-lsp |
tee -a rnix-lsp.out.txt

Expected behavior

show suggestions

Additional context

  • Version of rnix-lsp: 6925256
  • Name and version of the editor you've used:
  • Operating system:

vscodium

Version: 1.70.0
Commit: da76f93349a72022ca4670c1b84860304616aaa2
Date: 2022-08-05T11:26:33.437Z
Electron: 18.3.5
Chromium: 100.0.4896.160
Node.js: 16.13.2
V8: 10.0.139.17-electron.0
OS: Linux x64 5.15.67

Editor configuration

{
  "nix.enableLanguageServer": true,
  "nix.serverPath": "/tmp/rnix-lsp/target/debug/rnix-lsp-wrapper.sh"
}
@milahu milahu added the bug Something isn't working label Oct 4, 2022
@milahu
Copy link
Contributor Author

milahu commented Oct 9, 2022

on closer look, the textEdit range is wrong

actual: range of pkgs. in line 4

}; in pkgs.
01234567890
{
        "range": {
          "end": {
            "character": 10,
            "line": 4
          },
          "start": {
            "character": 6,
            "line": 4
          }
        }
}

expected: start == end == 4:11

{
        "range": {
          "end": {
            "character": 11,
            "line": 4
          },
          "start": {
            "character": 11,
            "line": 4
          }
        }
}

spec:
https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#textEdit

interface TextEdit {
	/**
	 * The range of the text document to be manipulated. To insert
	 * text into a document create a range where start === end.
	 */
	range: Range;

	/**
	 * The string to be inserted. For delete operations use an
	 * empty string.
	 */
	newText: string;
}

to compare, this works: completion from prefix

# autocomplete
let pkgs = {
  hello = "echo hello";
  a.b.c = "hello nested";
}; in pkgs.hel
#12345678901234
#             ^ 4:14
{
  "jsonrpc": "2.0",
  "id": 8,
  "method": "textDocument/completion",
  "params": {
    "textDocument": {
      "uri": "file:///tmp/test-lsp.nix"
    },
    "position": {
      "line": 4,
      "character": 14
    },
    "context": {
      "triggerKind": 1
    }
  }
}
{
  "jsonrpc": "2.0",
  "id": 8,
  "result": [
    {
      "deprecated": false,
      "detail": "Attribute",
      "label": "hello",
      "textEdit": {
        "newText": "hello",
        "range": {
          "end": {
            "character": 14,
            "line": 4
          },
          "start": {
            "character": 11,
            "line": 4
          }
        }
      }
    }
  ]
}

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant