elbywan / crystalline

A Language Server Protocol implementation for Crystal. 🔮
MIT License
448 stars 25 forks source link

No autocompletion on neovim with nvim-lspconfig #89

Open glyh opened 6 months ago

glyh commented 6 months ago

I've tried to use crystalline multiple times on neovim with nvim-lspconfig, and I get no autocomplete. Is there any information on troubleshooting crystalline?

glyh commented 1 month ago

Hello, I would like to help with this.

I'm on crystal 1.14.0, LLVM: 18.1.8 with crystalline built from 4bac6805fd80a53887bd38628c8ec9b49a9b86bc

Here's what I have with LSPInfo: image

As for LSP log it's empty.

The config is the default given by nvim-lspconfig:

https://github.com/neovim/nvim-lspconfig/blob/d141895d1d9f41048fff201d62a2d6e96d299e32/lua/lspconfig/configs/crystalline.lua#L5

Could you tell me how should I troubleshoot?

glyh commented 1 month ago

Also there's even more weird behavior as this LSP delete some of my code on save when save-on-format is enabled with some other plugins on neovim.

glyh commented 1 month ago

Here's a tmp fix so I can see linting, I'm still having issues with auto formatting/auto completion , though.

lspconfig.crystalline.setup {
  cmd = { "crystalline", "--stdio" },
}
and3md commented 1 month ago

Hi I have the same problem with lsp based autoformat so I start using vim-crystal for auto format:

-- turn on auto format with vim-crystal:
vim.g.crystal_auto_format = 1

add vim-crystal in lazy:

{
    'vim-crystal/vim-crystal',
},

and disable lsp_fallaback for crystal files (code form modified kickstart.nvim):

  { -- Autoformat
    'stevearc/conform.nvim',
    lazy = false,
    keys = {
      {
        '<leader>f',
        function()
          require('conform').format { async = true, lsp_fallback = true }
        end,
        mode = '',
        desc = '[F]ormat buffer',
      },
    },
    opts = {
      notify_on_error = false,
      format_on_save = function(bufnr)
        -- Disable "format_on_save lsp_fallback" for languages that don't
        -- have a well standardized coding style. You can add additional
        -- languages here or re-enable it for the disabled ones.
        local disable_filetypes = { c = true, cpp = true, crystal = true }
        return {
          timeout_ms = 500,
          lsp_fallback = not disable_filetypes[vim.bo[bufnr].filetype],
        }
      end,
      formatters_by_ft = {
        lua = { 'stylua' },
        -- Conform can also run multiple formatters sequentially
        -- python = { "isort", "black" },
        --
        -- You can use a sub-list to tell conform to run *until* a formatter
        -- is found.
        -- javascript = { { "prettierd", "prettier" } },
      },
    },
  },
glyh commented 1 month ago

Hello, thanks, that works now. Only thing that is broken is autocompletion now.

EDIT: it looks like we actually do have auto completion. It's just the quality of autocompletion is pretty bad.

and3md commented 1 month ago

Hello, thanks, that works now. Only thing that is broken is autocompletion now.

EDIT: it looks like we actually do have auto completion. It's just the quality of autocompletion is pretty bad.

It seems to work in the main source file but in others it works quite randomly