coc.nvim icon indicating copy to clipboard operation
coc.nvim copied to clipboard

Feature Request: Dynamic value for `diagnostic.virtualTextWinCol`

Open lanza opened this issue 1 year ago • 1 comments

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 image image image

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

lanza avatar Dec 24 '22 20:12 lanza