Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Filetypes empty with "nim" files and formatting doesn't work #240

Open
mogita opened this issue Feb 20, 2023 · 0 comments
Open

Filetypes empty with "nim" files and formatting doesn't work #240

mogita opened this issue Feb 20, 2023 · 0 comments

Comments

@mogita
Copy link

mogita commented Feb 20, 2023

Hi, my efm config in neovim works for all my other languages except for nim. The :LspInfo panel shows the filetypes as empty, and the format on save would not work if I opened a nim file in the neovim editor. I have nimpretty installed and it formats nim source files correctly when I ran it from the command line.

How should I fix this so nim files can also be formated on save? Thanks.

Here's the screenshot of :LspInfo:

SCR-20230220-ub3

Here are my relevant configs:

------------------------------------------------------------
-- formatters
------------------------------------------------------------
local prettierFmt = { formatCommand = 'prettier --config-precedence prefer-file --stdin-filepath ${INPUT}', formatStdin = true }
local luaFmt = { formatCommand = "lua-format -i", formatStdin = true }
local nimFmt = { formatCommand = "nimpretty", formatStdin = true }

------------------------------------------------------------
-- efm setup
------------------------------------------------------------
nvim_lsp.efm.setup {
  init_options = {
    documentFormatting = true
  },
  settings = {
    rootMarkers = {'.git', 'package.json', 'packages.json'},
    languages = {
      lua = {luaFmt},
      typescript = {prettierFmt},
      javascript = {prettierFmt},
      typescriptreact = {prettierFmt},
      javascriptreact = {prettierFmt},
      ["javascript.jsx"] = {prettierFmt},
      ["typescript.tsx"] = {prettierFmt},
      json = {prettierFmt},
      html = {prettierFmt},
      less = {prettierFmt},
      scss = {prettierFmt},
      css = {prettierFmt},
      markdown = {prettierFmt},
      nim = {nimFmt}
    },
    filetypes = {
      "javascript",
      "javascriptreact",
      "javascript.jsx",
      "typescript",
      "typescriptreact",
      "typescript.tsx",
      "html",
      "json",
      "less",
      "scss",
      "css",
      "markdown",
      "lua",
      "nim",
    }
  }
}

------------------------------------------------------------
-- nimlsp setup
------------------------------------------------------------
nvim_lsp.nimls.setup {
  filetypes = { "nim" },
  cmd = { '/Users/mogita/.nimble/bin/nimlsp' },
  on_attach = on_attach
}

------------------------------------------------------------
-- on_attach definition
------------------------------------------------------------
local on_attach = function(client, bufnr)
  local function buf_set_keymap(...) vim.api.nvim_buf_set_keymap(bufnr, ...) end
  local function buf_set_option(...) vim.api.nvim_buf_set_option(bufnr, ...) end

  --Enable completion triggered by <c-x><c-o>
  buf_set_option('omnifunc', 'v:lua.vim.lsp.omnifunc')

  -- Mappings
  local opts = { noremap = true, silent = true }

  buf_set_keymap('n', 'gd', '<Cmd>lua vim.lsp.buf.definition()<CR>', opts)

  if client.name == 'tsserver' then
    client.server_capabilities.documentFormattingProvider = false
  end

  if client.server_capabilities.documentFormattingProvider then
    vim.api.nvim_command [[augroup Format]]
    vim.api.nvim_command [[autocmd! * <buffer>]]
    vim.api.nvim_command [[autocmd BufWritePre <buffer> lua vim.lsp.buf.formatting_seq_sync()]]
    vim.api.nvim_command [[augroup END]]
  end

  if client.name == 'gopls' then
    vim.api.nvim_command [[autocmd BufWritePre <buffer> :silent! lua org_imports(1000)]]
  end

  --protocol.SymbolKind = { }
  protocol.CompletionItemKind = {
    '', -- Text
    '', -- Method
    '', -- Function
    -- ... redacted for simplicity
  }

  -- highlight symbol under the cursor
  if client.server_capabilities.documentHighlightProvider then
    vim.cmd [[
      hi! LspReferenceRead cterm=bold ctermbg=35 guibg=#2c465c
      hi! LspReferenceText cterm=bold ctermbg=35 guibg=#2c465c
      hi! LspReferenceWrite cterm=bold ctermbg=35 guibg=#2c465c
    ]]
    vim.api.nvim_create_augroup('lsp_document_highlight', {})
    vim.api.nvim_create_autocmd({ 'CursorHold', 'CursorHoldI' }, {
      group = 'lsp_document_highlight',
      buffer = 0,
      callback = vim.lsp.buf.document_highlight,
    })
    vim.api.nvim_create_autocmd('CursorMoved', {
      group = 'lsp_document_highlight',
      buffer = 0,
      callback = vim.lsp.buf.clear_references,
    })
  end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant