Skip to content

Add VS Code-style autocomplete with keyword suggestions#9

Merged
martinezharo merged 3 commits into
mainfrom
claude/vscode-autocomplete-approach-p5xnwq
Jul 2, 2026
Merged

Add VS Code-style autocomplete with keyword suggestions#9
martinezharo merged 3 commits into
mainfrom
claude/vscode-autocomplete-approach-p5xnwq

Conversation

@martinezharo

Copy link
Copy Markdown
Owner

Implements autocomplete for languages that lack built-in completion sources, providing word-based suggestions merged with curated keyword lists styled to match VS Code's suggest widget.

Summary

This PR adds intelligent autocomplete to the editor for 24 languages (Java, C/C++, PHP, Go, Rust, etc.) that either use legacy grammar modes or don't ship with completion sources. The implementation combines document word suggestions with language-specific keyword lists, styled with a VS Code-inspired popup design.

Key Changes

  • New completion module (src/components/Editor/completions.ts):

    • wordAndKeywordCompletion(): Merges CodeMirror's word-based completions with optional keyword lists, deduplicating keywords that appear in the document
    • LANGUAGE_KEYWORDS: Curated keyword lists for 24 languages (reserved words, builtins, common types/functions)
  • Editor integration (src/components/Editor/Editor.tsx):

    • Refactored JavaScript/TypeScript loading into loadJavaScript() helper to add scope-aware completions via scopeCompletionSource(globalThis)
    • Added FALLBACK_COMPLETION_LANGUAGES set to identify languages needing the fallback completion source
    • Registers fallback completions for applicable languages after loading their grammar extensions
    • Enabled autocompletion globally (changed autocompletion: false to true)
  • Styling (src/app/globals.css):

    • VS Code-style suggest widget with rounded borders, elevation shadows, and theme-aware colors
    • Symbol icons with language-specific colors (functions in purple, variables in blue, types in orange, etc.)
    • Matched text highlighting in blue (dark) / navy (light)
    • Responsive layout with proper spacing and typography
  • Tests (src/__tests__/completions.test.ts):

    • Comprehensive test suite covering word/keyword merging, deduplication, explicit requests, and token replacement
    • Validation that keyword lists have no duplicates

Implementation Details

  • Completions are only registered for languages in FALLBACK_COMPLETION_LANGUAGES; languages with native completion sources (JavaScript, Python, SQL, etc.) are unaffected
  • JavaScript/TypeScript get enhanced completions via scopeCompletionSource(globalThis) to expose runtime globals
  • The keyword deduplication ensures a keyword typed in the document doesn't appear twice in suggestions
  • Styling uses CSS custom properties for theme consistency and !important flags where necessary to override CodeMirror defaults

https://claude.ai/code/session_01QAjpJTH4WCmyRXkMWLSosz

Enable CodeMirror's completion UI in the editable setup (read-only
previews stay off) and wire per-language sources:

- JS/TS/JSX/TSX: keep the built-in keyword/local completions and add
  scopeCompletionSource(globalThis) so browser globals and their
  members (console.log, JSON.parse…) complete like in VS Code.
- HTML/CSS/Python/SQL: their lang packages already ship completion
  sources; enabling the UI is enough.
- Languages without a completion source (legacy stream modes plus
  bare grammars like Java/C++/PHP/JSON/XML): a fallback source merges
  word-based suggestions from the document with curated per-language
  keyword lists, deduplicating words already offered as keywords.
- Markdown prose stays quiet; fenced code blocks complete via their
  nested language.

Style the suggest popup after VS Code (panel tokens, blue matched
text, per-type symbol icon colors) in both themes, and swap the
default key-emoji keyword glyph for a plain marker.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01QAjpJTH4WCmyRXkMWLSosz
@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Jul 2, 2026

Copy link
Copy Markdown
Contributor

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Preview URL Updated (UTC)
✅ Deployment successful!
View logs
klipcode dce30b7 Commit Preview URL

Branch Preview URL
Jul 02 2026, 08:57 AM

@martinezharo martinezharo merged commit 6f23c1c into main Jul 2, 2026
2 checks passed
@martinezharo martinezharo deleted the claude/vscode-autocomplete-approach-p5xnwq branch July 2, 2026 12:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants