Skip to content

Commit

Permalink
feat(monaco-language-apidom): allow override ApiDOM Context (#4290)
Browse files Browse the repository at this point in the history
Refs #4216
  • Loading branch information
char0n committed Jul 18, 2023
1 parent da81530 commit 1a2081b
Show file tree
Hide file tree
Showing 6 changed files with 824 additions and 1,736 deletions.
46 changes: 42 additions & 4 deletions docs/customization/plug-points/editor-monaco-language-apidom.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,43 @@
# editor-monaco plug points

## Configuring web worker capabilities

Worker accepts configuration for a language service via ApiDOM Context configuration object.
By default, this configuration looks like this:

```js
{
validatorProviders: [],
completionProviders: [],
performanceLogs: false,
logLevel: apidomLS.LogLevel.WARN,
defaultLanguageContent: {
namespace: 'asyncapi',
},
completionContext: {
maxNumberOfItems: 100,
enableLSPFilter: false,
},
}
```

If you want to override the default ApiDOM Context configuration object, you need to pass `apiDOMContext` option to the `EditorMonacoLanguageApiDOM` plugin.

```js
EditorMonacoLanguageApiDOM({
createData: {
apiDOMContext: {
completionContext: {
enableLSPFilter: true, // enables "strict" word filtering (instead of default Monaco fuzzy matching; https://github.com/swagger-api/apidom/pull/2954)
},
},
},
});
```

> NOTE: note that the provided ApiDOM Context configuration object is merged with default ApiDOM Context configuration object
using [deep-extend](https://www.npmjs.com/package/deep-extend) npm package.

## Extending web worker capabilities

`editor-monaco-language-apidom` comes with implementation of `apidom` language.
Expand All @@ -10,14 +48,14 @@ The plugin comes with `apidom.worker` utilizing ApiDOM capabilities.

Dynamic extension happens during runtime, and we recommend to use it only for simple use-cases.

First thing we need to do is to pass a `customApiDOMWorkerPath` option to the `EditorMonaco` plugin.
First thing we need to do is to pass a `customApiDOMWorkerPath` option to the `EditorMonacoLanguageApiDOM` plugin.

```js
EditorMonacoLanguageApiDOM({
createData: {
customApiDOMWorkerPath: 'https://example.com/index.js',
},
})
});
```
`customApiDOMWorkerPath` is a URL (absolute or relative) of extending script. When the `apidom.worker`
is bootstrapping it, it imports this URL using [importScripts](https://developer.mozilla.org/en-US/docs/Web/API/WorkerGlobalScope/importScripts).
Expand Down Expand Up @@ -103,15 +141,15 @@ it will be fetching data on demand from authorized REST endpoint.

### Dynamic extension

`EditorMonaco` plugin configuration.
`EditorMonacoLanguageApiDOM` plugin configuration.

```js
EditorMonacoLanguageApiDOM({
createData: {
authToken: 'c32d8b45-92fe-44f6-8b61-42c2107dfe87',
customApiDOMWorkerPath: 'https://example.com/index.js',
},
})
});
```

**https://example.com/index.js**
Expand Down
Loading

0 comments on commit 1a2081b

Please sign in to comment.