monaco-auto-import
Easily add auto-import to the Monaco editor, with Javascript & Typescript support.
Demo
Example code
completor.imports.saveFiles
Getting started
Installing
yarn add @blitz/monaco-auto-import# or npm i @blitz/monaco-auto-import --save
Using
Initializing a new instance
Simply create a new Monaco editor instance and pass it to AutoImport
. This will register custom completion providers for Monaco's javascript
and typescript
language services.
Providing completion items
To make the auto-importer aware of a file with exports, simply call completor.imports.saveFile
.
completor.imports.saveFile
Tokenization
This package includes a built-in regexTokeniser
, which uses a simple Regex to extracts exports from Javascript / Typescript code
// [{ type: 'const', name: 'a'}, { type: 'class', name: 'Test' }] completor.imports.saveFile
API
imports.saveFile(file: File): void
Saves a file to the internal store, making it available for completion
imports.saveFiles(files: File[]): void
Bulk-saves files to the internal store from an Array of files
imports.getFile(path: string): File
Fetches a file from the internal store by it's path name (or one of it's aliases).
imports.getImports(name: string): ImportObject[]
Returns all the imports that exactly match a given string.
imports.addImport(path: string, name: string, type?: Expression): boolean
Adds an import to a given file, with an optional type
paramater. Returns true if the file existed
imports.removeImport(path: string, name: string): boolean
Removes an import from a given file. Returns true if the file existed