Repository navigation
Export a C or C++ header document as .h or .hpp [minor] - #368
Merged
Merged
Conversation
A SourceFile marked IsHeader is generated with #pragma once, but the editor's export always named the file with the generator's fixed extension, so a header came out as Physics.cpp / Physics.c. ILanguageGenerator gains FileExtensionFor(AstNode), defaulting to FileExtension. CFamilyGenerator answers HeaderFileExtension for a header SourceFile: "h" for C, "hpp" for C++. The editor's Export asks for the extension of the document it is writing. Fixes #367 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_017vfJW1rKnQJLnGSj1mbcDM
|
This was referenced Oct 30, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



Fixes #367
What was wrong
A
SourceFilewithIsHeaderis generated with#pragma once, butCoderEditorApp.Exportalways named the output{stem}.{generator.FileExtension}. A header document therefore came out asPhysics.cpporPhysics.c, which an#include "Physics.hpp"can't find and a*.cppglob compiles as its own translation unit.Change
ILanguageGenerator.FileExtensionFor(AstNode)is a new default interface member that returnsFileExtension.LanguageGeneratorBaseimplements it as a virtual method. (It isn't calledGetFileExtensionbecause CA1721 rejects that name next to theFileExtensionproperty.)CFamilyGeneratoroverrides it and returnsHeaderFileExtensionfor aSourceFile { IsHeader: true }.HeaderFileExtensionis virtual and defaults toh. C++ overrides it tohpp, so a C++ header isn't mistaken for one a C compiler can read.CoderEditorApp.Exportasks the generator for the extension of the document's root..cand.cpp. Every other language ignores the flag.This is marked
[minor]because it adds public API (the interface member is defaulted and the new property is virtual, so existing implementers still build).Tests
CoderEditorAppTests.Export_NamesAHeaderDocumentAsAHeadercovers C and C++, header and non-header. It checks the exported path and whether the file carries#pragma once.GeneratorFileExtensionTestscovers the C-family header extensions, and checks that every generator keeps its ordinary extension for a non-header and that the non-C-family languages ignoreIsHeader.Generated by Claude Code