emacs-lsp / lsp-mode

Emacs client/library for the Language Server Protocol
https://emacs-lsp.github.io/lsp-mode
GNU General Public License v3.0
4.81k stars 890 forks source link

`(wrong-type-argument hash-table-p nil)` when renaming with Haskell Language Server #4473

Open dschrempf opened 5 months ago

dschrempf commented 5 months ago

Thank you for the bug report

Bug description

When trying to lsp-rename a symbol in Haskell (Haskell Language Server, lsp-haskell), I get the following error:

(wrong-type-argument hash-table-p nil) (see also backtrace below).

The lsp-mode logs indicate the language server is not giving a proper response. Is that so?

Steps to reproduce

See above.

Expected behavior

Symbol can be renamed.

Which Language Server did you use?

Haskell Language Server with lsp-haskell.

OS

Linux

Error callstack

Debugger entered--Lisp error: (wrong-type-argument hash-table-p nil)
  lsp--position-to-point(nil)
  lsp--range-to-region(nil)
  lsp--get-symbol-to-rename()
  byte-code("\300\301 !C\207" [lsp--read-rename lsp--get-symbol-to-rename] 2)
  command-execute(lsp-rename)

LSP-log:
[Trace - 09:32:04 AM] Sending request 'textDocument/prepareRename - (4509)'.
Params: {
  "textDocument": {
    "uri": "file:///home/dominik/scratch/haskell/app/Scratch.hs"
  },
  "position": {
    "line": 27,
    "character": 25
  }
}

[Trace - 09:32:04 AM] Received response 'textDocument/prepareRename - (4509)' in 1ms.
Result: {
  "defaultBehavior": true
}

[Trace - 09:32:47 AM] Sending request 'textDocument/hover - (4510)'.
Params: {
  "textDocument": {
    "uri": "file:///home/dominik/scratch/haskell/app/Scratch.hs"
  },
  "position": {
    "line": 27,
    "character": 25
  }
}

[Trace - 09:32:47 AM] Sending request 'textDocument/codeAction - (4511)'.
Params: {
  "textDocument": {
    "uri": "file:///home/dominik/scratch/haskell/app/Scratch.hs"
  },
  "range": {
    "start": {
      "line": 27,
      "character": 25
    },
    "end": {
      "line": 27,
      "character": 25
    }
  },
  "context": {
    "diagnostics": []
  }
}

[Trace - 09:32:47 AM] Received response 'textDocument/codeAction - (4511)' in 3ms.
Result: []

Anything else?

No response

vst commented 5 months ago

I am getting a slightly different error message.

In my case, the stack shows one more function call (lsp--line-character-to-point(nil nil)) that results in:

wrong-type-argument number-or-marker-p nil

... instead of:

wrong-type-argument hash-table-p nil

... as reported in the original bug report.

In case that it matters: I am using emacs-lsp-booster as well.

Debugger entered--Lisp error: (wrong-type-argument number-or-marker-p nil)
  lsp--line-character-to-point(nil nil)
  lsp--position-to-point(nil)
  lsp--range-to-region(nil)
  lsp--get-symbol-to-rename()
  byte-code("\300\301 !C\207" [lsp--read-rename lsp--get-symbol-to-rename] 2)
  command-execute(lsp-rename)
LSP :: lsp-mode 20240610.524, Emacs 29.3, gnu/linux
  "clientInfo": {
    "name": "emacs",
    "version": "GNU Emacs 29.3 (build 1, x86_64-pc-linux-gnu, GTK+ Version 3.24.41, cairo version 1.18.0)"
  }
[Trace - 09:52:52 AM] Sending request 'textDocument/prepareRename - (68)'.
Params: {
  "textDocument": {
    "uri": "file:///<REDACTED>/Repositories/Assessment.hs"
  },
  "position": {
    "line": 739,
    "character": 19
  }
}

[Trace - 09:52:52 AM] Received response 'textDocument/prepareRename - (68)' in 1ms.
Result: {
  "defaultBehavior": true
}

[Trace - 09:52:54 AM] Sending request 'textDocument/codeAction - (69)'.
Params: {
  "textDocument": {
    "uri": "file:///<REDACTED>/Repositories/Assessment.hs"
  },
  "range": {
    "start": {
      "line": 739,
      "character": 19
    },
    "end": {
      "line": 739,
      "character": 19
    }
  },
  "context": {
    "diagnostics": []
  }
}

[Trace - 09:52:54 AM] Received response 'textDocument/codeAction - (69)' in 81ms.
Result: []
Askath commented 4 months ago

Getting the same error for typescript lsp

wrong-type-argument hash-table-p nil

is that also known or should I make a seperate issue for that?

dschrempf commented 4 months ago

I do not get this error with ts-ls.

Askath commented 4 months ago

I do not get this error with ts-ls.

It works on classes but not on variables

const role = this.userRole();

Here for example I want to rename role to foobar and it gives me the wrong-type-argument error

dschrempf commented 4 months ago

Hm, I can not reproduce.

cassandracomar commented 2 months ago

running into the same problem. (setq lsp-rename-use-prepare nil) appears to fix this issue, though. I think the problem is that haskell-language-server isn't sending back an actual symbol when sending textDocument/prepareRename. the flag I just mentioned makes lsp-mode just read the symbol at point instead of trying to get it from the language server.

0x28 commented 2 months ago

The current LSP-spec says the following:

If { defaultBehavior: boolean } is returned (since 3.16) the rename position is valid and the client should use its default behavior to compute the rename range.

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

The trace @vst posted contains the following:

[Trace - 09:52:52 AM] Received response 'textDocument/prepareRename - (68)' in 1ms.
Result: {
  "defaultBehavior": true
}

I think lsp-mode has to compute the symbol at point in this case.