Prompt
How do I set up an inline code suggestion platform for low-latency autocomplete in VS Code with private repository access?
Latest observation
To set up an inline code suggestion platform for low-latency autocomplete in VS Code with private repository access, you generally need four pieces:
- A VS Code extension for inline completions
- A backend suggestion service close to the editor for low latency
- Secure access to private repo context
- Caching/indexing and retrieval to keep suggestions fast
Here’s a practical setup.
1) Architecture
A good architecture looks like this:
-
VS Code extension
- Captures cursor context, open files, and optional repo signals
- Sends a small prompt/context payload to your backend
- Renders inline suggestions via VS Code’s inline completion API
-
Suggestion backend
- Runs in your cloud/VPC or on-prem
- Calls an LLM or completion model
- Uses a retrieval layer to pull relevant private code snippets
- Returns short inline completions quickly
-
Private repo ingestion/indexing
- Syncs Git repositories securely
- Builds embeddings or search indexes
- Stores metadata and access controls
- Supports repo-aware retrieval at suggestion time
-
Auth and policy layer
- Enforces per-user/per-repo permissions
- Ensures the model only sees authorized context
- Logs access for auditability
2) VS Code extension: inline completions
Use VS Code’s inline completion provider API.
What the extension does
- Watches the user’s current file, cursor position, and recent text
- Optionally includes:
- surrounding function/class
- language id
- file path
- repo identifier
- Sends a request to your suggestion API
- Displays returned completion as ghost text
Key implementation points
- Debounce requests heavily
- Cancel stale requests using abort/cancellation tokens
- Keep request payloads small
- Prefer streaming or very fast non-streaming responses for inline use
Useful VS Code APIs
languages.registerInlineCompletionItemProvider(...)TextDocumentPositionCancellationToken
3) Backend for low latency
For autocomplete, latency matters a lot. Aim for:
- p50 under 150–250 ms if possible
- p95 under 500 ms for a good experience
How to reduce latency
- Deploy backend in the same region as users or as close as possible
- Keep a warm pool of model workers
- Use a smaller/faster code model for inline completions
- Cache repeated context patterns
- Use retrieval only when necessary
- Limit context window to the minimal relevant code
Suggested request flow
- Extension sends cursor context
- Backend classifies whether this is:
- simple completion
- repository-aware completion
- snippet lookup
- Backend retrieves relevant code if needed
- Model generates a short inline completion
- Backend returns completion text and metadata
4) Private repository access
This is the most important security piece.
Best practice: do not send whole repos to the client
Instead:
- Sync private repos to a secured backend index
- Use repo-scoped access tokens or SSO identity
- Retrieve only the minimum relevant snippets
Access models
You can use one of these:
A. Backend-connected Git sync
- A service account clones private repos
- Indexes them into a vector DB + lexical search engine
- Permissions are enforced at query time
B. On-behalf-of user access
- The extension authenticates the user via SSO/OAuth
- Backend checks which repos the user can access
- Retrieval only searches authorized repos
C. Hybrid
- Server stores repo index
- User tokens are used to authorize access checks
- Best for enterprise environments
Security controls
- Encrypt indexes at rest
- Encrypt all traffic in transit
- Separate tenant or workspace indexes
- Store access logs
- Prevent prompt leakage from unauthorized repos
- Redact secrets before indexing
5) Retrieval layer for repo-aware suggestions
For private repos, a retrieval step often improves suggestion quality.
Indexing pipeline
- Clone or mirror repo
- Chunk code by:
- function
- class
- file sections
- Generate embeddings
- Store in:
- vector database
- keyword index
- metadata store
Retrieval at request time
- Use current file path, imports, symbols, and nearby code as query signals
- Retrieve top-k snippets
- Re-rank by:
- file proximity
- symbol similarity
- recent usage
- user permissions
- Pass only the top few snippets to the model
Good practice
Use hybrid retrieval:
- keyword search for exact symbol matches
- vector search for semantic matches
6) Model choice
For low-latency inline autocomplete:
- Prefer a smaller, code-optimized model
- Or a multi-stage system:
- fast small model for first pass
- larger model only for harder cases
Common patterns
- Fast local/hosted completion model for short suffix predictions
- Separate “chat” model for more complex code generation
- Cache common completions
If you need maximum privacy, consider:
- self-hosted models in your VPC
- no external API calls
- model inference on private infra
7) Request payload design
Keep payloads small and structured.
Example fields:
user_idrepo_idfile_pathlanguageprefix_textsuffix_textcursor_positionrecent_symbolsopen_tabsorworkspace contextif allowedrequest_id
Avoid sending:
- entire repository
- secrets
- unnecessary file contents
- huge context blobs
8) Caching strategy
Caching helps a lot for autocomplete.
Cache levels
- Prefix cache: same partial input -> same suggestion
- Symbol cache: common function signatures or boilerplate
- Retrieval cache: repeated repo snippet queries
- Embedding cache: avoid recomputing embeddings for unchanged files
Invalidation
- Reindex on git commit
- Invalidate affected chunks only
- Use file hashes to track changes
9) Privacy and compliance
If private repos are involved, build with:
- tenant isolation
- audit logs
- secret scanning/redaction
- data retention controls
- user consent and admin policy controls
Also consider:
- code never used to train models unless explicitly opted in
- per-org settings for retention
- data residency requirements
10) A simple implementation plan
Phase 1: MVP
- Build VS Code extension with inline completion provider
- Create backend API that returns completions from a model
- Authenticate users via SSO/OAuth
- Support one private repo by mirrored indexing
Phase 2: Repo-aware completions
- Add repo sync and chunk indexing
- Add vector + lexical retrieval
- Inject top snippets into model prompt
- Enforce per-user repo permissions
Phase 3: Optimize for latency
- Add cache
- Add model warm pools
- Reduce prompt size
- Use fast reranking
- Place backend near users
Phase 4: Enterprise hardening
- Audit logs
- Secret scanning
- Admin dashboards
- SSO, SCIM, RBAC
- Network isolation/VPC deployment
11) Recommended stack
A common stack might be:
- VS Code extension: TypeScript
- Backend API: FastAPI / Node.js / Go
- Auth: OAuth2 / OIDC / SAML via enterprise IdP
- Repo sync: GitHub App / GitLab App / SSH deploy keys
- Indexing: background workers
- Vector store: pgvector / Pinecone / Weaviate / OpenSearch
- Keyword search: OpenSearch / Elasticsearch
- Cache: Redis
- Inference: self-hosted code model or hosted LLM endpoint
12) Example flow
- Developer types in VS Code
- Extension sends
prefix_textand file metadata - Backend checks identity and repo permissions
- Backend retrieves relevant snippets from private repo index
- Model predicts next code tokens
- Extension renders inline ghost text
13) Common pitfalls
- Sending too much context, causing slow requests
- Using only vector search and missing exact symbol matches
- Not enforcing repo permissions at retrieval time
- Too-large models for inline completion
- No cancellation handling in the extension
- Not refreshing index on commit changes
If you want, I can give you one of these next:
- a reference architecture diagram
- a VS Code extension starter example
- a backend API design
- a private repo indexing pipeline
- a production security checklist
Observation history
See 1 earlier observation
Create a free Obsurfable account to unlock historical responses, model comparisons, and deeper brand intelligence.
How did Obsurfable measure this prompt?
Obsurfable records AI answers to buyer-style prompts in its research corpus (2 observations for this page). Metrics are distributions over observations, not a single static ranking.
Which AI systems does Obsurfable collect answers from?
OpenAI, ChatGPT, Google, Gemini, Google AI Mode, Anthropic, Claude, Perplexity, Grok, DeepSeek, Mistral, Copilot, and Meta AI.