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

Allow for no-results message in editor.action.goToLocations-command #95308

Closed
jdneo opened this issue Apr 15, 2020 · 14 comments
Closed

Allow for no-results message in editor.action.goToLocations-command #95308

jdneo opened this issue Apr 15, 2020 · 14 comments
Assignees
Labels
editor-hover Editor mouse hover feature-request Request for new features or functionality on-release-notes Issue/pull request mentioned in release notes polish Cleanup and polish issue verification-needed Verification of issue is requested verified Verification succeeded
Milestone

Comments

@jdneo
Copy link
Member

jdneo commented Apr 15, 2020

Is it possible to add the API to show the editor message?

The use case could be:

A extension registered a command in the context menu, and the user clicks on it. After the execution, show a editor message to provide some result hint.

image

@jrieken
Copy link
Member

jrieken commented Jun 15, 2020

@jdneo Is this a problem that occurs when using editor.action.peekLocations but not having a result? I am not a fan of exposing the in-editor-message widget but I can easily tweak the command so that can show a message

@jdneo
Copy link
Member Author

jdneo commented Jun 15, 2020

Thank you @jrieken!

In Java, we have a feature called go to super implementation (navigate to the implementation in the super type). Our current behavior is try to resolve it on hover, if it has a super implementation, then show the button in the hover information:
Screen Shot 2020-06-15 at 7 23 50 PM

To better expose the feature, we hope to add it into the context menu as well. Something like this: demo

So we hope we can get the same experience when there is no result for this navigation, show the editor message, just like what VS Code has for go to definition, go to reference...

@jrieken
Copy link
Member

jrieken commented Jun 15, 2020

Great. Than let's do this. The Java extension will call the editor.action.goToLocations command when it has its results and I will make sure it shows a message when called without results, e.g support an argument with a custom no result message

@jdneo
Copy link
Member Author

jdneo commented Jun 15, 2020

@jrieken Pretty cool! That works for us!

Thank you!

@jrieken
Copy link
Member

jrieken commented Jun 15, 2020

Alright, I'll try to get something in for tomorrow

@jrieken
Copy link
Member

jrieken commented Jun 15, 2020

I have pushed those changes, this is how you call the api command

return vscode.commands.executeCommand(
	'editor.action.goToLocations',
	vscode.window.activeTextEditor.document.uri, // anchor uri and position
	vscode.window.activeTextEditor.selection.start,
	[], // results (vscode.Location[])
	'goto', // mode
	'No Foo Found' // <- message
);

The command is a bit more powerful than what "go to super" needs, e.g it can handle multiple results etc, just like "Go to References" etc. Still, with the snippet above you should be able to get what you need and be as close as possible to our native experience.

@jrieken jrieken changed the title Is it possible to provide the API to show the editor message? Allow for no-results message in editor.action.goToLocations-command Jun 15, 2020
@jrieken jrieken added polish Cleanup and polish issue and removed api labels Jun 15, 2020
@jrieken jrieken closed this as completed Jun 15, 2020
@jdneo
Copy link
Member Author

jdneo commented Jun 22, 2020

Working like a charm!

image

@jrieken jrieken added verification-needed Verification of issue is requested verified Verification succeeded labels Jul 1, 2020
@jrieken
Copy link
Member

jrieken commented Jul 1, 2020

Adding verified based on the previous comment

@jrieken jrieken added the on-release-notes Issue/pull request mentioned in release notes label Jul 3, 2020
@jdneo
Copy link
Member Author

jdneo commented Jul 10, 2020

Hi @jrieken,

one more question: The API works fine when the location array is empty. Today I tried to add a location into it:

return commands.executeCommand(
    'editor.action.goToLocations',
    window.activeTextEditor.document.uri,
    window.activeTextEditor.selection.active,
    [targetLocation],
    'goto',
    'No super implementation found'
);

where the targetLocation is an object containing uri & range:

targetLocation = {
    uri: ...,
    range: ...,
};

Then I got an error: Unable to open 'Person.java': Invalid arguments.

Is that anything I missed here?

Thanks


Update:

Seems the range needs to be defined as:

range: {
	startLineNumber: xx,
	startColumn: xx,
	endLineNumber: xx,
	endColumn: xx,
}

which is different from the type defined in vscode.Range

@jrieken Does that mean we should still use the API window.window.showTextDocument() to do the navigation?

@jrieken
Copy link
Member

jrieken commented Jul 13, 2020

where the targetLocation is an object containing uri & range:

The range must be an instance of vscode.Range otherwise this won't work. Can you confirm it is like that, e.g no lookalike type but the real thing?

@jdneo
Copy link
Member Author

jdneo commented Jul 13, 2020

@jrieken

I tried to get a Range using the constructor, and failed to go to the target location.

targetLocation = {
    uri: Uri.parse(superImpl.uri),
    range: new Range(new Position(0, 0), new Position(0, 0)),
};

@jrieken
Copy link
Member

jrieken commented Jul 13, 2020

Yeah, I see it now. There is something wrong

@jrieken
Copy link
Member

jrieken commented Jul 13, 2020

Sorry, what must be is that the result array should be instances of vscode.Location-types. When calling commands we have special logic to check for that type which then turns it into the corresponding objects on the client side

@jdneo
Copy link
Member Author

jdneo commented Jul 13, 2020

@jrieken Thank you! I should try to use the constructor of Location... 😃

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
editor-hover Editor mouse hover feature-request Request for new features or functionality on-release-notes Issue/pull request mentioned in release notes polish Cleanup and polish issue verification-needed Verification of issue is requested verified Verification succeeded
Projects
None yet
Development

No branches or pull requests

3 participants