@exercism/codemirror-lang-cpp
v1.0.2
Published
C, C++ and Objective-C language support for the CodeMirror code editor, with autocompletion
Readme
@codemirror/lang-cpp 
Exercism's fork
This is Exercism's fork of @codemirror/lang-cpp.
Exercism uses it in the C, C++ and Objective-C editors on exercism.org.
It is published on npm as @exercism/codemirror-lang-cpp.
Our changes are on the exercism branch, and the main branch follows upstream.
Below this section, the README is upstream's.
The fork adds autocomplete to the upstream package. Use cpp() for C++
and c() for C. Both use the same parser, @exercism/lezer-cpp, and offer different names.
cpp()offers C++ keywords, fundamental types and literals, the fixed-width integer types, and snippets formain, functions,if, the loops (including rangefor),switch, classes, structs,enum class, namespaces,try/catch, lambdas, templates,#include,#define, include guards and#pragma once. Afterstd::it offers the common members of the standard library. If the file saysusing namespace std;, it offers them without the prefix too.c()offers C99 keywords and types,bool,true,falseandNULL, the common functions, types and macros of the C standard library, and snippets formain, functions,if, the loops,switch, structs,typedef struct, enums,#include,#defineand include guards.- Inside
#include <...>, both offer the standard header names. - Both offer the names declared in the file that are in scope at the
cursor: functions, structs, classes, unions, enums and their
enumerators, typedefs and
usingaliases, template parameters, fields (inside the class), namespaces, macros, parameters, and local, loop and catch variables. A local variable is offered only after its declaration.
objc() gives Objective-C support. It uses the parser's objc
dialect, which adds classes, protocols, methods, properties, message
sends, @ literals and blocks to C.
- It offers C's keywords and library, Objective-C's keywords and types
(
self,nil,YES,id,instancetype,BOOL,NSIntegerand others), and the common Foundation classes, functions and constants. - When the word starts with
@, it offers the@directives, with snippets for@interface,@implementation,@protocol,@property,@try/@catch,@autoreleasepool,@selectorand the array and dictionary literals. - Its other snippets cover C's constructs,
#import,for ... in, instance and class methods,init,NS_ENUMand blocks. - Where a message names its method, as in
[list add|, it offers the common Foundation selectors and the selectors of the methods declared in the file. CompletingsetObject:forKey:insertssetObject:. - It offers the names declared in the file where they are in scope:
classes, protocols,
NS_ENUMtypes and their values, properties and their_nameinstance variables, instance variables, C functions and variables,for ... inloop variables, and the parameters of methods, blocks and functions. - Inside
#import <...>, it offersFoundation/Foundation.hand the C headers.
Completion stays quiet in strings and comments, and after ., ->
or :: (apart from std::).
Install
npm install @exercism/codemirror-lang-cppBuilding and testing
To build and test it from a checkout, run npm install (which also builds the package), then npm test.
Contributing
Contributions to this fork follow the Exercism Code of Conduct. Please read about how to contribute to Exercism.
[ WEBSITE | ISSUES | FORUM | CHANGELOG ]
This package implements C++ language support for the CodeMirror code editor.
The project page has more information, a number of examples and the documentation.
This code is released under an MIT license.
We aim to be an inclusive, welcoming community. To make that explicit, we have a code of conduct that applies to communication around the project.
Usage
import {EditorView, basicSetup} from "codemirror"
import {cpp} from "@exercism/codemirror-lang-cpp"
const view = new EditorView({
parent: document.body,
doc: `for (int i = 0; i < 1024; i++)\n cout << elt[i] << "\\n";`,
extensions: [basicSetup, cpp()]
})