Skip to content

fix: correct Show in Source navigation (#line offset + unquoted filenames)#44

Merged
theodevelop merged 2 commits into
devfrom
fix/show-in-source
Apr 13, 2026
Merged

fix: correct Show in Source navigation (#line offset + unquoted filenames)#44
theodevelop merged 2 commits into
devfrom
fix/show-in-source

Conversation

@theodevelop

@theodevelop theodevelop commented Apr 13, 2026

Copy link
Copy Markdown
Owner

Type of change

  • Bug fix
  • New feature
  • Refactor / internal improvement
  • Docs / config only

What does this PR do?

  • Fixed showInSource jumping to the wrong line when the cursor is below a #line directive — now applies the correct offset sourceLine + (cursorLine − directiveLine)
  • Fixed #line detection not matching unquoted filenames (#line 28 parser.y without quotes)
  • Extracted pure helpers to client/src/lineDirectiveUtils.ts for testability (no VS Code mock needed)

Closes

Closes #29 #27 (comment by @GitMensch)

Changes

  • client/src/lineDirectiveUtils.ts — new module: isGeneratedFile, LineDirective, findNearestLineDirective
  • client/src/lineDirectiveNavigation.ts — imports from utils, applies offset formula
  • tests/test-line-directive.ts — 26 assertions (quoted, unquoted, edge cases)

How to test manually

  • TS_NODE_PROJECT=tsconfig.base.json npx ts-node tests/test-line-directive.ts → 26 passed, 0 failed
  • npm run compile → no errors
  • Manual: cursor N lines below #line M → navigates to line M + N in source
  • Manual: unquoted #line N filename.y → directive detected and navigation works
  • Manual: cursor above all #line directives → warning message shown

Checklist

  • npm run compile passes with no new errors
  • Tests added or updated (npx ts-node ...)
  • Manual test done in VS Code
  • CHANGELOG.md updated
  • No unintended files staged (node_modules, .env, dist...)

@theodevelop theodevelop self-assigned this Apr 13, 2026
@theodevelop theodevelop added the bug Something isn't working label Apr 13, 2026
@theodevelop theodevelop merged commit 22efb87 into dev Apr 13, 2026
1 check passed
@theodevelop theodevelop deleted the fix/show-in-source branch April 20, 2026 20:22
@theodevelop theodevelop mentioned this pull request Apr 20, 2026
14 tasks
}

const targetLine = Math.max(0, directive.sourceLine - 1); // convert to 0-based
const offset = cursorLine - directive.directiveLine; // lines between directive and cursor

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is that correct? I think yes, but the later use of the offset should possibly have another + 1:

Image

goes to

Image

note that #line 6287 "../../cobc/parser.y" says that the next line is line 6287;

cursor line (6290) - directive line (6287) = 3 (+1 --> 4 if considered from the #line itself), but the position is only 3 lines below the #line .

Apart from that the feature works fine.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants