Once the worker is configured, use the @volar/monaco utility functions to activate core language features. You must first register the language in Monaco, then create a WebWorker instance, and finally call the activation functions.
Key functions:
activateMarkers: Enables diagnostic markers (errors, warnings, etc.).activateAutoInsertion: Enables automatic tag closing/insertion.registerProviders: Registers IntelliSense/completion providers.
All these functions require a sync files callback that returns an array of Uri objects representing the current files in the editor context.
import type { WorkerLanguageService } from '@volar/monaco/worker';
import { editor, languages, Uri } from 'monaco-editor-core';
import { activateMarkers, activateAutoInsertion, registerProviders } from '@volar/monaco';
languages.register({ id: 'my-lang', extensions: ['.my-lang'] });
languages.onLanguage('my-lang', () => {
const worker = editor.createWebWorker<WorkerLanguageService>({
moduleId: 'vs/language/my-lang/myLangWorker',
label: 'my-lang',
});
activateMarkers(
worker,
['my-lang'],
'my-lang-markers-owner',
// sync files
() => [Uri.file('/Foo.my-lang'), Uri.file('/Bar.my-lang')],
editor
);
// auto close tags
activateAutoInsertion(
worker,
['my-lang'],
// sync files
() => [Uri.file('/Foo.my-lang'), Uri.file('/Bar.my-lang')],
editor
);
registerProviders(
worker,
['my-lang'],
// sync files
() => [Uri.file('/Foo.my-lang'), Uri.file('/Bar.my-lang')],
languages
)
});