Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

register vscode.openWith api #9881

Merged
merged 4 commits into from
Sep 9, 2021

Conversation

amos42
Copy link
Contributor

@amos42 amos42 commented Aug 11, 2021

register vscode.openWith api

What it does

Fixes #9865

Register vscode.openWith api

VSCode provides both 'open' and 'openWith' commands.
However, theia does not provide the 'openWith' command.
The 'open' command is a command that automatically finds and opens an editor that matches the 'resource' parameter.
'openWith' allows us to directly designate the editor we want and open it.

How to test

You can create a VSCode plugin and test it using the following code.

vscode.window.registerCustomEditorProvider('UserDefinedTyp_1', new CustomEditorProvider() ... );

.
.
.

vscode.commands.executeCommand('vscode.openWith', vscode.Uri.file(...), 'UserDefinedType_1');

Here is the code for testing.

Sample plug-ins code for test

import * as vscode from 'vscode';

class MyEditorProvider implements vscode.CustomTextEditorProvider {
	public static readonly viewTypeId = 'UserDef.MyCustomEditor';

	public static register(context: vscode.ExtensionContext): vscode.Disposable {
		const provider = new MyEditorProvider(context);
		return vscode.window.registerCustomEditorProvider(MyEditorProvider.viewTypeId, provider);
	}

	constructor(private readonly context: vscode.ExtensionContext) { }

	resolveCustomTextEditor(document: vscode.TextDocument, webviewPanel: vscode.WebviewPanel, token: vscode.CancellationToken): Thenable<void> | void {
		webviewPanel.webview.html = this.getHtmlForWebview(webviewPanel.webview, document.getText());
	}

	private getHtmlForWebview(webview: vscode.Webview, content: string): string {
		return /* html */`
			<!DOCTYPE html>
			<html lang="en">
			<body>
			<h1>Test View</h1>
			<br/>
			<pre>${content}</pre>
			</body>
			</html>`;
	}
}

export function activate(context: vscode.ExtensionContext) {
	// Register our custom editor providers
	MyEditorProvider.register(context);
	
	vscode.commands.registerCommand('user-command.openWith-test', () => {
		try {
			vscode.commands.executeCommand('vscode.openWith', vscode.Uri.file('/tmp/data/test.data'), MyEditorProvider.viewTypeId);
		} catch (e) {
			vscode.window.showErrorMessage(e);
		}
	});
}

NOTE : Before testing, you need to create a random text file and place it in /tmp/data/test.data

echo "Test Open With" > /tmp/data/test.data

Review checklist

Reminder for reviewers

@amos42 amos42 marked this pull request as draft August 11, 2021 05:14
@amos42 amos42 marked this pull request as ready for review August 11, 2021 05:15
Copy link
Member

@msujew msujew left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @amos42 and thank your for your contribution.

Please be sure to sign the eclipse contributor agreement (eca) with the same email as your authorship in order for us to accept the changes.

Also, the testing steps are quite non descriptive. However, the referenced issue mentions a perfectly viable way of testing your changes. Would you mind replacing your testing steps simply with "See #9865 for reproduction steps"?

Also, please don't modify the "Review checklist" and the "Reminder for reviewers" from the PR template. Instead, could you please reinstate them and mark the checklist as resolved using [x]?

Copy link
Member

@msujew msujew left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I noticed that the custom-editor-example provided by vscode does not correctly work with the current version of Theia, due to Theia not creating the file when executing the command. Which is quite weird, since the command does not specify to create a new file. It just creates an URI and passes this URI into the opener command.

I was able to trick Theia into displaying the editor either way. So I guess I can confirm that the changes are working correctly. How did you test your changes?

@vince-fugnitto vince-fugnitto added the vscode issues related to VSCode compatibility label Aug 12, 2021
@amos42 amos42 changed the title regist vscode.openWith api register vscode.openWith api Aug 13, 2021
Copy link
Member

@msujew msujew left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reminder that you still haven't signed the eclipse contributor agreement (eca) with the same email as your authorship in order for us to accept the changes.

@amos42
Copy link
Contributor Author

amos42 commented Aug 17, 2021

Hi @amos42 and thank your for your contribution.

Please be sure to sign the eclipse contributor agreement (eca) with the same email as your authorship in order for us to accept the changes.

Also, the testing steps are quite non descriptive. However, the referenced issue mentions a perfectly viable way of testing your changes. Would you mind replacing your testing steps simply with "See #9865 for reproduction steps"?

Also, please don't modify the "Review checklist" and the "Reminder for reviewers" from the PR template. Instead, could you please reinstate them and mark the checklist as resolved using [x]?

@amos42 amos42 closed this Aug 17, 2021
@amos42 amos42 reopened this Aug 17, 2021
@msujew
Copy link
Member

msujew commented Aug 17, 2021

@amos42 You used different emails in your commits, that's probably the reason the eca check is still failing. (once jcmh74 and amos74) The best course of action would be to simply squash all your commits and force push, as that would also remove the commits, that I "co-authored".

@amos42
Copy link
Contributor Author

amos42 commented Aug 17, 2021

@amos42 You used different emails in your commits, that's probably the reason the eca check is still failing. (once jcmh74 and amos74) The best course of action would be to simply squash all your commits and force push, as that would also remove the commits, that I "co-authored".

Ok. I will fix it according to your advice.

@amos42 amos42 force-pushed the am/regist-vscode.openWith-api branch 2 times, most recently from 54e434b to 08227d6 Compare August 18, 2021 03:28
Signed-off-by: Ju, Gyeong-min <jcmh74@gmail.com>
@amos42 amos42 force-pushed the am/regist-vscode.openWith-api branch from 08227d6 to 6632ce5 Compare August 18, 2021 03:39
@amos42
Copy link
Contributor Author

amos42 commented Aug 18, 2021

I've included a simple example in the description for reviewers.

@msujew
Copy link
Member

msujew commented Aug 18, 2021

I build a running example extension for other reviewers: download

You still need to create a file like this: echo "Test Open With" > /tmp/data/test.data and then run the Test vscode open with command.

@amos42
Copy link
Contributor Author

amos42 commented Aug 19, 2021

I build a running example extension for other reviewers: download

You still need to create a file like this: echo "Test Open With" > /tmp/data/test.data and then run the Test vscode open with command.

@msujew Thanks for your advice. added that content.

Signed-off-by: Ju, Gyeong-min <jcmh74@gmail.com>
@amos42 amos42 force-pushed the am/regist-vscode.openWith-api branch from 993e507 to 2bb2833 Compare August 27, 2021 05:31
Signed-off-by: Ju, Gyeong-min <jcmh74@gmail.com>
Signed-off-by: Ju, Gyeong-min <jcmh74@gmail.com>
Copy link
Member

@msujew msujew left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for your contribution @amos42, the changes look good to me and I can confirm that the vscode.openWith command works as expected.

@amos42
Copy link
Contributor Author

amos42 commented Sep 6, 2021

Thank you for your contribution @amos42, the changes look good to me and I can confirm that the vscode.openWith command works as expected.

@msujew Thanks for your appropriate advice. It helped me find hidden problems in my code.

@tsmaeder tsmaeder merged commit 10d5275 into eclipse-theia:master Sep 9, 2021
RomanNikitenko pushed a commit that referenced this pull request Sep 16, 2021
Signed-off-by: Ju, Gyeong-min <jcmh74@gmail.com>
RomanNikitenko pushed a commit that referenced this pull request Sep 16, 2021
Signed-off-by: Ju, Gyeong-min <jcmh74@gmail.com>
@vince-fugnitto vince-fugnitto added this to the 1.18.0 milestone Sep 30, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
vscode issues related to VSCode compatibility
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Command with id 'vscode.openWith' is not registered
4 participants