How to expand FileNode in Navigator view

in my commandContribution has a command like that(I copy from workspace-command.ts)

registry.registerCommand(MyCommands.NEW_PROJECT, this.newWorkspaceRootUriAwareCommandHandler({
            execute: uri => this.getDirectory(uri).then(parent => {
                if (parent) {
                    const parentUri = parent.resource;
                    const { fileName, fileExtension } = this.getDefaultFileConfig();
                    const vacantChildUri = FileSystemUtils.generateUniqueResourceURI(parentUri, parent, fileName, fileExtension);
                    const dialog = new WorkspaceInputDialog({
                        title: 'New Project',
                        parentUri: parentUri,
                        initialValue: vacantChildUri.path.base,
                        validate: name => this.validateFileName(name, parent, true)
                    }, this.labelProvider);

                    dialog.open().then(async name => {
                        if (name) {
                            const fileUri = parentUri.resolve(name);

                             **await this.fileService.create(fileUri);**//
                                await this.mySerrvice.createProject(projectName)// this method will create a folder and a file(test.c)
                             // this.fireCreateNewFile({ parent: parentUri, uri: fileUri });
                            open(this.openerService, fileUri/test.c); // it can open the test.c
                             // but this does not work 
                             const navigator = this.fileNavigatorContribution.tryGetWidget();
                             if (!navigator || !navigator.isVisible) {
                                  return;
                             }
                             const model: FileNavigatorModel = navigator.model;
                             const parent = await model.revealFile(event.parent);
                             if (DirNode.is(parent)) {
                                    await model.refresh(parent);
                             }
                             const node = await model.revealFile(event.uri);
                              if (SelectableTreeNode.is(node)) {
                                   model.selectNode(node);
                               if (DirNode.is(node)) {
                                    this.fileNavigatorContribution.openView({ activate: true });
                              }
                          }
                        }
                    });
                }
            })
        }));

This is pseudocode ,just like that, i want to create a folder,in the folder has a test.c file ,then open the test.c in editor, but in navigator view ,i can’t selection and expand the folder i just create. By Debug I sure the folder(DirNode) {expanded:true;slection:true;cursor:true} just not work. can help?

@sunchuanstc could you provide additional details about what the use-case is exactly, it is difficult to understand with the pseudocode and the current description, as well as identify what exactly is not working once the command is actually implemented.

From what I could understand you want to:

  1. open an input dialog to choose a workspace name
  2. create the workspace folder along with the test file
  3. open the explorer and select the test file

Am I correct?

An issue I can see initially is where on the filesystem will this folder actually be created as the newWorkspaceRootUriAwareCommandHandler uses a selection to determine the URI from which to create the folder (since I see it is from new file the code is copied from).

@vince-fugnitto sorry, now this is the read code:

> class MyCommandContribution implements CommandContribution{
>          @inject(FileNavigatorWidget) protected readonly fileNavigatorWidget:FileNavigatorWidget;
>          @inject(FileNavigatorContribution) protected readonly fileNavigatorContribution:FileNavigatorContribution;
>           .......         
>           .......
>           commands.registerCommand(MyCommands.NEW_CPROJECT,new WorkspaceRootUriAwareCommandHandler(this.workspaceService,this.selectionService,{
>            execute:async(uri)=>{
>                   const rooturi = this.workspaceService.getWorkspaceRootUri(uri);
>                   if(rooturi){
>                          let parent = await this.fileService.resolve(rooturi);
>                          const parenturi = parent.resource;
>                          const dialog = new WorkspaceInputDialog(.........);
>                          dialog.open().then(async name=>{
>                                  if(name){
>                                       const folderuri = parenturi.resolve(name);
>                                       await this.myService.createProject(folderuri );// in backend it will create a folder and a file name test.c;
>                                       open(this.openerService,parenturi.resolve(`${name}/test.c`)); // it will open test.c in edtior;
>                                       //the under code i want to expand the folder i just create and select the test.c,but it does not work,anywhere i was wrong?
>                                       const navigator = this.fileNavigatorContribution.tryGetWidget();
>                                       if(!navigator  || !navigator .isVisiable){
>                                           return;
>                                      }
>                                      const fileNavigatorModel = this.fileNavigatorWidget.mode;
>                                      await fileNavigatorModel.refresh();
>                                      let node = fileNavigatorModel.getNodesByUri(folderUri).next().value;
>                                      if(DirNode.is(node)){
>                                            if(SelectableTreeNode.is(node)){
>                                                    fileNavigatorModel.selectNode(node);
>                                                    fileNavigatorModel.expandNode(node);
>                                                    this.fileNavigatorContribution.openView({active:true});
>                                            }
>                                      }
>                                      
>                                 }
>                          });
>                   }
> 
>            }
> }));
> 
> }

@vince-fugnitto i exec my command then in navigator display like that

but i want to display like this

so this is my wondering, why the code does not work

@vince-fugnitto Hi,I have solved the problem through extends WorkspaceCommandContribution; and then call this.fireCreateNewFile(…); my doubts is that, why my code does not work? I want to know how it works,can you give me some hint? Thx…