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 21, 2020
1 parent 6a6a673 commit a2bc6b3
Show file tree
Hide file tree
Showing 17 changed files with 743 additions and 334 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,13 @@ 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,
CallHierarchyItem,
CallHierarchyIncomingCall,
CallHierarchyOutgoingCall
} 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 +46,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 +381,68 @@ 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);
})
}
);
commands.registerCommand(
{
id: 'vscode.prepareCallHierarchy'
},
{
execute: ((resource: URI, position: Position) => {
const args = {
resource: monaco.Uri.from(resource),
position: position
};
return commands.executeCommand<CallHierarchyItem[]>('_executePrepareCallHierarchy', args);
})
}
);
commands.registerCommand(
{
id: 'vscode.provideIncomingCalls'
},
{
execute: ((item: CallHierarchyItem) =>
commands.executeCommand<CallHierarchyIncomingCall[]>('_executeProvideIncomingCalls', { item }))
}
);
commands.registerCommand(
{
id: 'vscode.provideOutgoingCalls'
},
{
execute: ((item: CallHierarchyItem) =>
commands.executeCommand<CallHierarchyOutgoingCall[]>('_executeProvideOutgoingCalls', { item }))
}
);
}

}
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';
327 changes: 0 additions & 327 deletions packages/plugin-ext/src/common/known-commands.ts

This file was deleted.

22 changes: 22 additions & 0 deletions packages/plugin-ext/src/common/plugin-api-rpc-model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -519,3 +519,25 @@ export interface CallHierarchyReference {
callerDefinition: CallHierarchyDefinition,
references: Range[]
}

export interface CallHierarchyItem {
_sessionId?: string;
_itemId?: string;

kind: SymbolKind;
name: string;
detail?: string;
uri: UriComponents;
range: Range;
selectionRange: Range;
}

export interface CallHierarchyIncomingCall {
from: CallHierarchyItem;
fromRanges: Range[];
}

export interface CallHierarchyOutgoingCall {
to: CallHierarchyItem;
fromRanges: Range[];
}
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
5 changes: 5 additions & 0 deletions packages/plugin-ext/src/main/browser/style/tree.css
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,8 @@
align-items: center;
height: 100%;
}

.theia-tree-view .theia-TreeContainer .theia-TreeViewInfo {
color: var(--theia-descriptionForeground);
margin-left: 17px;
}
17 changes: 17 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,23 @@ export class PluginViewRegistry implements FrontendApplicationContribution {
}
}
}));

toDispose.push(this.commands.registerCommand({
id: `${view.id}.focus`
}, {
execute: async () => {
const widget = await this.openView(view.id);
if (widget) {
const data = this.views.get(view.id);
if (data) {
const [containerId] = data;
const identifier = this.toViewContainerIdentifier(containerId);
this.shell.activateWidget(identifier.id);
}
}
}
}));

return toDispose;
}

Expand Down
33 changes: 33 additions & 0 deletions packages/plugin-ext/src/main/browser/view/plugin-view-widget.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import { CommandRegistry } from '@theia/core/lib/common/command';
import { ViewContextKeyService } from './view-context-key-service';
import { StatefulWidget } from '@theia/core/lib/browser/shell/shell-layout-restorer';
import { Message } from '@phosphor/messaging';
import { TreeViewWidget } from './tree-view-widget';

@injectable()
export class PluginViewWidgetIdentifier {
Expand Down Expand Up @@ -59,6 +60,7 @@ export class PluginViewWidget extends Panel implements StatefulWidget {
const widget = this.widgets[0];
if (widget) {
widget.activate();
this.updateWidgetMessage();
} else {
this.node.focus();
}
Expand All @@ -67,12 +69,14 @@ export class PluginViewWidget extends Panel implements StatefulWidget {
storeState(): PluginViewWidget.State {
return {
label: this.title.label,
message: this.message,
widgets: this.widgets
};
}

restoreState(state: PluginViewWidget.State): void {
this.title.label = state.label;
this.message = state.message;
for (const widget of state.widgets) {
this.addWidget(widget);
}
Expand All @@ -96,10 +100,39 @@ export class PluginViewWidget extends Panel implements StatefulWidget {
}
}

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

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

private updateWidgetMessage(): void {
const widget = this.widgets[0];
if (widget) {
if (widget instanceof TreeViewWidget) {
widget.message = this._message;
}
}
}

addWidget(widget: Widget): void {
super.addWidget(widget);
this.updateWidgetMessage();
}

insertWidget(index: number, widget: Widget): void {
super.insertWidget(index, widget);
this.updateWidgetMessage();
}
}
export namespace PluginViewWidget {
export interface State {
label: string
message?: string;
widgets: ReadonlyArray<Widget>
}
}
21 changes: 21 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,25 @@ export class TreeViewWidget extends TreeWidget {
}
}
}

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

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

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

protected renderSearchInfo(): React.ReactNode {
if (this._message) {
return <div className='theia-TreeViewInfo'>{this._message}</div>;
}
return undefined;
}
}
15 changes: 15 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 @@ -22,6 +22,7 @@ import { SelectableTreeNode, ExpandableTreeNode, CompositeTreeNode, WidgetManage
import { ViewContextKeyService } from './view-context-key-service';
import { Disposable, DisposableCollection } from '@theia/core';
import { TreeViewWidget, TreeViewNode } from './tree-view-widget';
import { PluginViewWidget } from './plugin-view-widget';

export class TreeViewsMainImpl implements TreeViewsMain, Disposable {

Expand Down Expand Up @@ -108,6 +109,20 @@ export class TreeViewsMainImpl implements TreeViewsMain, Disposable {
}
}

async $setMessage(treeViewId: string, message: string): Promise<void> {
const viewPanel = await this.viewRegistry.getView(treeViewId);
if (viewPanel instanceof PluginViewWidget) {
viewPanel.message = message;
}
}

async $setTitle(treeViewId: string, title: string): Promise<void> {
const viewPanel = await this.viewRegistry.getView(treeViewId);
if (viewPanel) {
viewPanel.title.label = title;
}
}

protected handleTreeEvents(treeViewId: string, treeViewWidget: TreeViewWidget): void {
this.toDispose.push(treeViewWidget.model.onExpansionChanged(event => {
this.proxy.$setExpanded(treeViewId, event.id, event.expanded);
Expand Down
17 changes: 14 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,19 @@ 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 (!result) {
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 a2bc6b3

Please sign in to comment.