Skip to content

Code Completion

MyDeskBot provides intelligent AI-powered code completion that understands your codebase and context.

Overview

MyDeskBot's code completion goes beyond traditional autocomplete. It understands your entire codebase, learns from your coding patterns, and provides contextually relevant suggestions that help you write better code faster.

How It Works

Context Awareness

MyDeskBot analyzes multiple sources of context:

  • Current File: The code you're currently writing
  • Related Files: Files that import or are imported by the current file
  • Project Structure: Understanding of your project's architecture
  • Dependencies: Libraries and frameworks you're using
  • Coding Style: Your patterns and conventions

Learning from Your Code

MyDeskBot learns from:

  • Variable naming conventions
  • Code structure patterns
  • Common imports and utilities
  • Domain-specific logic
  • Testing patterns

Features

1. Inline Completions

As you type, MyDeskBot suggests completions inline:

python
# Type:
def calculate_average(

# MyDeskBot suggests:
def calculate_average(numbers: List[float]) -> float:
    return sum(numbers) / len(numbers)

Activation:

  • Auto: Suggestions appear automatically after typing
  • Manual: Press Tab to trigger suggestions

2. Multi-line Completions

MyDeskBot can suggest entire code blocks:

javascript
// Type:
class User {

// MyDeskBot suggests:
class User {
  constructor(name, email) {
    this.name = name;
    this.email = email;
  }

  validate() {
    return this.name && this.email.includes('@');
  }

  toJSON() {
    return {
      name: this.name,
      email: this.email
    };
  }
}

3. Context-aware Suggestions

MyDeskBot understands the surrounding code:

python
# If you have:
def create_user(name, email):
    pass

# MyDeskBot can suggest related functions:
def get_user(user_id):
    pass

def update_user(user_id, updates):
    pass

def delete_user(user_id):
    pass

4. Import Suggestions

MyDeskBot suggests relevant imports:

python
# Type:
datetime.now(

# MyDeskBot suggests adding:
from datetime import datetime

datetime.now()

5. Method Chain Completion

Complete entire method chains:

javascript
// Type:
const filtered = users

# MyDeskBot suggests:
const filtered = users
  .filter(user => user.active)
  .map(user => user.name)
  .sort();

Configuration

Enable/Disable Completions

JetBrains:

xml
<application>
  <component name="MyDeskBotSettings">
    <option name="inlineCompletionsEnabled" value="true" />
  </component>
</application>

VS Code:

json
{
  "mydeskbot.inlineCompletions.enabled": true
}

Neovim:

lua
require('mydeskbot').setup({
  completions = {
    enabled = true
  }
})

Trigger Mode

Choose when completions appear:

Automatic:

json
{
  "mydeskbot.completions.triggerMode": "automatic"
}

Suggestions appear automatically after you stop typing.

Manual:

json
{
  "mydeskbot.completions.triggerMode": "manual"
}

Press Tab to trigger suggestions.

Debounce Delay

Control how quickly suggestions appear:

json
{
  "mydeskbot.completions.debounceMs": 200
}

Lower values = faster suggestions but more API calls.

Max Suggestions

Limit the number of suggestions:

json
{
  "mydeskbot.completions.maxSuggestions": 3
}

Advanced Features

1. Semantic Understanding

MyDeskBot understands code semantics, not just syntax:

python
# It knows that:
calculate_average([1, 2, 3])

# Should return a float, not a list

2. Error Prevention

MyDeskBot helps avoid common errors:

javascript
// If you write:
if (user = null) {

# MyDeskBot suggests:
if (user === null) {  // Fixed assignment vs comparison

3. Pattern Recognition

Learn and repeat patterns from your codebase:

python
# If you commonly write:
async def fetch_data(url):
    async with aiohttp.ClientSession() as session:
        async with session.get(url) as response:
            return await response.json()

# MyDeskBot will suggest similar patterns:
async def post_data(url, data):
    async with aiohttp.ClientSession() as session:
        async with session.post(url, json=data) as response:
            return await response.json()

4. Cross-language Context

If you work in multiple languages, MyDeskBot can understand patterns across them:

typescript
// TypeScript pattern
interface User {
  id: number;
  name: string;
}

// MyDeskBot can suggest similar in Python
@dataclass
class User:
    id: int
    name: str

Best Practices

1. Provide Context

Give MyDeskBot context by:

  • Using descriptive names
  • Adding type hints
  • Writing clear comments
  • Maintaining consistent style

2. Review Suggestions

Always review AI suggestions:

python
# MyDeskBot might suggest:
def process_data(data):
    return [item * 2 for item in data]

# But you might need:
def process_data(data):
    return [item * 2 for item in data if item is not None]

3. Teach the AI

Help MyDeskBot learn your patterns:

python
# If it suggests:
def calc(x, y):
    return x + y

# Correct it to your style:
def calculate_sum(x: int, y: int) -> int:
    return x + y

4. Use Type Hints

Type hints improve suggestions:

python
# Without types:
def process(items):
    return [i for i in items]

# With types:
def process(items: List[Item]) -> List[ProcessedItem]:
    return [i.process() for i in items]

Keyboard Shortcuts

ActionJetBrainsVS CodeNeovim
Trigger CompletionCtrl+SpaceCtrl+SpaceTab
Accept SuggestionTab / EnterTab / EnterTab
Dismiss SuggestionEscEscEsc
Next SuggestionAlt+]Alt+]Ctrl+n
Previous SuggestionAlt+[Alt+[Ctrl+p

Troubleshooting

No Suggestions Appearing

Check:

  1. Completions are enabled
  2. API key is configured
  3. File is not too large (>10,000 lines)
  4. Language is supported

Solutions:

  • Restart your editor
  • Check network connectivity
  • Verify API credits
  • Try manual trigger

Suggestions Are Slow

Solutions:

  1. Increase debounce delay
  2. Reduce context window
  3. Use faster model (e.g., GPT-3.5 instead of GPT-4)
  4. Enable local model caching

Irrelevant Suggestions

Solutions:

  1. Provide more context (add imports, types)
  2. Check if related files are open
  3. Adjust temperature (lower for more focused suggestions)
  4. Clear MyDeskBot cache and re-index

Performance Optimization

1. Reduce API Calls

json
{
  "mydeskbot.completions": {
    "triggerMode": "manual",
    "debounceMs": 500,
    "minContextLength": 10
  }
}

2. Use Caching

json
{
  "mydeskbot.caching": {
    "enabled": true,
    "maxAge": 3600 // 1 hour
  }
}

3. Optimize Context

json
{
  "mydeskbot.context": {
    "files": 3, // Fewer files
    "linesBefore": 20,
    "linesAfter": 20
  }
}

Language Support

MyDeskBot supports code completion for:

  • JavaScript / TypeScript
  • Python
  • Java
  • Kotlin
  • Go
  • Rust
  • C#
  • C++
  • PHP
  • Ruby
  • Swift
  • And more...

Examples

Example 1: React Component

jsx
// Type:
function UserProfile

// MyDeskBot suggests:
function UserProfile({ user, onUpdate }) {
  return (
    <div className="user-profile">
      <img src={user.avatar} alt={user.name} />
      <h2>{user.name}</h2>
      <p>{user.email}</p>
      <button onClick={() => onUpdate(user)}>
        Edit Profile
      </button>
    </div>
  );
}

export default UserProfile;

Example 2: Python Data Processing

python
# Type:
def process_sales

// MyDeskBot suggests:
def process_sales(sales_data: List[Dict]) -> pd.DataFrame:
    df = pd.DataFrame(sales_data)
    df['date'] = pd.to_datetime(df['date'])
    df['revenue'] = df['quantity'] * df['price']
    return df.groupby('product_id')['revenue'].sum().reset_index()

Example 3: Java REST Controller

java
// Type:
@RestController

// MyDeskBot suggests:
@RestController
@RequestMapping("/api/users")
public class UserController {

    private final UserService userService;

    @Autowired
    public UserController(UserService userService) {
        this.userService = userService;
    }

    @GetMapping("/{id}")
    public ResponseEntity<User> getUser(@PathVariable Long id) {
        User user = userService.findById(id)
            .orElseThrow(() -> new UserNotFoundException(id));
        return ResponseEntity.ok(user);
    }

    @PostMapping
    public ResponseEntity<User> createUser(@RequestBody User user) {
        User created = userService.save(user);
        return ResponseEntity.status(HttpStatus.CREATED).body(created);
    }
}

See Also