haskell / haskell-language-server

Official haskell ide support via language server (LSP). Successor of ghcide & haskell-ide-engine.
Apache License 2.0
2.72k stars 368 forks source link

Tab character incorrectly assumed to be composed of 8 characters #1987

Open LiraOnGithub opened 3 years ago

LiraOnGithub commented 3 years ago

Your environment

Output of haskell-language-server --probe-tools or haskell-language-server-wrapper --probe-tools:

haskell-language-server version: 1.0.0.0 (GHC: 8.10.4) (PATH: [MYHOME]/.ghcup/bin/haskell-language-server-wrapper-1.0.0) (GIT hash: 4cd1cf934638881e52b3eba9f70157a4b799c0e9)
Tool versions found on the $PATH
cabal:          3.4.0.0
stack:          2.7.1
ghc:            8.6.5

Which OS do you use: Ubuntu

Which lsp-client do you use: Vim with Coc

Describe your project (alternative: link to the project): stack-project

Contents of hie.yaml:

cradle:
  stack:
      component: "name-of-project:lib"

Steps to reproduce

Type the following code

module Test where

main :: IO ()
main = do
    putStr "hello" -- there is a tab-character (\t) in front of putStr

And request information about putStr

Expected behaviour

I should get a pop-up with type information and a short description.

Actual behaviour

I get a pop-up about IO instead. If I put my cursor further ahead, over the string "hello", I do get information about putStr. It seems HLS treats a tab as 8 separate characters. Setting a tab-size of 8 does not help, since it is still one character.

Include debug information

Paste the logs from the lsp-client, e.g. for VS Code

LSP logs: The first part is when the cursor is on `putStr` and gives information about `IO`, the second part is when the cursor is on the last part of "hello" and gives information about `putStr` File: [hls-output.txt](https://github.com/haskell/haskell-language-server/files/6727553/hls-output.txt) Gist: [hls-output.txt gist](https://gist.github.com/LiraOnGithub/42d94188632e3343a83f9e98a24bd149) Please let me know if you need more of the output.
joeyh commented 3 years ago

I am also hit by this bug. Using emacs here. (I've disabled the usual emacs indent stuff since I do use tabs.)

LiraOnGithub commented 10 months ago

I tried digging a bit in the code but the only thing relating to tabs that I could find are Language.LSP.Protocol.Types.FormattingOptions._tabSize and Language.LSP.Protocol.Lens.HasTabSize

I could not find a single place in the code where a FormattingOptions is set with a tabsize of 8. Could it be that it is read from a config file?

michaelpj commented 10 months ago

I think this may be ultimately related to https://github.com/haskell/haskell-language-server/issues/2646 and our broken handling of unicode.