Skip to content

fix: blank lines inside mappings orphan all following entries - #14

Open
isutare412 wants to merge 1 commit into
armsnyder:mainfrom
isutare412:fix/blank-line-parent-stack
Open

isutare412 wants to merge 1 commit into
armsnyder:mainfrom
isutare412:fix/blank-line-parent-stack

Conversation

@isutare412

@isutare412 isutare412 commented Jul 23, 2026

Copy link
Copy Markdown

Symptom

In any OpenAPI spec with blank lines between schema entries (very common in hand-written specs), textDocument/definition and textDocument/references on $ref values silently return nothing for everything below the first blank line inside components. Blank lines between top-level sections are harmless (the next section is at indent 0 anyway), which is why the bundled testdata/petstore.yaml never caught it.

Minimal reproduction — without the fix, a definition request on a $ref to #/components/schemas/Bar returns null because Document.Locate cannot resolve it:

openapi: 3.0.0
components:
  schemas:
    Foo:
      type: object

    Bar:
      type: object

Cause

In Parse (internal/analysis/yaml/yaml.go), a blank line parses with indent 0 (len("") == 0). The parent-stack pop loop then treats it as an indent-0 mapping key: it pops the entire stack and registers the blank line as a new root under the empty key. Every line after the blank line is re-parented under that phantom root, so Locate can no longer resolve it.

Fix

Skip whitespace-only lines in the structure pass. They are still appended to document.Lines first, because Lines is indexed by LSP line number in internal/analysis/handler.go (document.Lines[params.Position.Line]).

Verification

  • New test TestRefs_BlankLineBetweenSchemas fails before the fix (could not locate #/components/schemas/Bar) and passes after.
  • go test ./... passes across the whole repo.
  • Validated against real hand-written OpenAPI specs via a raw LSP stdio client: $ref resolution went from 0/103, 0/95, 0/103 to 103/103, 95/95, 103/103. A machine-generated spec without blank lines was 58/58 both before and after (no regression).

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@isutare412

Copy link
Copy Markdown
Author

@armsnyder Could you please check this?

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