mattn / efm-langserver

General purpose Language Server
MIT License
1.37k stars 61 forks source link

On Save, EFM is Undoing my Change #156

Closed jrock2004 closed 3 years ago

jrock2004 commented 3 years ago

So I am trying to set up EFM to do my typescript formatting and having a little issue that I just am not sure what is causing the issue.

const foo = "happy"

const myFunc = (ev: any) => {
  const bar = "day"
          console.log(ev);
}

So I got and change the work day to night and hit save, and this is what happens

const foo = "happy";

const myFunc = (ev: any) => {
  const bar = "day"
  console.log(ev);
}

For some reason is undoing my code change and putting it back to day

Here is my config

local on_attach_common = function(client)
  print("LSP started.");

  if client.resolved_capabilities.document_formatting then
    vim.cmd [[augroup Format]]
    vim.cmd [[autocmd! * <buffer>]]
    vim.cmd [[autocmd BufWritePre <buffer> lua vim.lsp.buf.formatting_seq_sync()]]
    vim.cmd [[augroup END]]
  end

  if client.resolved_capabilities.document_highlight then
    vim.api.nvim_exec(
      [[
      hi LspReferenceRead cterm=bold ctermbg=red guibg=#464646
      hi LspReferenceText cterm=bold ctermbg=red guibg=#464646
      hi LspReferenceWrite cterm=bold ctermbg=red guibg=#464646
      augroup lsp_document_highlight
      autocmd! * <buffer>
      autocmd CursorHold <buffer> lua vim.lsp.buf.document_highlight()
      autocmd CursorMoved <buffer> lua vim.lsp.buf.clear_references()
      augroup END
      ]],
      false
    )
  end
end

local luafmt = Lvim.formatters.lua()
local prettier = Lvim.formatters.prettier()
local eslint = Lvim.formatters.eslint()

lsp.efm.setup {
  -- cmd = {"efm-langserver", "-logfile", "/tmp/efm.log", "-loglevel", "1" },
  on_attach = function(client)
    client.resolved_capabilities.document_formatting = true
    on_attach_common(client)
  end,
  init_options = {documentFormatting = true},
  root_dir = function()
    if not Lvim.eslintChecker() then
      return nil
    end
    return vim.fn.getcwd()
  end,
  settings = {
    -- rootMarkers = {".git/"},
    languages = {
      lua = {luafmt},
      typescript = {prettier},
      javascript = {prettier},
      typescriptreact = {prettier},
      javascriptreact = {prettier},
      ["javascript.jsx"] = {prettier},
      ["typescript.tsx"] = {prettier},
      yaml = {prettier},
      -- json = {prettier},
      html = {prettier},
      -- less = {prettier},
      -- scss = {prettier},
      -- css = {prettier},
      markdown = {prettier}
    }
  },
  filetypes = {
    "javascript",
    "javascriptreact",
    "javascript.jsx",
    "typescript",
    "typescript.tsx",
    "typescriptreact",
    "lua",
    -- "less",
    -- "scss",
    -- "css",
  }
}

I noticed this in my LSP log, so maybe LSP efm is conflicting with something?

[ START ] 2021-08-01T23:48:46-0400 ] LSP logging initiated
[ ERROR ] 2021-08-01T23:48:48-0400 ] ...llar/neovim/0.5.0/share/nvim/runtime/lua/vim/lsp/rpc.lua:462 ]  "rpc"   "/Users/jcostanzo/.local/share/nvim/lspinstall/efm/./efm-langserver"    "stderr"    "2021/08/01 23:48:48 efm-langserver: no configuration file\n2021/08/01 23:48:48 efm-langserver: reading on stdin, writing on stdout\n"
[ ERROR ] 2021-08-01T23:48:56-0400 ] ...llar/neovim/0.5.0/share/nvim/runtime/lua/vim/lsp/rpc.lua:462 ]  "rpc"   "/Users/jcostanzo/.local/share/nvim/lspinstall/efm/./efm-langserver"    "stderr"    "2021/08/01 23:48:56 format succeeded\n"

Thanks for any thoughts on what could be going wrong here

GustavoKatel commented 3 years ago

I was having the same issue and this solved for me https://github.com/mattn/efm-langserver/issues/121