blog bg

April 18, 2025

Enhancing LLM-Driven Autocomplete in VS Code with DeepSeek

Share what you learn in this blog to prepare for your interview, create your forever-free profile now, and explore how to monetize your valuable knowledge.

 

Have you ever wished that VS Code's suggestion feature could understand what you are typing, suggest quick answers, and explain complicated functions? If so, an extension for VS Code that works with DeepSeek might change the rules. 

Autocomplete and inline documentation help developers get more done faster, avoid making mistakes, and write better code. With LLM, DeepSeek is better than built-in IntelliSense. We can improve development by incorporating an AI-driven coding aid into VS Code. I will show you how to set up and build a custom VS Code app that uses DeepSeek to have AI-powered completion and explanations right in the code. 

 

Understanding DeepSeek and Its Capabilities

As an LLM, DeepSeek aspires to comprehend code, produce code, and alter code. While basic search is different, DeepSeek:

  • Predicts code structures, not just words.
  • Makes context-aware completion suggestions depending on code.
  • Offers inline documentation for quick explanations.

If you type def fetch_data, DeepSeek will build a whole function based on the situation. This is what we will use in our VS Code extension.

 

Setting Up a VS Code Extension with DeepSeek

 

Step 1: Install Required Tools

Installing the following tools is important before coding. Be sure to have:

  • Node.js to execute JavaScript-based VS Code extensions.
  • Yeoman and VS Code Extension Generator

Execute these terminal commands:

npm install -g yo generator-code

This installs Yeoman, a scaffolding tool, and the VS Code extension generator to make project setup faster.

 

Step 2: Create a New VS Code Extension

Now, let's make a simple extension for VS Code:

yo code

Pick out a type of extension. Give your "New TypeScript Extension" the name deepseek-autocomplete and do the defaults. This puts all the setup files in a project folder. 

 

Step 3: Install DeepSeek API SDK 

There is an LLM API on DeepSeek. Download and install a valid SDK or use direct API calls. For now, let us use HTTP to ask DeepSeek a question. 

Install Axios to handle API requests:
npm install axios

Start by editing src/extension.ts to add the DeepSeek API interface.

 

Implementing AI Autocomplete and Inline Documentation

 

Step 4: Register an Autocomplete Provider

Integrate DeepSeek with Visual Studio Code's IntelliSense using a CompletionItemProvider. This fetches DeepSeek AI suggestions according to user input.

Modify src/extension.ts:
import * as vscode from 'vscode';
import axios from 'axios';

export function activate(context: vscode.ExtensionContext) {
    let provider = vscode.languages.registerCompletionItemProvider(
        { scheme: 'file', language: 'javascript' },  // Target JavaScript files
        {
           provideCompletionItems(document, position, token, context) {
                return getDeepSeekSuggestions(document, position);
            }
        },
        '.' // Trigger on typing "."
    );

   context.subscriptions.push(provider);
}

async function getDeepSeekSuggestions(document: vscode.TextDocument, position: vscode.Position) {
    let textBeforeCursor = document.getText(new vscode.Range(new vscode.Position(position.line, 0), position));
   
    try {
        const response = await axios.post('https://deepseek-api.example.com/autocomplete', {
            input: textBeforeCursor
        });

        if (response.data.suggestions) {
            return response.data.suggestions.map((s: string) => {
                let item = new vscode.CompletionItem(s, vscode.CompletionItemKind.Method);
               item.insertText = s;
                return item;
            });
        }
    } catch (error) {
       console.error('DeepSeek API error:', error);
    }

    return [];
}

export function deactivate() {}

See what this script does:

  1. Look at requests for autocomplete in JavaScript code.
  2. Gets the current line of text and sends it to DeepSeek.
  3. Handles suggestions made by AI and sends completions.

 

Step 5: Add Inline Documentation Support

Get details of DeepSeek functions to help us make our extension better. Add hover support to src/extension.ts:

let hoverProvider = vscode.languages.registerHoverProvider({ scheme: 'file', language: 'javascript' }, {
    async provideHover(document, position, token) {
        let wordRange = document.getWordRangeAtPosition(position);
        let word = document.getText(wordRange);

        try {
            const response = await axios.post('https://deepseek-api.example.com/explain', {
               function_name: word
            });

            if (response.data.explanation) {
                return new vscode.Hover(response.data.explanation);
            }
        } catch (error) {
           console.error('DeepSeek API error:', error);
        }

        return null;
    }
});

context.subscriptions.push(hoverProvider);

When you hover over a function name, DeepSeek now displays an inline description.

 

Optimizing Performance and User Experience

We need to improve performance even if our extension does work. See some major improvements:

  • Minimize API latency by caching frequent recommendations to reduce network queries.
  • Batch API requests to aggregate requests over a short time instead of sending them on each keystroke.
  • Allow user settings to let users choose more or fewer recommendations.

 

Example of caching suggestions using a simple in-memory object:

let cache: { [key: string]: string[] } = {};

async function getDeepSeekSuggestions(document: vscode.TextDocument, position: vscode.Position) {
    let textBeforeCursor = document.getText(new vscode.Range(new vscode.Position(position.line, 0), position));
   
    if (cache[textBeforeCursor]) {
        return cache[textBeforeCursor].map(s => new vscode.CompletionItem(s, vscode.CompletionItemKind.Method));
    }

    try {
        const response = await axios.post('https://deepseek-api.example.com/autocomplete', { input: textBeforeCursor });
        if (response.data.suggestions) {
           cache[textBeforeCursor] = response.data.suggestions;
            return response.data.suggestions.map(s => new vscode.CompletionItem(s, vscode.CompletionItemKind.Method));
        }
    } catch (error) {
       console.error('DeepSeek API error:', error);
    }

    return [];
}

 

Conclusion

This is only starting! Several updates in the future could make this connection even stronger. If AI-driven finishing worked with more programming languages, some workers would be able to use it more. Response times might get even faster if offline model fine-tuning makes servers less important. User-defined UI components might simplify development and enhance AI suggestions. 

DeepSeek's AI-powered VS Code code helper enhances inline documentation and completion. Due to its smart AI recommendations and explanations, this extension boosts productivity and code accuracy. See how it aids development by giving it a go and tweaking it as needed.

58 views

Please Login to create a Question