Constructor
new CodeMirrorWorker(mode)
#
Properties
mode :string
#
The mode for which the worker is created.
Type:
- string
- Source:
The mode for which the worker is created.
queue
#
Queue of callbacks to be called when the worker is loaded.
- Source:
Queue of callbacks to be called when the worker is loaded.
Methods
Get the configuration for the worker.
Get the localized messages for the worker.
getLintConfig() → {Promise}
#
Get the linting configuration for the worker.
lint(view) → {Promise}
#
Get lint diagnostics for the given document.
Parameters:
| Name | Type | Description |
|---|---|---|
view |
EditorView |
Returns:
- Type
- Promise
- Source:
Get lint diagnostics for the given document.
onload(callback)
#
Add a callback to be called when the worker is loaded.
Parameters:
| Name | Type | Description |
|---|---|---|
callback |
function |
- Source:
Add a callback to be called when the worker is loaded.
setConfig(config)
#
Set the configuration for the worker. This can be used to customize the rules for ESLint and Stylelint.
Example
mw.hook( 'ext.CodeMirror.ready' ).add( ( cm ) => {
const { worker } = cm.langExtension;
if ( cm.mode === 'javascript' ) {
// ESLint configuration
worker.onload( () => {
worker.setConfig( {
rules: {
semi: 2
}
} );
} );
} else if ( cm.mode === 'css' ) {
// Stylelint configuration
worker.onload( () => {
worker.setConfig( {
rules: {
'length-zero-no-unit': true
}
} );
} );
}
} );
Parameters:
| Name | Type | Description |
|---|---|---|
config |
Object |
- Source:
Set the configuration for the worker.
setI18N(i18n)
#
Set the localized messages for the worker.
setLintConfig(config)
#
Set the linting configuration for the worker. This can be used to customize the rules for WikiLint.
Example
mw.hook( 'ext.CodeMirror.ready' ).add( ( cm ) => {
const { worker } = cm.langExtension;
if ( cm.mode === 'mediawiki' ) {
// WikiLint configuration
worker.onload( () => {
worker.setLintConfig( {
rules: {
'insecure-style': 2
}
} );
} );
}
} );
Parameters:
| Name | Type | Description |
|---|---|---|
config |
Object |
- Source:
Set the linting configuration for the worker.
pos(view, line, column) → {number}static
#
Calculate the position in the document for a given line and column.
Parameters:
| Name | Type | Description |
|---|---|---|
view |
EditorView | |
line |
number | |
column |
number |
Returns:
- Type
- number
- Source:
Calculate the position in the document for a given line and column.