Skip to content

Fix diagnostics of unloaded buffers highlighting - #854

Open
jclsn wants to merge 1 commit into
yegappan:mainfrom
jclsn:fix/highlight-bug
Open

jclsn wants to merge 1 commit into
yegappan:mainfrom
jclsn:fix/highlight-bug

Conversation

@jclsn

@jclsn jclsn commented Oct 17, 2026 •

Copy link
Copy Markdown
Contributor

📌 Summary

When diagnostics arrive for an unloaded buffer, its line count is 1, so the start line of every diagnostic was clamped to the first line while the end line was kept. Once the buffer was loaded, the inline highlight spanned from line 1 to the end of the diagnostic. Load the buffer before reading its line count.


🔍 Related Issues

None


🧪 What This PR Improves

Fixes a bug that sporadically happened for me in clangd.


🛠️ Changes Made

Loading the buffer before reading its line count. There was already a Todo there.


🧪 Testing

Repro:

repro.c

#include "repro.h"

int func1() { return 0; }
int func2() { return 0; }
int func3() { return 0; }
int func4() { return 0; }
int func5() { return 0; }

int main(void)
{
    f();
    return 0;
}

repro.h

#ifndef REPRO_H
#define REPRO_H

int f(void);

#endif

Steps:

  1. Execute vim repro.c and wait for clangd to load
  2. :e repro.h and remove the semicolon at the end of the function declaration to make clangd show and error. Save with :w.
  3. :b repro.c
  4. The whole file should be highlighted as error.
image

📦 Breaking Changes

Does this PR introduce any breaking changes?

  • Yes
  • No

📚 Documentation

Does this PR require documentation updates?

  • Yes
  • No

If yes, describe what needs updating.


✔️ Checklist

  • I have tested this with a minimal Vim9script configuration.
  • I have run the plugin against the relevant LSP server(s).
  • I have updated documentation if needed.
  • I have followed the project’s coding style and conventions.
  • I have added tests or examples where appropriate.

When diagnostics arrive for an unloaded buffer, its line count is 1, so
the start line of every diagnostic was clamped to the first line while
the end line was kept. Once the buffer was loaded, the inline highlight
spanned from line 1 to the end of the diagnostic. Load the buffer before
reading its line count.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant