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

Find All references doesn't exist for typescript plugin #14856 #7055

Merged
merged 1 commit into from
Mar 3, 2020

Conversation

vrubezhny
Copy link
Contributor

Signed-off-by: Victor Rubezhny vrubezhny@redhat.com

What it does

The fix adds the required API and fixes required to make possible to run VSCode Reference View extension plug-in on Theia.

et14856

How to test

Tested manually using references-view-0.0.47 (https://github.com/microsoft/vscode-references-view) downloaded into plugins/ Theia folder,

Review checklist

  • [*] as an author, I have thoroughly tested my changes and carefully followed the review guidelines
  • Check that VSCode Reference View is loaded and shown in Theia Plugins View
  • Test by executing Find All References context menu action and revisiting the result tree of the References View
  • Test by executing Find All Implementations context menu action and revisiting the result tree of the References View

Reminder for reviewers

@akosyakov akosyakov added typescript issues related to the typescript language vscode issues related to VSCode compatibility labels Feb 4, 2020
@akosyakov
Copy link
Member

akosyakov commented Feb 4, 2020

I can have a look but later this week. If someone else can test and review it would help. That's cool btw :)

Tree styling on the screenshot looks bad.

Copy link
Contributor

@tsmaeder tsmaeder left a comment

Choose a reason for hiding this comment

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

Looks good in general, but I have a couple of suggestions/questions

packages/plugin-ext/src/common/index.ts Outdated Show resolved Hide resolved
@@ -108,6 +108,23 @@ export class TreeViewsMainImpl implements TreeViewsMain, Disposable {
}
}

async $setMessage(treeViewId: string, message: string): Promise<void> {
this.viewRegistry.getView(treeViewId).then(viewPanel => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we need some error handling here? What if the tree view does not exist?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not sure if we can do anything here (with $setMessage or $setTitle) in case of tree view doesn't exist. Add an error record to Log?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, this indicates something is wrong, needs to got to the log even if we can't handle it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

When I try to print an error by console.error(...) TSLint says: Calls to 'console.error' are not allowed. (no-console)tslint(1).
What is the correct way o report an error here?

mappings['goToNextReference'] = ['goToNextReference', MONACO_CONVERSION_IDENTITY];
mappings['goToPreviousReference'] = ['goToPreviousReference', MONACO_CONVERSION_IDENTITY];
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const VSCODE_CONVERSION_IDENTITY = (args: any[] | undefined) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Also, this is not an identity, it changes stuff. Needs a better name.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Renamed

if (!thing) {
return false;
}
return ('startLineNumber' in thing) && ('startColumn' in thing) &&
Copy link
Contributor

Choose a reason for hiding this comment

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

Shouldn't we be checking the types are correct?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

How? I use these methods (isModelLocation(), isModelRange() and isUriComponents()) in result conversion in order to detect if I can convert an object into a theia.Location, theia.Range etc. Here I have a json-like object with properties. No type nor type name available...

Copy link
Contributor

Choose a reason for hiding this comment

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

still, doesn't startLineNumber have to be of type number?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

added checks for property types

packages/plugin-ext/src/plugin/types-impl.ts Outdated Show resolved Hide resolved
packages/plugin-ext/src/plugin/types-impl.ts Outdated Show resolved Hide resolved
@@ -390,7 +411,8 @@ export class Range {
return new Range(start, end);
}

static isRange(thing: {}): thing is theia.Range {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
static isRange(thing: any): thing is theia.Range {
Copy link
Contributor

Choose a reason for hiding this comment

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

Why is this change necessary?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The same reason: to make this class to be defined exactly as it's done in VS Code. Probably it's not necessary change.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I can rollback the changes in types-impl.ts as they aren't necessary and do not bring any fixes/improvements regarding this issue. Rolledback in fixup

@tsmaeder
Copy link
Contributor

tsmaeder commented Feb 6, 2020

I built your branch and added the references extension from the marketplace. I noticed the following problems:
image

  1. The View has no icon in the view sidebar
  2. the search term ("CallHierarchyCommands") is not highlighted
  3. The icon is not the typescript file icon, but a "folder" icon.
  4. There is a line break in the rendering of the file entry ("callhierarchy-contribution.ts\npackages...")
  5. The message "4 results in 1 file is not indented, which looks weird.
  6. When I do "Show All References" from the context menu in an editor, the references view does not open, I need to go through the menu bar "view" menu.

@vince-fugnitto
Copy link
Member

  1. The View has no icon in the view sidebar

For that specific issue, there is a bug tracking icons which are not rendered in Electron: #7040

@akosyakov
Copy link
Member

There is a line break in the rendereing of the file entry ("callhierarchy-contribution.ts\npackages...")

It is a regression: #7109

@vrubezhny
Copy link
Contributor Author

I've uploaded a new version of PR. Most of requests to change were reworked, but not all. For example, #7055 (comment) - to improve KnownCommands.map()...
Also, I found that I still have problem to show a search message on very first run of 'Find References/Implementations' - the message isn't shown... Looking into why this happens.
But still, please, review

@vrubezhny
Copy link
Contributor Author

vrubezhny commented Feb 14, 2020

I've pushed a new version of PR:

  • Fixed very first command invocation search message problem: now the search message is displayed correctly on the first run
  • Added check for type when converting from model.* to types.* for Location, Range and UriComponents
  • An error is reported to console in $setTitle and $setMessage API in case of Tree Widget cannot be found

@tsmaeder Please review.


if (widget instanceof TreeViewWidget) {
widget.message = message;
} else {
Copy link
Member

Choose a reason for hiding this comment

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

i'm not sure about logging errors in else cases, other methods don't do it. It could be that message is resolved by the time when a user already closed the tree, there is nothing bogus to ignore message then.

Copy link
Contributor Author

@vrubezhny vrubezhny Feb 14, 2020

Choose a reason for hiding this comment

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

It was requested by @tsmaeder. I also think the logging is not needed here.
During the run this error appears several times, while not always indicate a real problem with absent widget.
It was discussed here: #7055 (comment)

Copy link
Contributor

Choose a reason for hiding this comment

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

So what we're trying to guard here is the widget being present, not that it might be there but not a TreeWidget? Then why not do a if (widget) It has the same effect, but IMO would be better express the meaning.

Copy link
Member

@akosyakov akosyakov Feb 20, 2020

Choose a reason for hiding this comment

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

If we do like here #7055 (comment) then we should log error if only metadata is missing completely (such view is not registered). The same for title.

import { cloneAndChange } from './objects';
import { Position, Range, Location } from '../plugin/types-impl';
import { fromPosition, fromRange, fromLocation } from '../plugin/type-converters';
import { cloneAndChange } from '../common/objects';
Copy link
Member

Choose a reason for hiding this comment

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

Could someone elaborate except moving this file and renaming things what was fixes in this file? It is used for all commands triggered by the plugin host process would be bad to break it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

For vscode.executeReferenceProvider and vscode.executeImplementationProvider, as they return location array as result, it is required to convert the result from model.* objects to theia.* objects in order to be accepted by VSCode Reference View plugin.
So, optional property is added to the mapping to specify the converter function that is to be used to convert the results. As it is optional, there is no need to add this property to all the other existing mappings. Currently, CONVERT_MONACO_TO_VSCODE is added to convert the results array into an array of theia.Location objects. It's used to convert the results of vscode.executeReferenceProvider and vscode.executeImplementationProvider command execution.
The only change for the old mappings is that MONACO_CONVERSION_IDENTITY function used for arguments conversion is renamed to CONVERT_VSCODE_TO_MONACO (in order to indicate the fact that it really changes arguments - requested by @tsmaeder )

Copy link
Contributor

Choose a reason for hiding this comment

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

Unfortunately, the github diff algorithm is being really stupid here: there are loads of single line changes in the command definitions, but GH picks it up as a two entirely changed blocks of code 🤷‍♂

@@ -159,6 +176,10 @@ class TreeViewExtImpl<T> implements Disposable {
private readonly onDidChangeVisibilityEmitter = new Emitter<TreeViewVisibilityChangeEvent>();
readonly onDidChangeVisibility = this.onDidChangeVisibilityEmitter.event;

protected updateMessage = debounce(() => {
Copy link
Member

Choose a reason for hiding this comment

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

Why to debounce? Did you observe any performance or usability issues?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

At first invocation of Find All References or Find All Implementations command, the Reference View widget is not yet created, so I cannot set a message on it. So, when you ask for the references or implementation for the first time the references tree will be shown without that search summary message. Debouncing solves this problem.

Copy link
Contributor

Choose a reason for hiding this comment

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

No, we cannot just "do it later". The problem here is that the state of the tree view can be changed before the widget in the UI is actually created. This just means that we need to transfer the state at the time the widget is created. But this can be 5 minutes after creation of the tree view, so the debounce() is not reliable.
IMO, we have to pass message and title to TreeViewsMain#reveal(). I think that is the only way a plugin can make a tree view visible, right?

Copy link
Contributor

Choose a reason for hiding this comment

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

Note sure where to put the message when the widget is not created yet. @akosyakov any suggestions how to do that?

Copy link
Contributor

Choose a reason for hiding this comment

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

Had a discussion on Friday and will investigate what the behaviour of createTreeView should be: if it is supposed to open the widget, the set message should come afterwards and succeed.

Copy link
Contributor Author

@vrubezhny vrubezhny Feb 19, 2020

Choose a reason for hiding this comment

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

The widget creation happens in several steps and is distributed in several events and backend/frontend communications.
During this process $setMessage and $setTitle are invoked with default values message=undefined and title="Results" in order to indicate that the reference tree is empty during the search for the references (the results are not received yet) - trying to process this initial call is the reason of debounce appearance.
And it is still possible that $setMessage with a valuable message will be called before the widget is finally initialized and added to the view on the first request for references/implementations.

After the widget creation these methods are called once again with the real (not empty) values.

Copy link
Member

@akosyakov akosyakov Feb 20, 2020

Choose a reason for hiding this comment

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

I think it should be part of tree view metadata which initially loaded from package.json. When $setMessage or $setTitle are called then metadata should be updated and used during creation. If a view already present then we update it as well.

Actually for title is even stated it in js-doc:

The tree view title is initially taken from the extension package.json
Changes to the title property will be properly reflected in the UI in the title of the view.

We should respect it and make sure that initial title and message from metadata are installed properly. It does not seem to happen in the PR.

@vrubezhny
Copy link
Contributor Author

vrubezhny commented Feb 14, 2020

2. the search term ("CallHierarchyCommands") is  not highlighted

When I test it with Electron, in some cases the result items are highlighted, in other cases are not. In case such an item is not highlighted it's enough to mouse click on editor area (so the editor receives focus) - the search item immediately gets highlighted. Exactly the same happens when running Browser version.

6. When I do "Show All References" from the context menu in an editor, the references view does not open, I need to go through the menu bar "view" menu.

Yes, it is. In my case I even didn't have View->References menu item, it looks like it appeared after I tried to invoke Find All Referencess or Find All Implementations command.
But the following invocation of Find All Referencess/Find All Implementations commands, in my case, successfully opens References View (if it's not opened) even after I restarted Electron application several times.

@akosyakov
Copy link
Member

Do I get correctly that the reference widget extension already makes use of the call hierarchy API? And we can replace our call hierarchy Theia extension by using it?

@vrubezhny
Copy link
Contributor Author

vrubezhny commented Feb 21, 2020

Do I get correctly that the reference widget extension already makes use of the call hierarchy API? And we can replace our call hierarchy Theia extension by using it?

No.
Yes it uses CallHierarchy API, but I really never could make it work ]from the commands provided by the current version of the extension] on VSCode when I was testing it. The plugin's REAAD.me doesn't have any information on CallHierarchy commands... So, I suppose it either just doesn't work with typescript or there are some other limitations.

The support for vscode.prepareCallHierarchy, vscode.provideIncomingCalls and vscode.provideOutgoingCalls commands is included in order to fully support vscode-reference-view existing capabilities

@vrubezhny vrubezhny force-pushed the et14856 branch 2 times, most recently from 6cda569 to a2bc6b3 Compare February 21, 2020 13:57
@vrubezhny
Copy link
Contributor Author

The <view.id>.focus command registration is made to not have UI contributions.

@akosyakov
Copy link
Member

I have errors in logs when try to activate it with keybindings:
Screenshot 2020-02-21 at 16 22 47

@akosyakov
Copy link
Member

akosyakov commented Feb 21, 2020

There is no enough spacing around message and the color is bogus:
Screenshot 2020-02-21 at 16 23 10

And in VS Code:
Screenshot 2020-02-21 at 16 23 16

BTW what is wrong with icons, folders instead of files?

Not sure why description color is wrong as well. We need to make it look decent at least and then file issues for everything else if you don't want to address them in this PR.

@vrubezhny
Copy link
Contributor Author

There is no enough spacing around message and the color is bogus:
Screenshot 2020-02-21 at 16 23 10

And in VS Code:
Screenshot 2020-02-21 at 16 23 16

I'll fix spacing

BTW what is wrong with icons, folders instead of files?

Probably we should look into Label Provider: https://github.com/eclipse-theia/theia/blob/master/packages/core/src/browser/label-provider.ts#L203
I'd like to create a separate issue for this.

Not sure why description color is wrong as well. We need to make it look decent at least and then file issues for everything else if you don't want to address them in this PR.

What do you mean by "description color"? Is it a X results in Y files (message) on top of the tree?
As for me, the View colors in Chrome (for Browser example) and in VSCode are pretty the same (Fedora 29, Gnome):
Screenshot from 2020-02-21 22-46-51
The only that message is different (grey instead of white).
I don't have orange backgrounded words (looks like a word that was searched for) - but, imho, it's better not to have it colored on the tree side.
But I don't understand why some lines in your VSCode have orange foreground and a labeled like 9+ on the right... Is it a something in the UI specially made for MacOS?

@vrubezhny
Copy link
Contributor Author

I have errors in logs when try to activate it with keybindings:
Screenshot 2020-02-21 at 16 22 47

I don't have any errors in log when I use Alt + Shift + F12 to find references. The hotkey combination is not shown in context menu, but it still works fine for me.
What version you use to test - Browser or Electron?

@akosyakov
Copy link
Member

@vrubezhny Could you please do #7153 (comment) it will easy testing of this PR and it would be good to have this extension on master after merging.

@vrubezhny
Copy link
Contributor Author

I've updated the PR with:

package.json Outdated Show resolved Hide resolved
@akosyakov
Copy link
Member

#7055 (comment)

@vrubezhny I can reproduce it reliably for browser. Please make sure to reset the layout before that it is not opened.

Copy link
Member

@akosyakov akosyakov left a comment

Choose a reason for hiding this comment

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

Probably we should look into Label Provider: https://github.com/eclipse-theia/theia/blob/master/packages/core/src/browser/label-provider.ts#L203
I'd like to create a separate issue for this.

Ok, please create.

But I don't understand why some lines in your VSCode have orange foreground and a labeled like 9+ on the right... Is it a something in the UI specially made for MacOS?

We don't support tree item highlights VS Code API: https://github.com/vrubezhny/theia/blob/c9370d3de85b225419d7946938ac6d3ac5624a21/packages/plugin/src/theia-proposed.d.ts#L213 It would be good to file a new issue for this.

@akosyakov
Copy link
Member

It looks good except keybindings don't work for me.

@akosyakov
Copy link
Member

akosyakov commented Feb 26, 2020

@vrubezhny Don't care about keybindings. I know there is the issue and it will be fixed in: dae6865#diff-0291e1b92ff01c13c0dc1c98263ac426 Keybindings don't call command handlers properly, so the plugin system gets never notified about executed commands.

Copy link
Member

@akosyakov akosyakov left a comment

Choose a reason for hiding this comment

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

I think it is good, there are some issues but they can be resolved separately. Please take care though about color variable comment before merging.

Fixes: #14856

Signed-off-by: Victor Rubezhny <vrubezhny@redhat.com>
@akosyakov akosyakov dismissed tsmaeder’s stale review March 3, 2020 09:04

i believe all comments were addressed

@akosyakov akosyakov merged commit 5ea335c into eclipse-theia:master Mar 3, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
typescript issues related to the typescript language vscode issues related to VSCode compatibility
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants