Giter Site home page Giter Site logo

Comments (8)

aiotter avatar aiotter commented on July 22, 2024

#181 may or may not be related to this.

from efm-langserver.

aiotter avatar aiotter commented on July 22, 2024

Oh wait, it seems the problem only occurs when the input file does not end with a newline character.
(So the file is not a text file in the sense of POSIX)

$ cat -e main.ts
import App from './App.svelte';$
$
const app = new App({$
        target: document.body,$
        props: {$
                name: 'world'$
        }$
});$
$
export default app;

When the input file has a newline character at the EOF when opening the file on neovim, it works without problem.
When the file lacks the newline character at the EOF when opening the file on neovim, the issue occurs.
Note that when I open the file and save the file immediately, the issue occurs despite the fact that the input file is now with a newline character at the EOF.

from efm-langserver.

mattn avatar mattn commented on July 22, 2024

do you set noeol ?

from efm-langserver.

aiotter avatar aiotter commented on July 22, 2024

It seems it is on by default. I set nothing related to EOL.

from efm-langserver.

mattn avatar mattn commented on July 22, 2024

Hmm, formatting does not modify outputs.

from efm-langserver.

SimonEggert avatar SimonEggert commented on July 22, 2024

I have the same issue. Did anyone find a suitable solution yet?

from efm-langserver.

SimonEggert avatar SimonEggert commented on July 22, 2024

I dug a little deeper today and hope I can provide additional information:

The problem only occurs for me when Prettier needs to change the last line, e.g. with semicolons required in JS:

export const test = () => {}

results in

export const test = () => {};
<-- newline here

This is the corresponding log:

2024/01/23 08:55:40 jsonrpc2: --> notif: textDocument/didChange: {"textDocument":{"version":55,"uri":"file:test.js"},"contentChanges":[{"text":"export const test = () =\u003e {}\n"}]}
2024/01/23 08:55:40 jsonrpc2: <-- notif: textDocument/publishDiagnostics: {"uri":"file:test.js","diagnostics":[],"version":55}

2024/01/23 08:55:45 jsonrpc2: --> request #14: textDocument/formatting: {"textDocument":{"uri":"file:test.js"},"options":{"insertSpaces":true,"tabSize":2}}
2024/01/23 08:55:46 eslint_d --fix-to-stdout --stdin --stdin-filename test.js:
2024/01/23 08:55:46 jsonrpc2: <-- result #14: textDocument/formatting: [{"range":{"start":{"line":0,"character":0},"end":{"line":1,"character":0}},"newText":""},{"range":{"start":{"line":1,"character":0},"end":{"line":1,"character":0}},"newText":"export const test = () =\u003e {};\n"}]
2024/01/23 08:55:46 jsonrpc2: --> notif: textDocument/didChange: {"textDocument":{"version":56,"uri":"file:test.js"},"contentChanges":[{"text":"export const test = () =\u003e {}\nexport const test = () =\u003e {};\n\n"}]}
2024/01/23 08:55:46 jsonrpc2: --> notif: textDocument/didChange: {"textDocument":{"version":57,"uri":"file:test.js"},"contentChanges":[{"text":"export const test = () =\u003e {};\n\n"}]}
2024/01/23 08:55:46 jsonrpc2: --> notif: textDocument/didSave: {"textDocument":{"uri":"file:test.js"}}
2024/01/23 08:55:46 jsonrpc2: <-- notif: textDocument/publishDiagnostics: {"uri":"file:test.js","diagnostics":[],"version":57}
2024/01/23 08:55:46 jsonrpc2: <-- notif: textDocument/publishDiagnostics: {"uri":"file:test.js","diagnostics":[],"version":57}

On the other hand

const x = 0
export const test = () => {};

correctly results in

const x = 0;
export const test = () => {};

log:

2024/01/23 08:58:42 jsonrpc2: --> notif: textDocument/didChange: {"textDocument":{"version":74,"uri":"file:test.js"},"contentChanges":[{"text":"const x = 0\nexport const test = () =\u003e {};\n"}]}
2024/01/23 08:58:42 jsonrpc2: <-- notif: textDocument/publishDiagnostics: {"uri":"file:test.js","diagnostics":[],"version":74}

2024/01/23 08:58:45 jsonrpc2: --> request #16: textDocument/formatting: {"textDocument":{"uri":"file:test.js"},"options":{"insertSpaces":true,"tabSize":2}}
2024/01/23 08:58:45 eslint_d --fix-to-stdout --stdin --stdin-filename test.js:
2024/01/23 08:58:45 jsonrpc2: <-- result #16: textDocument/formatting: [{"range":{"start":{"line":0,"character":0},"end":{"line":1,"character":0}},"newText":""},{"range":{"start":{"line":1,"character":0},"end":{"line":1,"character":0}},"newText":"const x = 0;\n"}]
2024/01/23 08:58:45 jsonrpc2: --> notif: textDocument/didChange: {"textDocument":{"version":75,"uri":"file:test.js"},"contentChanges":[{"text":"const x = 0\nconst x = 0;\nexport const test = () =\u003e {};\n"}]}
2024/01/23 08:58:45 jsonrpc2: --> notif: textDocument/didChange: {"textDocument":{"version":76,"uri":"file:test.js"},"contentChanges":[{"text":"const x = 0;\nexport const test = () =\u003e {};\n"}]}
2024/01/23 08:58:45 jsonrpc2: --> notif: textDocument/didSave: {"textDocument":{"uri":"file:test.js"}}
2024/01/23 08:58:45 jsonrpc2: <-- notif: textDocument/publishDiagnostics: {"uri":"file:test.js","diagnostics":[],"version":76}
2024/01/23 08:58:46 jsonrpc2: <-- notif: textDocument/publishDiagnostics: {"uri":"file:test.js","diagnostics":[],"version":76}

Please let me know if I can help any further in investigating.


This is the relevant part of my nvim config btw in case someone wants to try to reproduce this:

-- init.lua
local formatting_lsps = {
  'efm',
}

local filter = function(client)
  for _, lsp in pairs(formatting_lsps) do
    if client.name == lsp then
      return true
    end
  end
  return false
end

local common_on_attach = function(client, bufnr)
  if client.supports_method("textDocument/formatting") then
    vim.api.nvim_clear_autocmds({ group = augroup, buffer = bufnr })
    vim.api.nvim_create_autocmd("BufWritePre", {
      group = augroup,
      buffer = bufnr,
      callback = function()
        vim.lsp.buf.format({
          bufnr = bufnr,
          filter = filter,
        })
      end,
    })
  end
end

-- efm
local eslint = {
  lintCommand = "eslint_d --format unix --stdin --stdin-filename ${INPUT}",
  lintIgnoreExitCode = true,
  lintStdin = true,
  lintFormats = {"%f:%l:%c: %m"},
  formatCommand = "eslint_d --fix-to-stdout --stdin --stdin-filename ${INPUT}",
  formatStdin = true,
  rootMarkers = {
    '.eslintrc',
    '.eslintrc.cjs',
    '.eslintrc.js',
    '.eslintrc.json',
    '.eslintrc.yaml',
    '.eslintrc.yml',
    'package.json',
  },
}

local prettier = {
  formatCanRange = true,
  formatCommand = "prettierd ${INPUT} ${--range-start=charStart} ${--range-end=charEnd}",
  formatStdin = true,
  rootMarkers = {
    '.prettierrc',
    '.prettierrc.json',
    '.prettierrc.js',
    '.prettierrc.yml',
    '.prettierrc.yaml',
    '.prettierrc.json5',
    '.prettierrc.mjs',
    '.prettierrc.cjs',
    '.prettierrc.toml',
  },
}

nvim_lsp.efm.setup{
  cmd = { "efm-langserver", "-logfile", "efm.log", "-loglevel", "5" },
  on_attach = common_on_attach,
  init_options = {documentFormatting = true},
  settings = {
    rootMarkers = {".git/"},
    languages = {
      javascript = {
        prettier,
        eslint,
      },
  },
  filetypes = { 
    'javascript',
  }
}

I was running efm version 0.0.44 and have now updated to 0.0.49. I'll let you know if this changes anything.

from efm-langserver.

SimonEggert avatar SimonEggert commented on July 22, 2024

FWIW: This issue is also happening to me when using efm with helix.

This is my config:

# languages.toml

[language-server.efm]
command = "efm-langserver"

[language-server.efm.config]
documentFormatting = true

[language-server.efm.config.languages]
css = [
  { formatCommand ="prettierd --stdin-filepath ${INPUT}", formatStdin = true },
  { lintCommand = "stylelint_d --stdin --stdin-filename ${INPUT} --formatter compact", lintIgnoreExitCode = true, lintStdin = true, lintFormats = [ "%f: line %l, col %c, %tarning - %m", "%f: line %l, col %c, %trror - %m" ], formatCommand = "stylelint_d --fix --stdin-filename ${INPUT}", formatStdin = true, rootMarkers = [ ".stylelintrc", ".stylelintrc.json", "stylelint.config.js", "stylelint.config.cjs", "stylelint.config.mjs", "stylelint.config.ts" ] },
]

[[language]]
name = "css"
scope = "source.css"
language-servers = [ "efm" ]
auto-format = true

from efm-langserver.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.