Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
ffoDevilSusiJ committed Jun 24, 2024
1 parent bd1fe2d commit 108bd8b
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 33 deletions.
67 changes: 38 additions & 29 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,47 +1,56 @@
# Auto Include C++
# VSCode C++ Include Helper Extension

Automatically add include directives for C++ classes in your project.
## Overview

The **C++ Include Helper** extension for Visual Studio Code streamlines the process of adding `#include` directives to your C++ source files. As you type class names, it provides autocompletion suggestions and automatically inserts the appropriate `#include` directive at the top of your file.

![Demo](gifs/demo.gif)

## Features

- Automatically scans the workspace for C++ header and source files.
- Suggests `#include` directives for classes found in the workspace.
- Updates the class map every 30 seconds and on demand.
- Provides commands to trigger workspace analysis and add includes.
1. **Automatic Workspace Analysis**:
- The extension scans your workspace for C++ source (`.cpp`) and header files (`.h`, `.hpp`).
- It identifies class names within these files and maps them to their respective file paths.
- This analysis runs initially when the extension is activated and updates every 30 seconds to reflect any changes in your workspace.

## Usage
2. **Class Name Autocompletion**:
- While you type, the extension offers autocompletion suggestions for class names found in your workspace.
- Selecting a class from the suggestions inserts a corresponding `#include` directive at the top of the current file, ensuring you never miss an essential include.

1. Install the extension.
2. Open a C++ project in VS Code.
3. Use the command `Make an analysis` to scan the workspace for C++ classes.
4. Start typing a class name to see suggestions for `#include` directives.
5. Select a suggestion to automatically add the `#include` directive to your file.
3. **Manual Workspace Analysis Command**:
- You can manually trigger workspace analysis using the command palette (`Ctrl+Shift+P` or `Cmd+Shift+P`).
- The command `Make Analysis` updates the class mappings immediately, which is particularly useful after adding new files or classes.

## Commands

- `Make an analysis`: Manually trigger an analysis of the workspace.
- `Add Include`: Add an include directive for the selected class.
- **Add Include**: Registers a command (`Add Include`) which is currently set up to show a message confirming the execution (primarily for demonstration purposes in this version).
- **Make Analysis**: Executes the `Make Analysis` command to scan and update the workspace class mappings on demand.

## Installation
## How to Use

1. Clone the repository:
```bash
git clone https://github.com/ffoDevilSusiJ/auto-include.git
cd auto-include
```
1. **Install the Extension**:
- Install the extension from the Visual Studio Code marketplace or from a `.vsix` file.

2. Install dependencies and compile the extension:
```bash
npm install
npm run compile
```
2. **Activate the Extension**:
- Open your C++ project in VSCode. The extension will automatically activate and start scanning your workspace.

3. Open the project in VS Code and press `F5` to run the extension in a new VS Code window.
3. **Start Typing**:
- As you type a class name, the extension will suggest possible completions.
- Select the appropriate class from the suggestions to insert its `#include` directive at the top of your file.

## License
4. **Manual Analysis**:
- You can manually trigger a workspace analysis by running the `Make Analysis` command from the command palette (`Ctrl+Shift+P` or `Cmd+Shift+P`).

This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
## Installation

1. Download and install Visual Studio Code.
2. Search for "C++ Include Helper" in the VSCode marketplace and click "Install".
3. Alternatively, you can download the `.vsix` file and install it via `Extensions: Install from VSIX...` in the command palette.

## Contributing

Feel free to submit issues and pull requests to improve the project.
Contributions are welcome! Feel free to open issues or pull requests on the [GitHub repository](https://github.com/your-repo-link).

## License

This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
Binary file added gifs/demo.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "auto-include-cpp",
"displayName": "Auto Include C++",
"description": "Automatically add include directives for C++ classes",
"name": "cpp-include-helper",
"displayName": "C++ Include Helper",
"description": "The **C++ Include Helper** extension for Visual Studio Code streamlines the process of adding `#include` directives to your C++ source files. As you type class names, it provides autocompletion suggestions and automatically inserts the appropriate `#include` directive at the top of your file.",
"version": "1.0.0",
"publisher": "ffodevilsusij",
"engines": {
Expand Down
22 changes: 21 additions & 1 deletion src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,34 @@ export function activate(context: vscode.ExtensionContext) {
if (className.toLowerCase().includes(currentWord.toLowerCase())) {
let item = new vscode.CompletionItem(className, vscode.CompletionItemKind.Class);
item.detail = `Add #include "${classMap[className]}"`;
item.insertText = `#include "${classMap[className]}"`;

// Change the insertion logic to add include at the beginning of the file
item.command = {
command: 'extension.insertIncludeAtTop',
title: 'Insert Include at Top',
arguments: [`#include "${classMap[className]}"\n`]
};
completions.push(item);
}
});

return completions;
}
});

// Command to insert include at the top of the file
let disposableInsertIncludeAtTop = vscode.commands.registerCommand('extension.insertIncludeAtTop', (includeLine: string) => {
const editor = vscode.window.activeTextEditor;
if (editor) {
const document = editor.document;
const firstLine = document.lineAt(0);
editor.edit(editBuilder => {
editBuilder.insert(firstLine.range.start, includeLine);
});
}
});

context.subscriptions.push(disposableInsertIncludeAtTop);
}

function analyzeWorkspace() {
Expand Down

0 comments on commit 108bd8b

Please sign in to comment.