Skip to content

feat(cmake): add CMakeLists.txt IntelliSense and title bar project build/run actions - #7

Open
FunToHard wants to merge 2 commits into
mainfrom
feat/cmake-language-and-title-run-actions
Open

FunToHard wants to merge 2 commits into
mainfrom
feat/cmake-language-and-title-run-actions

Conversation

@FunToHard

@FunToHard FunToHard commented Nov 7, 2026 •

Copy link
Copy Markdown
Contributor

Summary

This pull request introduces offline CMake language intelligence and syntax highlighting for CMakeLists.txt and *.cmake, resolves continuous clangd destroyed stream error loops, and adds project build/run action options to the editor title Run button when a project file is focused.

1. CMake Syntax Highlighting & Language Configuration

  • Added \syntaxes/CMake.tmLanguage.json\ and \syntaxes/CMakeCache.tmLanguage.json\ from TextMate grammar definitions.
  • Added \syntaxes/cmake-language-configuration.json\ for comments (#), bracket matching, and auto-closing pairs.
  • Registered \contributes.languages\ (\cmake\ and \cmake-cache) and \contributes.grammars\ in \package.json.
  • Preserved packaging in .vscodeignore.

2. Clangd Stream Error Suppression & Watcher Isolation

  • Root cause:
    1. \CMakeWatcher\ treated \CMakeLists.txt\ as a compilation database, triggering \daemonManager.restart()\ on every keystroke/save and double-reloading through \cmakeManager.refresh().
    2. \cmakeManager.synthesizeCompilationDatabase\ rewrote \compile_commands.json\ even when content did not change, creating an infinite reload loop.
    3. Pending \ extDocument/semanticTokens/full\ requests dispatched during stream teardown triggered \Cannot call write after a stream was destroyed Code: -32099\ because semantic tokens were not intercepted in middleware.
  • Fix:
    • Added \isConnectionOrStreamError\ to classify stream teardown codes (-32099, -32097, ERR_STREAM_DESTROYED, stream disposed messages).
    • Implemented \provideDocumentSemanticTokens, \provideDocumentSemanticTokensEdits, and \provideDocumentRangeSemanticTokens\ middleware guards returning
      ull\ gracefully when the stream is closing/destroyed or when \isServerReady()\ is false.
    • Guarded \provideCompletionItem,
      esolveCompletionItem, \provideWorkspaceSymbols, \provideHover, \provideDefinition, \provideInlayHints, and \provideCodeActions\ against unready server states and connection dropouts.
    • Added \isServerReady()\ method to \DaemonManager\ and handled stream errors in \errorHandler.error\ with suppression logging.
    • Isolated \CMakeWatcher\ so CMake configuration edits only update AST/presets without restarting clangd unless compilation database contents actually change.
    • Made \synthesizeCompilationDatabase\ idempotent by comparing existing on-disk content before writing.

3. Offline IntelliSense for CMakeLists.txt & *.cmake

  • Completion Item Provider (\CMakeLanguageService):
    • Autocompletion for 130 CMake commands with parameter snippets (\�dd_executable, \ arget_include_directories, \ arget_link_libraries, \ ind_package, \project, \cmake_minimum_required, etc.).
    • Autocompletion for 1,362 built-in CMake variables (\CMAKE_CXX_STANDARD, \CMAKE_BUILD_TYPE, \CMAKE_CURRENT_SOURCE_DIR, \BUILD_SHARED_LIBS, etc.) with contextual triggering inside \.
    • Autocompletion for standard keywords and scoping modifiers (\PUBLIC, \PRIVATE, \INTERFACE, \REQUIRED, \COMPONENTS, \STATIC, \SHARED, \MODULE, \CONFIG, \WIN32, \PROPERTIES).
  • Hover Provider:
    • Command hovers render signatures, parameter visibility breakdowns, and syntax examples in formatted markdown.
    • Variable hovers render descriptions, expected types, and default values.
    • Keyword hovers document scope propagation and behavior.

4. Project Run Button Options

  • Added one-click project actions to the editor title Run button (\editor/title/run) when a project file is focused (\CMakeLists.txt, *.cmake, .sln, .slnx, .vcxproj):
    • Build & Run Project (\c-cpp-pro.buildAndRunProject)
    • Build Project (\c-cpp-pro.buildProject)
    • Build & Debug Project (\c-cpp-pro.buildAndDebugProject)
  • Controller implemented in \ProjectBuildController\ (\src/tasks/project-build-controller.ts).

Verification

  • TypeScript typecheck (
    pm run check-types): 0 errors.
  • Unit test suite (
    pm test): 518 passing (100% pass rate).
  • Production build bundle (
    pm run build): Completed cleanly.
  • Strict No Emojis rule maintained across all files, comments, and commit messages.

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.

1 participant