Documentation
Core Features/AI Code Assistance

AI Code Assistance

ThinkCode leverages advanced artificial intelligence to enhance your coding workflow, increase productivity, and reduce cognitive load. This guide covers the core AI assistance features and how to best utilize them.

Understanding AI Code Assistance

ThinkCode's AI code assistance helps you write, understand, and improve code through context-aware suggestions and intelligent guidance.

graph LR
    A[Developer Intent] --> B[ThinkCode AI]
    B --> C[Code Suggestions]
    B --> D[Inline Completions]
    B --> E[Code Generation]
    B --> F[Explanations]
    B --> G[Refactoring]
    
    style B fill:#f96,stroke:#333,stroke-width:2px

Key Capabilities

Code Generation

Transform natural language or comments into working code:

From Natural Language

Use the Think Panel to generate code from descriptions:

  1. Open the Think Panel with Ctrl+Shift+T (Cmd+Shift+T on macOS)
  2. Describe what you need: "Create a React hook that manages a paginated API request with error handling"
  3. Review and apply the generated code

From Comments

Write descriptive comments and get code generated inline:

// Create a function that fetches user data from an API and caches the results
function fetchUserData(userId) {
  // AI will generate implementation here
}

After typing your comment, press Alt+Enter (Option+Enter on macOS) to generate the implementation.

Multi-File Generation

For larger features that span multiple files:

  1. Open the Think Panel
  2. Describe the feature: "Create a user authentication system with login, registration, and password reset"
  3. The AI will analyze your project structure and suggest implementations across multiple files

Intelligent Code Completion

ThinkCode provides context-aware completions as you type:

Inline Completions

As you write code, ThinkCode suggests completions based on:

  • Current file context
  • Project patterns and conventions
  • Related files and imports
  • Type information
  • Documentation

Accept suggestions with Tab or dismiss with Esc.

Completion Controls

Fine-tune your completion experience:

ActionShortcut
Accept full suggestionTab
Accept word by wordCtrl+Right / Cmd+Right
Next suggestionAlt+] / Option+]
Previous suggestionAlt+[ / Option+[
Trigger suggestion manuallyAlt+\ / Option+\
Dismiss suggestionEsc

Completion Settings

Adjust the frequency and behavior of completions in Settings:

{
  "think.suggestions.enabled": true,
  "think.suggestions.mode": "inline",
  "think.suggestions.frequency": "medium",
  "think.suggestions.languages": {
    "typescript": true,
    "javascript": true,
    "python": true
  }
}

Code Understanding and Explanations

Get instant explanations for complex code:

Explain Code

To explain selected code:

  1. Select the code you want to understand
  2. Right-click and choose "Think: Explain Selection" or use Ctrl+Alt+E (Cmd+Option+E on macOS)
  3. View the explanation in the Think Panel

Example explanation for complex regex:

The selected regex pattern /^(([^<>()[\]\\.,;:\s@"]+(\.[^<>()[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/ is an email validation pattern that:

1. Validates the local part (before @) which can be:
   - A sequence of characters not containing <>()[]\\.,;:\"@ or whitespace, with optional dots between
   - OR a quoted string

2. Followed by @ symbol

3. Validates the domain part which can be:
   - An IP address in square brackets
   - OR a sequence of alphanumeric subdomains with a top-level domain of at least 2 characters

Understanding Error Messages

Get plain-language explanations for errors:

  1. Hover over the error squiggle
  2. Click "Explain Error" in the hover tooltip
  3. View the explanation and suggested fix

Code Refactoring and Improvement

Improve existing code with AI-assisted refactoring:

Refactor Selection

To refactor code:

  1. Select the code to refactor
  2. Right-click and choose "Think: Refactor Selection" or use Ctrl+Alt+R (Cmd+Option+R on macOS)
  3. View suggested improvements in the Think Panel
  4. Apply changes selectively or all at once

Optimization Suggestions

Get performance optimization suggestions:

  1. Select code to optimize
  2. Right-click and choose "Think: Optimize Selection"
  3. Review suggested optimizations with explanations of potential performance improvements

Code Quality Improvements

Improve code quality with AI suggestions:

  1. Select code to improve
  2. Use the Command Palette (Ctrl+Shift+P / Cmd+Shift+P) to run "Think: Improve Code Quality"
  3. Review suggestions for:
    • Better naming
    • More maintainable structure
    • Improved error handling
    • Enhanced readability
    • Proper documentation

Advanced Features

Language-Specific Assistance

ThinkCode provides specialized assistance for different programming languages:

TypeScript/JavaScript

  • Type inference and suggestions
  • React component generation
  • Modern ES6+ patterns
  • Framework-specific suggestions (React, Angular, Vue, etc.)

Python

  • PEP 8 compliant suggestions
  • Library-specific code patterns (Django, Flask, NumPy, etc.)
  • Type hints and documentation

Other Languages

ThinkCode supports numerous languages with varying levels of assistance:

  • Java
  • C#
  • Go
  • Rust
  • PHP
  • Ruby
  • And many more

Interactive Code Generation

For complex generation tasks, engage in an interactive process:

  1. Start with a high-level request
  2. Review the initial generation
  3. Ask follow-up questions to refine
  4. Provide feedback on what works and what doesn't
  5. Guide the AI to your desired implementation

Example conversation:

You: Generate a React component for a file upload form
AI: [Generates basic file upload component]
You: Can you add drag-and-drop functionality?
AI: [Updates code with drag-and-drop]
You: How would I limit it to only accept image files?
AI: [Explains and implements file type restrictions]

AI Unit Test Generation

Generate comprehensive test suites:

  1. Select the code to test
  2. Use the Command Palette to run "Think: Generate Tests"
  3. Choose your testing framework (Jest, Mocha, Pytest, etc.)
  4. Review and customize the generated tests

Code Transformation

Transform code between different styles or paradigms:

  1. Select the code to transform
  2. Use the Command Palette to run "Think: Transform Code"
  3. Choose a transformation type:
    • Convert to async/await from Promises
    • Refactor class to functional components
    • Convert to TypeScript from JavaScript
    • And many more

AI-Generated Documentation

Generate comprehensive documentation for your code:

  1. Select the code to document
  2. Use Ctrl+Alt+D (Cmd+Option+D on macOS)
  3. Choose documentation style (JSDoc, docstrings, etc.)
  4. Review and customize the generated documentation

Best Practices

Effective Prompting

Get better results with these prompting techniques:

  • Be specific: Provide clear, detailed instructions
  • Add context: Mention frameworks, patterns, or requirements
  • Iterative refinement: Start general, then refine with follow-up requests
  • Use examples: Show examples of the patterns you prefer

Verifying AI Code

Always review AI-generated code:

  • Understand the code: Make sure you understand what the AI has generated
  • Test thoroughly: Verify functionality with appropriate tests
  • Check edge cases: Consider boundary conditions and error scenarios
  • Review for security: Look for potential security issues
  • Optimize if needed: Make performance improvements where necessary

Customizing AI Behavior

Adjust ThinkCode's AI to match your preferences:

  • AI Settings: Customize in the settings under "Think" section
  • Context Controls: Adjust what files the AI considers
  • AI Roles: Switch between different AI personalities (Developer, Architect, Reviewer, etc.)
  • Language-Specific Settings: Configure behavior for specific languages

Troubleshooting

Improving Poor Suggestions

If you're getting unhelpful suggestions:

  1. Provide more context: Give additional information about your project and goals
  2. Use more specific prompts: Detail exactly what you need
  3. Adjust AI settings: Change the suggestion frequency or model
  4. Check file visibility: Ensure relevant files are available in the workspace
  5. Update AI model: Check if you're using the latest AI model

Managing Resource Usage

If AI features are causing performance issues:

  1. Adjust suggestion frequency in settings
  2. Limit the context size
  3. Use lighter AI models
  4. Close unused files

Next Steps

To further enhance your AI coding experience:

Pro Tip

Create a file called .thinkcode/prompts.json in your project root to save commonly used prompts for your team. This helps maintain consistency when using AI assistance across your project.