Skip to content

Latest commit

 

History

History
15 lines (11 loc) · 851 Bytes

File metadata and controls

15 lines (11 loc) · 851 Bytes

Inline C++

Makes C++ code embedded in Rust files pleasant to work with.

If you keep C++ source inside a Rust string — VS Code normally paints the whole thing as one flat string color, and nothing formats it. This extension fixes both: tag the string with /* cpp */ and its contents get real C++ syntax highlighting, plus optional clang-format on save.

const KERNEL: &str = r#" /* cpp */
    __global__ void k(float *x) {
        x[threadIdx.x] *= 2.0f;
    }
"#;

Add "rust-analyzer.semanticHighlighting.strings.enable": false to your VS Code settings, otherwise the Rust language plugin colors the whole string itself and covers up the C++ highlighting. Also optionally, if you'd like the embedded C++ tidied up automatically every time you save, turn on the inlineCpp.formatOnSave setting to run clang-format from path.