# @theia/variable-resolver

> Theia - Variable Resolver Extension

Latest version **1.75.0** (published 2026-08-27) · EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0 license · 16.1K weekly downloads

## Install

```sh
npm install @theia/variable-resolver
pnpm add @theia/variable-resolver
yarn add @theia/variable-resolver
bun add @theia/variable-resolver
```

## Health

**Score 75/100 (B)** — status: active.

Positive: no vulnerabilities; has provenance; recently updated; high maintenance score; popular repo.

Warnings: no types; no esm support.

## Facts

| | |
|---|---|
| Version | 1.75.0 |
| Published | 2026-08-27 |
| First published | 2018-03-28 |
| Weekly downloads | 16.1K |
| License | EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0 |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 2 |
| Unpacked size | 136 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Provenance | attested (GitHub Actions) |
| GitHub stars | 21695 |
| Maintainers | eclipsetheia, vince-fugnitto, bhufmann, marc.dumais, paul-marechal, msujew, tsmaeder, jfaltermeier, jhelming, eclipse-theia-bot, sgraband, ndoschek |
| Keywords | theia-extension |

## Links

- npm: https://www.npmjs.com/package/@theia/variable-resolver
- Repository: https://github.com/eclipse-theia/theia
- Issues: https://github.com/eclipse-theia/theia/issues
- npm.io page: https://npm.io/package/@theia/variable-resolver

## Dependencies (2)

- [tslib](https://npm.io/package/tslib.md) ^2.8.1
- [@theia/core](https://npm.io/package/@theia/core.md) 1.75.0

## Recent versions

- 1.75.0 (latest) — 2026-08-27
- 1.76.0-next.28 (next) — 2026-09-16
- 1.64.4 (patch) — 2025-10-10
- 0.4.0-testnext.d1b1bc8c (testnext) — 2019-01-22
- 1.76.0-next.23 — 2026-09-15
- 1.76.0-next.18 — 2026-09-14
- 1.76.0-next.16 — 2026-09-11
- 1.76.0-next.14 — 2026-09-10
- 1.76.0-next.10 — 2026-09-09
- 1.76.0-next.7 — 2026-09-08
- 1.76.0-next.6 — 2026-09-04
- 1.76.0-next.4 — 2026-09-03
- 1.76.0-next.0 — 2026-08-28
- 1.75.0-next.46 — 2026-08-27
- 1.75.0-next.43 — 2026-08-26
- … 3200 more at https://npm.io/package/@theia/variable-resolver/versions

## README

<div align='center'>

<br />

<img src='https://raw.githubusercontent.com/eclipse-theia/theia/master/logo/theia.svg?sanitize=true' alt='theia-ext-logo' width='100px' />

<h2>ECLIPSE THEIA - VARIABLE-RESOLVER EXTENSION</h2>

<hr />

</div>

## Description

The `@theia/variable-resolved` extension provides variable substitution mechanism inside of strings using `${variableName}` syntax.

### Variable Contribution Point

Extension provides a hook that allows any extensions to contribute its own variables.
Here's the example of contributing two variables:

- `${file}` - returns the name of the file opened in the current editor
- `${lineNumber}` - returns the current line number in the current file

```typescript
@injectable()
export class EditorVariableContribution implements VariableContribution {

    constructor(
        @inject(EditorManager) protected readonly editorManager: EditorManager
    ) { }

    registerVariables(variables: VariableRegistry): void {
        variables.registerVariable({
            name: 'file',
            description: 'The name of the file opened in the current editor',
            resolve: () => {
                const currentEditor = this.getCurrentEditor();
                if (currentEditor) {
                    return currentEditor.uri.displayName;
                }
                return undefined;
            }
        });
        variables.registerVariable({
            name: 'lineNumber',
            description: 'The current line number in the current file',
            resolve: () => {
                const currentEditor = this.getCurrentEditor();
                if (currentEditor) {
                    return `${currentEditor.cursor.line + 1}`;
                }
                return undefined;
            }
        });
    }

    protected getCurrentEditor(): TextEditor | undefined {
        const currentEditor = this.editorManager.currentEditor;
        if (currentEditor) {
            return currentEditor.editor;
        }
        return undefined;
    }
}
```

Note that a Variable is resolved to `MaybePromise<string | undefined>` which means that it can be resolved synchronously or within a Promise.

### Using the Variable Resolver Service

There's the example of how one can use Variable Resolver Service in its own plugin:

```typescript
@injectable()
export class MyService {

    constructor(
        @inject(VariableResolverService) protected readonly variableResolver: VariableResolverService
    ) { }

    async resolve(): Promise<void> {
        const text = 'cursor is in file ${file} on line ${lineNumber}';
        const resolved = await this.variableResolver.resolve(text);
        console.log(resolved);
    }
}
```

If `package.json` file is currently opened and cursor is on line 5 then the following output will be logged to the console:

```sh
cursor is in file package.json on line 5
```

## Additional Information

- [API documentation for `@theia/variable-resolver`](https://eclipse-theia.github.io/theia/docs/next/modules/_theia_variable-resolver.html)
- [Theia - GitHub](https://github.com/eclipse-theia/theia)
- [Theia - Website](https://theia-ide.org/)

## License

- [Eclipse Public License 2.0](http://www.eclipse.org/legal/epl-2.0/)
- [一 (Secondary) GNU General Public License, version 2 with the GNU Classpath Exception](https://projects.eclipse.org/license/secondary-gpl-2.0-cp)

## Trademark

"Theia" is a trademark of the Eclipse Foundation
<https://www.eclipse.org/theia>

---
_Source: https://npm.io/package/@theia/variable-resolver · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
