mrcjkb / haskell-tools.nvim

🦥 Supercharge your Haskell experience in neovim!
GNU General Public License v2.0
432 stars 18 forks source link

HSC file's error message is inundating!!! #372

Closed NamelessDev0000 closed 2 months ago

NamelessDev0000 commented 2 months ago

Neovim version (nvim -v)

v0.10.0

Operating system/version

Archlinux Rolling

Output of :checkhealth haskell-tools

haskell-tools: require("haskell-tools.health").check()

Checking for Lua dependencies ~
- OK [nvim-telescope/telescope.nvim](https://github.com/nvim-telescope/telescope.nvim) installed.

Checking external dependencies ~
- OK haskell-language-server: found haskell-language-server version: 2.7.0.0 (GHC: 9.2.8) (PATH: /home/even/.local/share/nvim/mason/packages/haskell-language-server/lib/haskell-language-server-2.7.0.0/bin/haskell-language-server-wrapper)
- OK hoogle: found Hoogle 5.0.18.4, https://hoogle.haskell.org/
- OK fast-tags: found fast-tags, version 2.0.2
- OK curl: found curl 8.8.0 (x86_64-pc-linux-gnu) libcurl/8.8.0 OpenSSL/3.3.0 zlib/1.3.1 brotli/1.1.0 zstd/1.5.6 libidn2/2.3.7 libpsl/0.21.5 libssh2/1.11.0 nghttp2/1.62.1 nghttp3/1.3.0
- OK haskell-debug-adapter: found haskell-debug-adapter-0.0.39.0
- OK ghci-dap: found The Glorious Glasgow Haskell Compilation System, version 9.6.5

Checking config ~
- OK No errors found in config.

Checking for conflicting plugins ~
- OK No conflicting plugins detected.

How to reproduce the issue

Create any .hsc. file such this:

{-# LANGUAGE CPP, ForeignFunctionInterface #-}
{-# LANGUAGE UnboxedTuples #-}
{-# LANGUAGE MagicHash #-}
{-# LANGUAGE UnliftedFFITypes #-}

#define PCRE2_CODE_UNIT_WIDTH 16

#include <pcre.h>
#include <pcre2.h>

module Text.Regex.PCRE2.Demo.Base (
  PCREOption,
  PCRE,
  PCRE2_Code,
  PCRE2_Compile_Context,
  caseless,
  dollar_endonly,
  dotall,
  c_pcre_compile,
  c_pcre2_compile,
) where

import Data.Bits        ((.|.))
import Foreign.C.Types  (CInt(CInt), CSize(CSize))
import Foreign.C.String (CString)
import Foreign.Ptr      (Ptr)
import Data.Word        (Word8)
import GHC.Base         (Word32##)

newtype PCREOption = PCREOption CInt

instance Semigroup PCREOption where
  (PCREOption a) <> (PCREOption b) = PCREOption (a .|. b)

instance Monoid PCREOption where
  mempty = PCREOption 0

#{enum PCREOption, PCREOption
, caseless       = PCRE_CASELESS
, dollar_endonly = PCRE_DOLLAR_ENDONLY
, dotall         = PCRE_DOTALL
}

data PCRE

foreign import ccall unsafe "pcre.h pcre_compile"
  c_pcre_compile :: CString
                 -> PCREOption
                 -> Ptr CString
                 -> Ptr CInt
                 -> Ptr Word8
                 -> IO (Ptr PCRE)

data PCRE2_Code
data PCRE2_Compile_Context

-- pcre2_code *
-- pcre2_compile(PCRE2_SPTR pattern,
--              PCRE2_SIZE length,,
--              uint32_t options,,
--              int *errorcode,
--              PCRE2_SIZE *erroroffset,
--              pcre2_compile_context *ccontext); 
foreign import ccall unsafe "pcre2.h pcre2_compile"
  c_pcre2_compile :: CString
                  -> CSize
                  -> Word32##
                  -> Ptr CInt
                  -> Ptr CSize
                  -> Ptr PCRE2_Compile_Context
                  -> Ptr PCRE2_Code

Expected behaviour

At lease, we should have a option to block such bothering warning rather than let it destroy user's FFI coding experience.

Actual behaviour

图片 图片

Log files

No response

The minimal config used to reproduce this issue.

nothing special, any haskell-tools.nvim installation will reproduce this problem...(I'm using lazyvim now.
mrcjkb commented 2 months ago

Hey :wave:

this is a haskell-language-server issue, not related to haskell-tools. You can disable auto_attach for .hsc files. See :h haskell-tools.config.

NamelessDev0000 commented 2 months ago

Hey 👋

this is a haskell-language-server issue, not related to haskell-tools. You can disable auto_attach for .hsc files. See :h haskell-tools.config.

sry, i can't understand how to use it? it doesn't accept any parameters and seemed to be a const function... could you paste a example here?

NamelessDev0000 commented 2 months ago

Hey 👋

this is a haskell-language-server issue, not related to haskell-tools. You can disable auto_attach for .hsc files. See :h haskell-tools.config.

thx for your reply, successfully solved.

NamelessDev0000 commented 2 months ago

A possible solution:

return {
  {
    "mrcjkb/haskell-tools.nvim",

    config = function()
      vim.g.haskell_tools = {
        hls = {
          auto_attach = function()
            local bufnr = vim.api.nvim_get_current_buf()
            local filename = vim.api.nvim_buf_get_name(bufnr)
            return not filename:match("%.hsc$")
          end,
        },
      }
    end,
  },
}