New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@theia/variable-resolver

Package Overview
Dependencies
Maintainers
11
Versions
2976
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@theia/variable-resolver

Theia - Variable Resolver Extension

  • 1.58.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
4.7K
decreased by-23.03%
Maintainers
11
Weekly downloads
 
Created
Source

theia-ext-logo

ECLIPSE THEIA - VARIABLE-RESOLVER EXTENSION


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
@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:

@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:

cursor is in file package.json on line 5

Additional Information

  • API documentation for @theia/variable-resolver
  • Theia - GitHub
  • Theia - Website

License

Trademark

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

Theia - Variable Resolver Extension

The extension

License

Keywords

FAQs

Package last updated on 03 Feb 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc