Skip to content

feat: add Bison/Flex Navigation output channel for Show in Generated#48

Merged
theodevelop merged 3 commits into
devfrom
fix/issue-27
Apr 20, 2026
Merged

feat: add Bison/Flex Navigation output channel for Show in Generated#48
theodevelop merged 3 commits into
devfrom
fix/issue-27

Conversation

@theodevelop
Copy link
Copy Markdown
Owner

Type of change

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

What does this PR do?

Fix bisonFlex.buildDirectory not resolved (client/src/lineDirectiveNavigation.ts)
The setting was used raw, causing ${workspaceFolder}/build, build/cobc and ../build/cobc to all fail silently. A new resolveSettingBuildDir() helper substitutes ${workspaceFolder} and resolves relative paths against the workspace folder before searching.
Add "Bison/Flex Navigation" output channel
Show in Generated File now logs every directory and candidate file searched, plus the resolved buildDirectory value. The panel opens automatically (focus preserved) on each invocation to ease debugging.

Related issue

Closes #27

How to test manually

  1. Open a project with cobc/parser.y and a generated file in build/cobc/parser.c
  2. Set bisonFlex.buildDirectory to "build/cobc", "${workspaceFolder}/build/cobc" or a relative path
  3. Right-click in parser.yShow in Generated File
  4. Check Output → Bison/Flex Navigation for the resolved path and files searched

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 18, 2026
@theodevelop theodevelop added bug Something isn't working enhancement New feature or request labels Apr 18, 2026
Copy link
Copy Markdown
Contributor

@GitMensch GitMensch left a comment

Choose a reason for hiding this comment

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

I'm just a g... user - but maybe some of those thoughts are useful.

Side note: shouldn't there be some automated tests for that as well?


/** Resolve `bisonFlex.buildDirectory`: substitutes ${workspaceFolder} and resolves relative paths. */
function resolveSettingBuildDir(rawDir: string, sourceFilePath: string): string {
const wsFolder = workspace.workspaceFolders?.[0]?.uri.fsPath ?? path.dirname(sourceFilePath);
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.

Not sure, but possibly if there is a code-workspace then this should be used as "root"?
claude says the code above works for all scenarios, but to have it relative to a code workspace one may use vscode.workspace.workspaceFile?.fsPath;

It's "practical example" (untested)

function getWorkspaceInfo() {
  const wsFile = vscode.workspace.workspaceFile;
  const folders = vscode.workspace.workspaceFolders;

  if (!folders || folders.length === 0) {
    // No folder or workspace open at all
    return null;
  }

  if (wsFile) {
    if (wsFile.scheme === 'untitled') {
      // Unsaved multi-root workspace (added folders via "Add Folder to Workspace"
      // but never saved the .code-workspace file)
      console.log('Unsaved workspace, first folder:', folders[0].uri.fsPath);
    } else {
      // Saved .code-workspace file
      console.log('Workspace file:', wsFile.fsPath);
      console.log('First folder:', folders[0].uri.fsPath);
    }
  } else {
    // Single-folder mode — no .code-workspace involved
    console.log('Folder mode, root:', folders[0].uri.fsPath);
  }
}

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.

Drop that... a code-workspace can be stored anywhere = also outside of the workspace, so if that is used as a lookup for relative files then it can only be the last fallback.
Documenting that the first folder is used for that in multi-folder workspaces and using that is the right approach.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

Agreed — added a doc comment to resolveSettingBuildDir explaining that folders[0] is intentionally used as the workspace root for all cases, and why workspaceFile is not suitable (a .code-workspace file can live anywhere outside the workspace folders).

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.

That looks nice, but I've meant the buildDir configuration doc and/or README entry.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

Blimey, I hadn't realised that lol. I've updated the README file.

/** Locate the generated file corresponding to a grammar source file. */
async function findGeneratedFile(sourceFilePath: string): Promise<string | null> {
const ch = getNavChannel();
const config = workspace.getConfiguration('bisonFlex');
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.

Can this have a static var saving the last result along with the file name?
That would prevent the lookup (reading config, testing files and folders) to be done each time.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

Done — added a module-level lastFoundCache keyed on (sourceFilePath, buildDirectory setting). On a cache hit the function returns early, before ch.show(true), so the output panel won't pop on repeated navigations to the same file. Only successful lookups are cached, so compiling between two invocations will still trigger a fresh search.

@theodevelop
Copy link
Copy Markdown
Owner Author

Thanks for the review, @GitMensch!

On the tests side note: findGeneratedFile depends on VS Code APIs (workspace.getConfiguration, workspace.findFiles, fs.existsSync), which can't be exercised with the current ts-node-based test infrastructure. Proper coverage would require setting up a VS Code integration test runner (@vscode/test-electron). I'll open a separate issue to track that.

@theodevelop theodevelop merged commit 20effd8 into dev Apr 20, 2026
1 check passed
@theodevelop theodevelop deleted the fix/issue-27 branch April 20, 2026 20:22
@GitMensch
Copy link
Copy Markdown
Contributor

🚀 docs are fine, debug output is really useful when not found and resolving the build directory works finally as well

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

Labels

bug Something isn't working enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants