Coder Social home page Coder Social logo

Comments (8)

towry avatar towry commented on June 27, 2024

It is this line causing the difference:

this.nvim.resumeNotification(isCurrent, true)

from coc.nvim.

towry avatar towry commented on June 27, 2024

tracked down to line

call nvim_buf_set_lines(a:bufnr, a:start, a:end, 0, a:replacement)

turns out when format without change, the arguments passed to nvim_buf_set_lines is (bufnr, 1, 1, 0, {})

And i test this function on a buffer, it did change the buffer and create empty change.

From :h nvim_buf_set_lines:

To insert lines at a given index, set start and end to the same index.
To delete a range of lines, set replacement to an empty array.

So (bufnr, 1, 1, 0, {}) will do nothing but make an empty change since a:start is same as a:end and replacement is empty.

from coc.nvim.

fannheyward avatar fannheyward commented on June 27, 2024

Thank you for your tracking, but I can't reproduce this with your mini.nivm and formatted demo.lua, with coc-sumneko-lua on nvim nightly. And I couldn't reproduce with other language servers too.

from coc.nvim.

fannheyward avatar fannheyward commented on June 27, 2024

The checking fix in #4995 is OK, but I couldn't result any format without change, coc.nvim couldn't run to this check.

from coc.nvim.

towry avatar towry commented on June 27, 2024

@fannheyward Just tested on different version of coc.

coc release branch coc.nvim version: 0.0.82-2ec31666 2024-04-23 09:10:14 +0800

have issue.

coc tag v0.0.82, v0.0.81 doesn't have issue.

from coc.nvim.

towry avatar towry commented on June 27, 2024

I believe this issue was introduced after v0.0.82.
another issue in format is that I have to use call CocAction('format') | sleep 1m to make it work in BufWritePre, otherwise the buf sometimes will be in dirty state.

But in v0.0.82, it works well without the need of sleep 1m.

You can discard this pr, and i will just stick to version v0.0.82.

from coc.nvim.

fannheyward avatar fannheyward commented on June 27, 2024

I believe this issue was introduced after v0.0.82.

Thank you for your tests with different releases of coc, I don't complain your PR, but how to reproduce this, here's my tests:

  1. mkdir -p test-4994
  2. copy your mini.vim and demo.lua, and empty coc-settings.json. I've removed @statiolake/coc-stylua because sumneko-lua already supports formatting, no need to use stylus any more.
  3. When tested with nvim 0.10.0 nightly, I need to add nvim-treesitter, otherwise, nvim reports highlighting error
augroup vimrc | autocmd! | augroup end

set nocompatible
set number
set laststatus=2

let g:coc_global_extensions = ['coc-sumneko-lua']
" change this to your local coc.nvim location.
set runtimepath^=/Users/fannheyward/.local/share/nvim/plugged/coc.nvim
set runtimepath^=/Users/fannheyward/.local/share/nvim/plugged/nvim-treesitter 
filetype plugin indent on
syntax on
autocmd BufWritePre * call CocAction('format')
command! -nargs=0 Format :call CocActionAsync('format')

set expandtab shiftwidth=4 tabstop=4 softtabstop=4
  1. nvim -u mini.vim demo.lua, sumneko-lua reports unused local foo, the Lua LS is working
  2. :call CocAction('format'), no changes
  3. :Format, no changes
  4. :w to fire autocmd, no changes
  5. Tested with nvim 0.9.5 and 0.10.0 nightly, vim 9.1.0350, same results.

Also I've tested the formatting with tsserver, gopls, rust-analyzer servers, won't change on formatted files.

from coc.nvim.

fannheyward avatar fannheyward commented on June 27, 2024

You can use coc.preferences.formatOnSave instead of BufWritePre.

from coc.nvim.

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.