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

<leader>f applied to selection formats whole file instead of the selection #120

Open
osenvosem opened this issue Mar 31, 2021 · 11 comments
Open
Labels
wontfix This will not be worked on

Comments

@osenvosem
Copy link

Result from CocInfo
## versions

vim version: NVIM v0.5.0-dev+acd643bd4
node version: v15.10.0
coc.nvim version: 0.0.80-bd41b16bd9
coc.nvim directory: /Users/srg/.config/nvim/plugged/coc.nvim
term: xterm-kitty
platform: darwin

## Log of coc.nvim

2021-03-31T12:57:15.857 INFO (pid:82753) [services] - registered service "languageserver.rescript"
2021-03-31T12:57:16.207 INFO (pid:82753) [plugin] - coc.nvim 0.0.80-bd41b16bd9 initialized with node: v15.10.0 after 450ms
2021-03-31T12:57:16.214 INFO (pid:82753) [language-client-index] - cSpell started with 82755
2021-03-31T12:57:16.226 INFO (pid:82753) [watchman] - watchman watching project: /Users/srg/Documents/Projects/pipeline-frontend
2021-03-31T12:57:17.385 INFO (pid:82753) [attach] - receive notification: highlight []
2021-03-31T12:57:19.082 INFO (pid:82753) [attach] - receive notification: doAutocmd [ 1 ]
2021-03-31T12:57:19.182 INFO (pid:82753) [language-client-index] - eslint started with 82759
2021-03-31T12:57:19.193 INFO (pid:82753) [watchman] - watchman watching project: /Users/srg/Documents/Projects/pipeline-frontend/js
2021-03-31T12:57:19.258 INFO (pid:82753) [services] - registered service "tsserver"
2021-03-31T12:57:19.994 INFO (pid:82753) [attach] - receive notification: highlight []
2021-03-31T12:57:24.206 INFO (pid:82753) [attach] - receive notification: highlight []
2021-03-31T12:57:24.952 INFO (pid:82753) [attach] - receive notification: formatSelected [ 'V' ]
2021-03-31T12:57:26.212 INFO (pid:82753) [attach] - receive notification: highlight []
2021-03-31T12:57:30.182 INFO (pid:82753) [attach] - receive notification: highlight []
2021-03-31T12:57:43.672 INFO (pid:82753) [attach] - receive notification: codeAction [ 'V' ]
2021-03-31T12:57:46.872 INFO (pid:82753) [attach] - receive notification: highlight []
2021-03-31T12:57:48.331 INFO (pid:82753) [attach] - receive notification: highlight []
2021-03-31T12:57:49.610 INFO (pid:82753) [attach] - receive notification: openList [ 'diagnostics' ]
2021-03-31T12:57:49.648 INFO (pid:82753) [attach] - receive notification: doAutocmd [ 1 ]
2021-03-31T12:57:54.017 INFO (pid:82753) [attach] - receive notification: doAutocmd [ 1 ]
2021-03-31T12:57:54.527 INFO (pid:82753) [attach] - receive notification: highlight []
2021-03-31T12:57:55.313 INFO (pid:82753) [attach] - receive notification: highlight []
2021-03-31T12:57:56.053 INFO (pid:82753) [attach] - receive notification: codeAction [ '' ]
2021-03-31T12:57:58.397 INFO (pid:82753) [attach] - receive notification: highlight []
2021-03-31T12:57:59.453 INFO (pid:82753) [attach] - receive notification: highlight []
2021-03-31T12:58:02.430 INFO (pid:82753) [attach] - receive notification: highlight []
2021-03-31T12:58:02.643 INFO (pid:82753) [attach] - receive notification: doAutocmd [ 1 ]
2021-03-31T12:58:02.967 INFO (pid:82753) [attach] - receive notification: highlight []
2021-03-31T12:58:06.432 INFO (pid:82753) [attach] - receive notification: highlight []
2021-03-31T12:58:08.121 INFO (pid:82753) [attach] - receive notification: formatSelected [ 'V' ]
2021-03-31T12:58:08.603 INFO (pid:82753) [attach] - receive notification: highlight []
2021-03-31T12:58:09.436 INFO (pid:82753) [attach] - receive notification: highlight []
2021-03-31T12:59:31.030 INFO (pid:82753) [attach] - receive notification: highlight []
2021-03-31T12:59:33.765 INFO (pid:82753) [attach] - receive notification: openList [ 'diagnostics' ]
2021-03-31T12:59:33.800 INFO (pid:82753) [attach] - receive notification: doAutocmd [ 1 ]
2021-03-31T12:59:39.891 INFO (pid:82753) [attach] - receive notification: doAutocmd [ 1 ]
2021-03-31T12:59:40.401 INFO (pid:82753) [attach] - receive notification: highlight []
2021-03-31T12:59:43.755 INFO (pid:82753) [attach] - receive notification: highlight []
2021-03-31T12:59:45.566 INFO (pid:82753) [attach] - receive notification: highlight []
2021-03-31T12:59:47.075 INFO (pid:82753) [attach] - receive notification: highlight []
2021-03-31T12:59:52.189 INFO (pid:82753) [attach] - receive request: CocAutocmd [ 'BufWritePre', 2 ]
2021-03-31T12:59:52.194 INFO (pid:82753) [attach] - receive request: doAutocmd [ 2, 2 ]
2021-03-31T12:59:52.605 INFO (pid:82753) [attach] - receive notification: highlight []
2021-03-31T13:00:02.074 INFO (pid:82753) [attach] - receive notification: highlight []
2021-03-31T13:00:04.622 INFO (pid:82753) [attach] - receive notification: highlight []
2021-03-31T13:00:05.549 INFO (pid:82753) [attach] - receive request: CocAutocmd [ 'BufWritePre', 2 ]
2021-03-31T13:00:05.555 INFO (pid:82753) [attach] - receive request: doAutocmd [ 2, 2 ]
2021-03-31T13:00:05.904 INFO (pid:82753) [attach] - receive notification: highlight []
2021-03-31T13:00:14.790 INFO (pid:82753) [attach] - receive notification: highlight []
2021-03-31T13:00:16.026 INFO (pid:82753) [attach] - receive notification: highlight []
2021-03-31T13:00:18.591 INFO (pid:82753) [attach] - receive notification: highlight []
2021-03-31T13:00:19.754 INFO (pid:82753) [attach] - receive notification: highlight []
2021-03-31T13:00:23.280 INFO (pid:82753) [attach] - receive notification: highlight []
2021-03-31T13:00:30.487 INFO (pid:82753) [attach] - receive notification: highlight []
2021-03-31T13:00:31.183 INFO (pid:82753) [attach] - receive notification: highlight []
2021-03-31T13:00:32.093 INFO (pid:82753) [attach] - receive notification: jumpDefinition []
2021-03-31T13:00:32.170 INFO (pid:82753) [attach] - receive notification: doAutocmd [ 1 ]
2021-03-31T13:00:32.680 INFO (pid:82753) [attach] - receive notification: highlight []
2021-03-31T13:00:35.119 INFO (pid:82753) [attach] - receive notification: highlight []
2021-03-31T13:00:36.078 INFO (pid:82753) [attach] - receive notification: highlight []
2021-03-31T13:00:39.386 INFO (pid:82753) [attach] - receive notification: doAutocmd [ 1 ]
2021-03-31T13:00:39.896 INFO (pid:82753) [attach] - receive notification: highlight []
2021-03-31T13:00:47.872 INFO (pid:82753) [completion-complete] - Results from: around,buffer,tsserver-javascript
2021-03-31T13:00:53.558 INFO (pid:82753) [attach] - receive notification: highlight []
2021-03-31T13:00:54.540 INFO (pid:82753) [attach] - receive notification: highlight []
2021-03-31T13:00:56.341 INFO (pid:82753) [attach] - receive notification: highlight []
2021-03-31T13:03:14.881 INFO (pid:82753) [attach] - receive notification: highlight []
2021-03-31T13:03:16.662 INFO (pid:82753) [attach] - receive notification: highlight []
2021-03-31T13:03:20.213 INFO (pid:82753) [attach] - receive notification: highlight []
2021-03-31T13:03:22.352 INFO (pid:82753) [attach] - receive notification: highlight []
2021-03-31T13:03:25.740 INFO (pid:82753) [attach] - receive notification: startCompletion [
  {
    word: '',
    bufnr: 2,
    col: 2,
    synname: '',
    filepath: '/Users/srg/Documents/Projects/pipeline-frontend/js/frontend/release.js',
    blacklist: [],
    line: '  ',
    filetype: 'javascript',
    linenr: 20,
    input: '',
    colnr: 3,
    changedtick: 35
  }
]
2021-03-31T13:03:25.788 INFO (pid:82753) [completion-complete] - Results from: tsserver-javascript
2021-03-31T13:03:49.763 INFO (pid:82753) [attach] - receive notification: highlight []
2021-03-31T13:03:50.929 INFO (pid:82753) [attach] - receive notification: highlight []
2021-03-31T13:04:00.195 INFO (pid:82753) [attach] - receive notification: highlight []
2021-03-31T13:04:05.076 INFO (pid:82753) [attach] - receive notification: startCompletion [
  {
    word: '',
    bufnr: 2,
    col: 8,
    synname: 'jsDestructuringBlock',
    filepath: '/Users/srg/Documents/Projects/pipeline-frontend/js/frontend/release.js',
    blacklist: [],
    line: "const {  } = require('../integrations/jenkins');",
    filetype: 'javascript',
    linenr: 27,
    input: '',
    colnr: 9,
    changedtick: 248
  }
]
2021-03-31T13:04:05.111 INFO (pid:82753) [completion-complete] - Results from: tsserver-javascript
2021-03-31T13:04:32.632 INFO (pid:82753) [attach] - receive notification: highlight []
2021-03-31T13:04:33.596 INFO (pid:82753) [attach] - receive notification: highlight []
2021-03-31T13:08:25.578 INFO (pid:82753) [attach] - receive notification: highlight []
2021-03-31T13:08:32.835 INFO (pid:82753) [attach] - receive notification: formatSelected [ 'V' ]
2021-03-31T13:08:34.521 INFO (pid:82753) [attach] - receive notification: highlight []
2021-03-31T13:08:37.713 INFO (pid:82753) [attach] - receive notification: highlight []
2021-03-31T13:08:52.875 INFO (pid:82753) [attach] - receive notification: openList [ 'extensions' ]
2021-03-31T13:08:52.964 INFO (pid:82753) [attach] - receive notification: doAutocmd [ 1 ]
2021-03-31T13:09:11.348 WARN (pid:82753) [events] - Handler of InputChar blocked more than 2s: Error
    at Events.on (/Users/srg/.config/nvim/plugged/coc.nvim/build/index.js:36969:19)
    at ListManager.init (/Users/srg/.config/nvim/plugged/coc.nvim/build/index.js:57134:20)
    at Plugin.init (/Users/srg/.config/nvim/plugged/coc.nvim/build/index.js:65490:24)
    at processTicksAndRejections (node:internal/process/task_queues:94:5)
    at async /Users/srg/.config/nvim/plugged/coc.nvim/build/index.js:36142:9
2021-03-31T13:09:20.187 INFO (pid:82753) [attach] - receive notification: doAutocmd [ 1 ]
2021-03-31T13:09:20.697 INFO (pid:82753) [attach] - receive notification: highlight []
2021-03-31T13:09:21.636 INFO (pid:82753) [attach] - receive notification: highlight []
2021-03-31T13:09:22.783 INFO (pid:82753) [attach] - receive notification: formatSelected [ 'char' ]
2021-03-31T13:09:23.263 INFO (pid:82753) [attach] - receive notification: highlight []
2021-03-31T13:09:24.857 INFO (pid:82753) [attach] - receive notification: highlight []
2021-03-31T13:09:26.237 INFO (pid:82753) [attach] - receive notification: formatSelected [ 'V' ]
2021-03-31T13:09:27.964 INFO (pid:82753) [attach] - receive notification: highlight []
2021-03-31T13:09:29.837 INFO (pid:82753) [attach] - receive notification: formatSelected [ 'V' ]
2021-03-31T13:09:30.268 INFO (pid:82753) [attach] - receive notification: highlight []
2021-03-31T13:09:33.798 INFO (pid:82753) [attach] - receive notification: highlight []
2021-03-31T13:09:35.000 INFO (pid:82753) [attach] - receive notification: highlight []
2021-03-31T13:09:36.014 INFO (pid:82753) [attach] - receive notification: formatSelected [ 'V' ]
2021-03-31T13:09:36.472 INFO (pid:82753) [attach] - receive notification: highlight []
2021-03-31T13:09:40.900 INFO (pid:82753) [attach] - receive notification: highlight []
2021-03-31T13:09:42.365 INFO (pid:82753) [attach] - receive request: CocAutocmd [ 'BufWritePre', 2 ]
2021-03-31T13:09:42.367 INFO (pid:82753) [attach] - receive request: doAutocmd [ 2, 2 ]
2021-03-31T13:09:42.845 INFO (pid:82753) [attach] - receive notification: highlight []
2021-03-31T13:09:43.967 INFO (pid:82753) [attach] - receive notification: highlight []
2021-03-31T13:09:45.509 INFO (pid:82753) [attach] - receive notification: formatSelected [ 'V' ]
2021-03-31T13:09:46.027 INFO (pid:82753) [attach] - receive notification: highlight []
2021-03-31T13:09:47.573 INFO (pid:82753) [attach] - receive notification: highlight []
2021-03-31T13:10:01.101 INFO (pid:82753) [attach] - receive notification: formatSelected [ 'V' ]
2021-03-31T13:10:02.818 INFO (pid:82753) [attach] - receive notification: highlight []
2021-03-31T13:10:03.167 INFO (pid:82753) [attach] - receive notification: highlight []
2021-03-31T13:10:04.300 INFO (pid:82753) [attach] - receive notification: highlight []
2021-03-31T13:10:18.275 INFO (pid:82753) [attach] - receive notification: highlight []
2021-03-31T13:10:20.310 INFO (pid:82753) [attach] - receive notification: openList [ 'commands' ]
2021-03-31T13:10:20.344 INFO (pid:82753) [attach] - receive notification: doAutocmd [ 1 ]
2021-03-31T13:10:34.004 INFO (pid:82753) [attach] - receive notification: doAutocmd [ 1 ]
2021-03-31T13:10:34.513 INFO (pid:82753) [attach] - receive notification: highlight []
2021-03-31T13:10:41.387 INFO (pid:82753) [attach] - receive notification: highlight []
2021-03-31T13:11:50.394 INFO (pid:82753) [attach] - receive notification: highlight []
2021-03-31T13:11:58.501 INFO (pid:82753) [attach] - receive notification: doAutocmd [ 1 ]
2021-03-31T13:11:59.011 INFO (pid:82753) [attach] - receive notification: highlight []
2021-03-31T13:12:00.352 INFO (pid:82753) [attach] - receive notification: doAutocmd [ 1 ]
2021-03-31T13:12:00.371 INFO (pid:82753) [attach] - receive notification: doAutocmd [ 1 ]
2021-03-31T13:12:00.626 INFO (pid:82753) [attach] - receive notification: doAutocmd [ 1 ]
2021-03-31T13:12:00.632 INFO (pid:82753) [attach] - receive notification: doAutocmd [ 1 ]
2021-03-31T13:12:00.670 INFO (pid:82753) [attach] - receive notification: doAutocmd [ 1 ]
2021-03-31T13:12:00.878 INFO (pid:82753) [attach] - receive notification: doAutocmd [ 1 ]
2021-03-31T13:12:00.885 INFO (pid:82753) [attach] - receive notification: doAutocmd [ 1 ]
2021-03-31T13:12:00.917 INFO (pid:82753) [attach] - receive notification: doAutocmd [ 1 ]
2021-03-31T13:12:01.105 INFO (pid:82753) [attach] - receive notification: doAutocmd [ 1 ]
2021-03-31T13:12:01.114 INFO (pid:82753) [attach] - receive notification: doAutocmd [ 1 ]
2021-03-31T13:12:01.148 INFO (pid:82753) [attach] - receive notification: doAutocmd [ 1 ]
2021-03-31T13:12:01.336 INFO (pid:82753) [attach] - receive notification: doAutocmd [ 1 ]
2021-03-31T13:12:01.345 INFO (pid:82753) [attach] - receive notification: doAutocmd [ 1 ]
2021-03-31T13:12:01.378 INFO (pid:82753) [attach] - receive notification: doAutocmd [ 1 ]
2021-03-31T13:12:01.566 INFO (pid:82753) [attach] - receive notification: doAutocmd [ 1 ]
2021-03-31T13:12:01.573 INFO (pid:82753) [attach] - receive notification: doAutocmd [ 1 ]
2021-03-31T13:12:01.607 INFO (pid:82753) [attach] - receive notification: doAutocmd [ 1 ]
2021-03-31T13:12:01.803 INFO (pid:82753) [attach] - receive notification: doAutocmd [ 1 ]
2021-03-31T13:12:01.812 INFO (pid:82753) [attach] - receive notification: doAutocmd [ 1 ]
2021-03-31T13:12:01.842 INFO (pid:82753) [attach] - receive notification: doAutocmd [ 1 ]
2021-03-31T13:12:02.034 INFO (pid:82753) [attach] - receive notification: doAutocmd [ 1 ]
2021-03-31T13:12:02.040 INFO (pid:82753) [attach] - receive notification: doAutocmd [ 1 ]
2021-03-31T13:12:02.548 INFO (pid:82753) [attach] - receive notification: highlight []
2021-03-31T13:12:05.302 INFO (pid:82753) [attach] - receive notification: highlight []
2021-03-31T13:12:05.950 INFO (pid:82753) [attach] - receive notification: highlight []
2021-03-31T13:12:07.953 INFO (pid:82753) [attach] - receive notification: highlight []
2021-03-31T13:12:12.687 INFO (pid:82753) [attach] - receive notification: highlight []
2021-03-31T13:12:15.238 INFO (pid:82753) [attach] - receive notification: highlight []
2021-03-31T13:12:17.367 INFO (pid:82753) [attach] - receive notification: highlight []
2021-03-31T13:12:23.848 INFO (pid:82753) [attach] - receive notification: highlight []
2021-03-31T13:12:26.933 INFO (pid:82753) [attach] - receive notification: highlight []
2021-03-31T13:13:59.931 INFO (pid:82753) [attach] - receive notification: doAutocmd [ 1 ]
2021-03-31T13:14:00.442 INFO (pid:82753) [attach] - receive notification: highlight []
2021-03-31T13:14:05.229 INFO (pid:82753) [attach] - receive notification: showInfo []

Describe the bug

The whole buffer is formatted instead of just selected lines.

Reproduce the bug

We will close your issue when you don't provide minimal vimrc and we can't
reproduce it

This is the result of trying to launch vim -u mini.vim:

Screenshot 2021-03-31 at 13 35 44

Screenshots (optional)

Screen.Recording.2021-03-31.at.13.38.26.mov
@fannheyward
Copy link
Member

Can't reproduce, which language server/extension do you use when do formatting?

I can't reproduce your mini.vim error, looks like your mini.vim has some error.

@osenvosem
Copy link
Author

TS/JS (tsserver) with prettier or with prettier plugin switched off.

@chemzqm
Copy link
Member

chemzqm commented Apr 1, 2021

@chemzqm chemzqm closed this as completed Apr 1, 2021
@fannheyward
Copy link
Member

Tested with coc+tsserver, still can't reproduce.

@backdround
Copy link

I have the same behavior, when use coc-prettier.

vim version: NVIM v0.5.0-dev+1197-ga17782042
node version: v15.13.0
coc.nvim version: 0.0.80-2dbe0ae611
coc-prettier: 1.1.23

@osenvosem
Copy link
Author

osenvosem commented Apr 1, 2021

Yes, it seems like coc-prettier is the culprit.

[Trace - 4/1/2021, 10:42:09 AM:] Formatted file: file:///Users/srg/Documents/Projects/myproject/src/js/post/store.ts


[Trace - 4/1/2021, 10:42:09 AM:] Prettier format edits: [
  {
    "range": {
      "start": {
        "character": 0,
        "line": 0
      },
      "end": {
        "character": 0,
        "line": 478
      }
    }
]

It formats the whole file. @chemzqm @fannheyward

@chemzqm
Copy link
Member

chemzqm commented Apr 1, 2021

Prettier doesn't provide range format.

@osenvosem
Copy link
Author

Prettier doesn't provide range format.

https://github.com/neoclide/coc-prettier#remap-keys-for-range-format-in-your-initvim-or-vimrc

Prettier range format only support languageId including: javascript, javascriptreact, typescript, typescriptreact, json and graphql.

@yaegassy
Copy link

yaegassy commented Apr 1, 2021

@osenvosem Do you have the <Plug>(coc-format-selected) mappings set correctly?

If you try running it as a command instead of mapping, do you get the same symptoms?

:'<,'>call CocAction('formatSelected', visualmode())

@chemzqm
Copy link
Member

chemzqm commented Apr 1, 2021

I can reproduce, old version of prettier doesn't work with range https://prettier.io/docs/en/options.html#range

@chemzqm chemzqm reopened this Apr 1, 2021
@chemzqm chemzqm transferred this issue from neoclide/coc.nvim Apr 1, 2021
@chemzqm chemzqm added the wontfix This will not be worked on label Apr 1, 2021
@osenvosem
Copy link
Author

@osenvosem Do you have the <Plug>(coc-format-selected) mappings set correctly?

If you try running it as a command instead of mapping, do you get the same symptoms?

:'<,'>call CocAction('formatSelected', visualmode())

Key bindings are default ones from the README.md, didn't change anything. The command you offered has the same behavior.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
wontfix This will not be worked on
Projects
None yet
Development

No branches or pull requests

5 participants