feat: add Bison/Flex Navigation output channel for Show in Generated#48
Conversation
GitMensch
left a comment
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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);
}
}There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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).
There was a problem hiding this comment.
That looks nice, but I've meant the buildDir configuration doc and/or README entry.
There was a problem hiding this comment.
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'); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
|
Thanks for the review, @GitMensch! On the tests side note: |
|
🚀 docs are fine, debug output is really useful when not found and resolving the build directory works finally as well |
Type of change
What does this PR do?
Fix
bisonFlex.buildDirectorynot resolved (client/src/lineDirectiveNavigation.ts)The setting was used raw, causing
${workspaceFolder}/build, build/cobcand../build/cobcto all fail silently. A newresolveSettingBuildDir()helper substitutes${workspaceFolder}and resolves relative paths against the workspace folder before searching.Add "Bison/Flex Navigation" output channel
Show in Generated Filenow logs every directory and candidate file searched, plus the resolvedbuildDirectoryvalue. The panel opens automatically (focus preserved) on each invocation to ease debugging.Related issue
Closes #27
How to test manually
cobc/parser.yand a generated file inbuild/cobc/parser.cbisonFlex.buildDirectoryto"build/cobc","${workspaceFolder}/build/cobc"or a relative pathparser.y→ Show in Generated FileChecklist
npm run compilepasses with no new errorsnpx ts-node ...)