-
Notifications
You must be signed in to change notification settings - Fork 145
feat(command): Add Create Source/Header Pair command #840
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
Improves the C++ development workflow by providing a new command to create corresponding source and header files simultaneously, mirroring common IDE functionality. This new command, `clangd.createSourceHeaderPair`, provides the following features: - Prompts the user for a valid C++ class name with robust validation. - Intelligently detects the target directory, preferring the active file's location. - Generates professional-grade file templates for both the header and source file. - Handles cross-platform line endings (EOL) correctly by respecting user settings. - Prevents accidental file overwrites by checking for existing files before creation. - Is accessible from the Command Palette and the editor context menu. Resolves #[Your-Issue-Number-Here]
Refactored the PairCreator class to modularize logic for file name validation, language detection, template generation, file existence checks, and file writing. Added interfaces and constants for better type safety and maintainability. Improved user prompts and error handling, and made the code more extensible for both C and C++ file generation.
context-aware wizard, significantly improving user experience and flexibility. Key improvements include: - A single, multi-step input flow for all creation logic. - Dynamically sorts template choices based on the active language context (C vs. C++), prioritizing the most likely user intention. - Disambiguates between C and C++ structs, providing correct templates and file extensions for each. - Introduces intelligent, dynamic placeholders in the file name input box based on the current file and selected template. - The underlying code has been significantly refactored for clarity, maintainability, and type safety, breaking down complex logic into single-responsibility helper methods.
|
Following up on my previous comment, I took some time to explore the idea of context-aware support for both C and C++, and I'm excited to share the results. |
Replaces the old template and file extension logic with a unified PairingRule structure, simplifying template selection and file generation for C and C++ header/source pairs. Improves language detection, user prompts, and file content generation, making the code more maintainable and user-friendly.
|
Just wanted to post a final summary of what this PR currently accomplishes and what I see as potential next steps, based on all the great feedback and discussion in issue #839. What this PR delivers:
Current Limitations & Future Work:
I believe this PR, in its current state, provides a solid and valuable foundation. Thank you again for all the guidance. I'm looking forward to your review! |
Renamed 'createSourceHeaderPair' to 'newSourcePair' throughout the codebase and updated command titles for clarity. Added a new command for configuring source/header pairing rules. Improved template rule labels with icon syntax for better UI presentation. Created a placeholder for pairing rule service.
|
It's almost done, but the template issue still isn't resolved, and it can only generate .h type templates. Besides that, the code is pretty long due to a lot of templates and comments. If possible, can we break it down into separate files? |
Split the monolithic create-source-header-pair.ts into separate files: coordinator.ts, service.ts, ui.ts, and templates.ts, and updated the module index and registration logic. Updated package.json command and configuration descriptions for clarity. Adjusted extension and command registration in extension.ts and updated pairing-rule-manager.ts as needed.
Refactored the coordinator to move directory and language detection to the service layer, streamlined the file creation flow, and added logic to offer saving custom C++ extension pairs as defaults. The UI now prompts for template type and file extensions in a more intuitive order, and success messages are shown non-blockingly. Service layer now provides file path creation and improved file existence caching.
Refactors the PairCoordinator to use dependency injection for service and UI layers, simplifying the workflow and improving testability. Moves file creation and rule-saving logic into the service layer, and moves workspace folder picking into the UI layer. Updates the registration logic to construct dependencies explicitly. Also, centralizes file extension selection UI in PairingRuleUI and cleans up related code.
Added an icon to the 'New Source/Header Pair' command and registered it in the explorer context menu for folders. This improves discoverability and usability of the command within the file explorer.
Deleted the clangd.newSourcePair command configuration from the package.json contributes.commands section. This cleans up unused or deprecated command definitions.
|
finished. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See comments
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
vscode-nls seems to be deprecated: https://github.com/microsoft/vscode-nls
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See comment in bug, though I'd be more inclined to ask for a snippet ID rather than having fields to indicate a class/struct.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like your addition of relevant icons, though can you do this in a separate PR, such that it's easier to track the relevant changes and/or land these changes separately?
| import * as vscodelc from 'vscode-languageclient/node'; | ||
|
|
||
| import {ClangdContext} from './clangd-context'; | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
File is touched without any significant changes. Can you undo this newline? (Unless required by formatting rules)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This contains a lot of code trying to find out which rule the user intended. Can't we delegate that to the user? If they add a 'label' as part of the configuration, they can have a rule for classes, structs, free functions or anything custom with the exact same extensions. They can than pick the intended entry from a list.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Binaries should not be included
| { | ||
| "name": "vscode-clangd", | ||
| "version": "0.2.0", | ||
| "name": "vscode-clangd-fancy", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please don't rename the project



Improves the C++ development workflow by providing a new command to create corresponding source and header files simultaneously, mirroring common IDE functionality.
This new command,
clangd.createSourceHeaderPair, provides the following features:Resolves #839