Skip to content

Commit

Permalink
Find All references doesn't exist for typescript plugin #14856
Browse files Browse the repository at this point in the history
Signed-off-by: Victor Rubezhny <vrubezhny@redhat.com>
  • Loading branch information
vrubezhny committed Feb 14, 2020
1 parent 8663a52 commit ea84e78
Show file tree
Hide file tree
Showing 12 changed files with 431 additions and 213 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import { CommandService } from '@theia/core/lib/common/command';
import TheiaURI from '@theia/core/lib/common/uri';
import { EditorManager } from '@theia/editor/lib/browser';
import { CodeEditorWidget } from '@theia/plugin-ext/lib/main/browser/menus/menus-contribution-handler';
import { TextDocumentShowOptions } from '@theia/plugin-ext/lib/common/plugin-api-rpc-model';
import { TextDocumentShowOptions, Location } from '@theia/plugin-ext/lib/common/plugin-api-rpc-model';
import { DocumentsMainImpl } from '@theia/plugin-ext/lib/main/browser/documents-main';
import { createUntitledResource } from '@theia/plugin-ext/lib/main/browser/editor/untitled-resource';
import { toDocumentSymbol } from '@theia/plugin-ext/lib/plugin/type-converters';
Expand All @@ -40,6 +40,7 @@ import { WorkspaceService, WorkspaceInput } from '@theia/workspace/lib/browser/w
import { DiffService } from '@theia/workspace/lib/browser/diff-service';
import { MonacoEditor } from '@theia/monaco/lib/browser/monaco-editor';
import { inject, injectable } from 'inversify';
import { Position } from '@theia/plugin-ext/lib/common/plugin-api-rpc';
import URI from 'vscode-uri';

export namespace VscodeCommands {
Expand Down Expand Up @@ -374,8 +375,36 @@ export class PluginVscodeCommandsContribution implements CommandContribution {
})
}
);

// TODO register other `vscode.execute...` commands.
// see https://github.com/microsoft/vscode/blob/master/src/vs/workbench/api/common/extHostApiCommands.ts
commands.registerCommand(
{
id: 'vscode.executeReferenceProvider'
},
{
execute: ((resource: URI, position: Position) => {
const args = {
resource: monaco.Uri.from(resource),
position: position
};
return commands.executeCommand<Location[]>('_executeReferenceProvider', args);
})
}
);
commands.registerCommand(
{
id: 'vscode.executeImplementationProvider'
},
{
execute: ((resource: URI, position: Position) => {
const args = {
resource: monaco.Uri.from(resource),
position: position
};
return commands.executeCommand<Location[]>('_executeImplementationProvider', args);
})
}
);
}

}
1 change: 0 additions & 1 deletion packages/plugin-ext/src/common/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,3 @@
export * from './plugin-protocol';
export * from './plugin-api-rpc';
export * from './plugin-ext-api-contribution';
export * from './known-commands';
2 changes: 2 additions & 0 deletions packages/plugin-ext/src/common/plugin-api-rpc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -514,6 +514,8 @@ export interface TreeViewsMain {
$unregisterTreeDataProvider(treeViewId: string): void;
$refresh(treeViewId: string): void;
$reveal(treeViewId: string, treeItemId: string): Promise<any>;
$setMessage(treeViewId: string, message: string): void;
$setTitle(treeViewId: string, title: string): void;
}

export interface TreeViewsExt {
Expand Down
13 changes: 13 additions & 0 deletions packages/plugin-ext/src/main/browser/view/plugin-view-registry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,19 @@ export class PluginViewRegistry implements FrontendApplicationContribution {
}
}
}));

toDispose.push(this.commands.registerCommand({
id: `${view.id}.focus`,
label: `Focus ${view.name} View`
}, {
execute: async () => {
const widget = await this.openView(view.id);
if (widget) {
this.shell.activateWidget(widget.id);
}
}
}));

return toDispose;
}

Expand Down
20 changes: 20 additions & 0 deletions packages/plugin-ext/src/main/browser/view/tree-view-widget.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -372,4 +372,24 @@ export class TreeViewWidget extends TreeWidget {
}
}
}

protected render(): React.ReactNode {
return React.createElement('div', this.createContainerAttributes(), this.renderTreeInfo(), this.renderTree(this.model));
}

private _message: string | undefined;
get message(): string | undefined {
return this._message;
}

set message(message: string | undefined) {
this._message = message;
this.update();
}

protected renderTreeInfo(): React.ReactNode {
if (this._message) {
return <div className='search-info'>{this._message}</div>;
}
}
}
22 changes: 22 additions & 0 deletions packages/plugin-ext/src/main/browser/view/tree-views-main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,28 @@ export class TreeViewsMainImpl implements TreeViewsMain, Disposable {
}
}

async $setMessage(treeViewId: string, message: string): Promise<void> {
const viewPanel = await this.viewRegistry.getView(treeViewId);
const widget = viewPanel && viewPanel.widgets[0];

if (widget instanceof TreeViewWidget) {
widget.message = message;
} else {
console.error(`Widget not found for Tree View ID: ${treeViewId}`);
}
}

async $setTitle(treeViewId: string, title: string): Promise<void> {
const viewPanel = await this.viewRegistry.getView(treeViewId);
const widget = viewPanel && viewPanel.widgets[0];

if (widget instanceof TreeViewWidget) {
widget.message = title;
} else {
console.error(`Widget not found for Tree View ID: ${treeViewId}`);
}
}

protected handleTreeEvents(treeViewId: string, treeViewWidget: TreeViewWidget): void {
this.toDispose.push(treeViewWidget.model.onExpansionChanged(event => {
this.proxy.$setExpanded(treeViewId, event.id, event.expanded);
Expand Down
18 changes: 15 additions & 3 deletions packages/plugin-ext/src/plugin/command-registry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import { CommandRegistryExt, PLUGIN_RPC_CONTEXT as Ext, CommandRegistryMain } fr
import { RPCProtocol } from '../common/rpc-protocol';
import { Disposable } from './types-impl';
import { DisposableCollection } from '@theia/core';
import { KnownCommands } from '../common/known-commands';
import { KnownCommands } from './known-commands';

// eslint-disable-next-line @typescript-eslint/no-explicit-any
export type Handler = <T>(...args: any[]) => T | PromiseLike<T | undefined>;
Expand Down Expand Up @@ -104,8 +104,20 @@ export class CommandRegistryImpl implements CommandRegistryExt {
return this.executeLocalCommand(id, ...args);
} else if (KnownCommands.mapped(id)) {
// Using the KnownCommand exclusions, convert the commands manually
return KnownCommands.map(id, args, (mappedId: string, mappedArgs: any[] | undefined) =>
this.proxy.$executeCommand(mappedId, ...mappedArgs));
return KnownCommands.map(id, args, (mappedId: string, mappedArgs: any[] | undefined, mappedResult: KnownCommands.ConversionFunction) => {
const mr: KnownCommands.ConversionFunction = mappedResult;
return this.proxy.$executeCommand(mappedId, ...mappedArgs).then((result: any) => {
if (!Array.isArray(result) || result === undefined) {
return undefined;
}
if (!mr) {
return result;
}

return mr(result);
});
}
);
} else {
return this.proxy.$executeCommand(id, ...args);
}
Expand Down
2 changes: 1 addition & 1 deletion packages/plugin-ext/src/plugin/known-commands.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
********************************************************************************/

import * as assert from 'assert';
import { KnownCommands } from '../common/known-commands';
import { KnownCommands } from './known-commands';
import URI from 'vscode-uri';
import { Position } from './types-impl';
import { fromPosition } from './type-converters';
Expand Down
Loading

0 comments on commit ea84e78

Please sign in to comment.