How to get current chosen file uri in new extension?

I try to run a compile command for current chosen file in theia.
For example, when i choose(click) the file test.c in the frontend of theia, and click one button, it should automatically open a new terminal and run “gcc test.c -o test”.
Now, i can realize a button that can open terminal and run fixed command. But i have no idea how to get uri of current chosen file.
Thanks a lot!

@RichardZeyu from the EditorManager you can retrieve the currentEditor which exposes the underlying TextEditor which has the uri.

You can also make use of UriAwareCommandHandler to support a command in different context, i.e. when an editor selected or preview or a file in the navigator.

1 Like

it works, thanks a lot for all you two!

1 Like

Hello Richard, i have the similar needs, could you please tell me how to open a terminal and run commands?

You should use TerminalFrontendContribution to open a terminal and then call sendCommand on it.