coc.nvim
coc.nvim copied to clipboard
Feature Request: Dynamic value for `diagnostic.virtualTextWinCol`
The current diagnostic.virtualTextWinCol
option lets you select a fixed location for the insertion of virtual text diagnostics. However, it would be nice to be able to more wisely use the space available within the buffer.
Using Xcode for a few examples:
![image](https://user-images.githubusercontent.com/12656790/209450252-aca94c76-faff-486d-b73f-4fb700d1f3f6.png)
![image](https://user-images.githubusercontent.com/12656790/209450241-3ea63f4c-0c7c-41f6-b0eb-bfb22aac5a59.png)
![image](https://user-images.githubusercontent.com/12656790/209450237-74d8c6c2-52f9-47c9-8141-c8c041853223.png)
![image](https://user-images.githubusercontent.com/12656790/209450409-53d3ca38-7331-44cf-8399-2f4acc5ab485.png)
Some hypothetical logic here (making up the APIs since I don't remember them)
let diagnosticMessage = getDiagnostic(); // "Use of undeclared identifier 'a'"
let diagnosticMessageLength = diagnosticMessage.length(); // 32
let currentWindowWidth = window.getWidth(); // e.g. 90
let columnIndexOfLastCharacter = window.getLineAtColumn(getCurrentColumnIndex()); // e.g. 5
let freeSpaceOnTheRight = currentWindowWidth - columnIndexOfLastCharacter; // e.g. 85
if (diagnosticMessageLength < freeSpaceOnTheRight)
// lots of extra room: right align it. e.g. images 1 and 2
diagnostic.VirtualTextWinCol = currentWindowWidth - diagnosticMessageLength;
else if (columnIndexOfLastChar < currentWindowWidth)
// not enough room: truncate the message and put it as close to the text as possible. e.g. image 3
diagnostic.VirtualTextWinCol = columnIndexOfLastChar + 1;
else
// Don't show virtual text since there's no room. e.g. image 4