How to set file/folder selection in workspace

Hi All,

Is there a way, I can select a folder in the workspace programmatically

I tried this.selectionService.selection=new URL(/file/path/in/workspace);

But this didn’t highlight the tree node representing the folder in the workspace navigator view.


@chakraborty-slx thank you for the discussion, you can use the tree-model to select a node:

You can look at how it is used across the framework, most notably the navigator/explorer.

1 Like

I have the following class,

import {SelectableTreeNode, TreeModel} from ‘@theia/core/lib/browser’;

export class HomeViewService {
@inject(TreeModel) readonly model: TreeModel;
private readonly backendService: BackendService;
protected readonly commandRegistry: CommandRegistry;

async createNewProject(projectMessage: ProjectMessage) {

    //create new project
    await this.backendService.createNewProject(projectMessage);
    const projectURI = new URI(projectMessage.destination + Path.separator +;

    //select the project in navigator
    const targetNode = this.model.getNode(projectURI.path.toString());
    if (targetNode && {



I am getting the following error:

planner.ts:113 Uncaught (in promise) Error: No matching bindings found for serviceIdentifier: Symbol(TreeModel)
at _validateActiveBindingCount (planner.ts:113)
at _getActiveBindings (planner.ts:91)
at _createSubRequests (planner.ts:163)
at planner.ts:197
at Array.forEach ()
at planner.ts:196
at Array.forEach ()
at _createSubRequests (planner.ts:167)
at planner.ts:197
at Array.forEach ()

Do i need to add something like this


@chakraborty-slx it looks like an error with your injections, from what I can tell the tree-model is only accessible in trees (constructor).

Thanks @vince-fugnitto, i think you are right, but is there any other way to do selection on FileNavigatorWidget, from outside the view?

@chakraborty-slx you can get an instance of the FileNavigatorTree (ex: through the ApplicationShell), and will have access to the tree’s model (from which you can perform selections).

The following is an example on how I was able to select the first node in a standard workspace (for a simple POC):

import { injectable, inject } from '@theia/core/shared/inversify';
import { CommandContribution, CommandRegistry } from '@theia/core/lib/common';
import { ApplicationShell } from '@theia/core/lib/browser/shell/application-shell';
import { FileNavigatorWidget, FILE_NAVIGATOR_ID } from '@theia/navigator/lib/browser/navigator-widget';
import { SelectableTreeNode } from '@theia/core/lib/browser';
import { WorkspaceNode } from '@theia/navigator/lib/browser/navigator-tree';

export const SelectNavigatorCommand = {
    id: '',
    category: 'Navigator',
    label: 'Select First Child'

export class TheiaSelectNavCommandContribution implements CommandContribution {

    protected readonly shell: ApplicationShell;

    registerCommands(registry: CommandRegistry): void {
        registry.registerCommand(SelectNavigatorCommand, {
            execute: () => {
                const widget = as FileNavigatorWidget | undefined;
                if (!widget) {

                if ( {
                    const rootNodes = widget.model.root.children;
                    for (const root of rootNodes) {
                        const children = root.children;
                        if ([0])) {
1 Like

Thanks, a lot @vince-fugnitto this solution works.