Comments (10)
What's the output :verbose imap <Esc>
? Can't reproduce, maybe caused by other vim plugin.
from coc-clangd.
I checked and there is no mapping. The problem, as I wrote on the OP, only happens on files that make coc-clangd kick in, except for .cpp ones. It does not happen on other file types. So, I am pretty sure it is a coc-clangd bug.
from coc-clangd.
I tried every possible combination of settings and I managed to stop this behavior by removing the first line of my coc-settings.json:
"coc.preferences.formatOnInsertLeave": true
From the coc.nvim documentation, this setting does the following:
"Trigger format on type when insert leave by send \n to the server."
Maybe this has to do with clang specifically?
from coc-clangd.
Reproduced.
from coc-clangd.
Minimal:
coc-settings.json (I needed all of these)
"coc.preferences.formatOnInsertLeave": true,
"coc.preferences.formatOnType": true,
"coc.preferences.formatOnTypeFiletypes": ["cpp"],
Create file containing int;
, open it.
Type ox<esc>
The new line containing x will be erased
Relevant messages:
textDocument/didChange
, insert "x" at line 1 char 0textDocument/onTypeFormatting
, character is "\n"at line 1 char 1 (after 'x')- formatting response: delete from line 1 char 0 to line 1 char 1
Where's the bug: unclear.
onTypeFormatting
is underspecified, clangd expects the client to do what vscode does: edit the document first (including any client-side autoformatting) and then send the onTypeFormatting to the server.
Here, coc is sending a character of "\n" but not editing the document to include one, which doesn't seem to be a well-defined use of the protocol. In fact, formatOnType really does claim it needs to be triggered by a character that was typed, so binding exit-insert-mode to it is always going to be a stretch.
Clangd assumes that the previous "\n" is the one that was inserted, and anything between it and the point is automatic indentation. It formats the previous line.
We could hack around this by trying to detect the coc behavior on the server side, or make coc send something a bit less ambiguous, and teach clangd to do the right thing. What if we make "ch" the empty string?
from coc-clangd.
@sam-mccall can you test the master branch? Just a quick fix to hack the ch to empty.
from coc-clangd.
Here is an issue about onTypeFormatting: neoclide/coc.nvim#1363 (comment)
from coc-clangd.
@fannheyward Better with that patch indeed, it doesn't destroy text :-)
And it does some formatting, not sure if it's ever going to be great as we don't know how well-formed the code is after exiting insert mode. Depends on editing flow I guess.
That will stop "regular" format-on-type from working though: if you press enter while in insert mode it'd be nice if format-on-type activated (though I can't get that to work in coc today...)
from coc-clangd.
Yes, this will stop format-on-type feature. I've revert this patch from master, and create a PR to trace it. #37 (I should do in this way from the beginning...)
from coc-clangd.
Yes, this will stop format-on-type feature
It actually doesn't stop format-on-type from working, clangd will reformat immediatly around the cursor if ch is sent as ''.
It's specifically ch='\n' that causes problems, because it tries to do line continuations and reindenting and stuff.
from coc-clangd.
Related Issues (20)
- stdint.h Library error HOT 1
- Question: navigate to conflicting item/item causing error? HOT 4
- clangd don't start on windows HOT 1
- Unable to locate C/C++ header files (stdio.h, etc.) HOT 1
- coc-clangd still use c++03 to diagnose HOT 1
- some error flag but the code can running HOT 1
- How do I remove the automatically added parameter label in parentheses? HOT 1
- An issue of including libraries HOT 9
- Duplicate references HOT 2
- Command CocCommand clangd.install fails with error 'Failed to install clangd language server' HOT 5
- 这个插件如何在补全头文件比如#include<iostream>时,光标在>的右边,否则每次都多跳过这个符号一次 HOT 1
- [coc.nvim] Connection to server got closed. Server will not be restarted. HOT 4
- 'iostream' file not found (clang pp_file_not_found) HOT 1
- Connection to server got closed HOT 1
- coc-clangd没有输入头文件的情况下也能补全 HOT 4
- Header file not found, even though autocompletion works and include path is added correctly HOT 5
- MinGW issue HOT 1
- MinGW issue
- It can support like [c-mantic] feature? HOT 1
- Env include path not working in header files HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from coc-clangd.