Skip to content

Commit

Permalink
[plugin] support vscode.executeDocumentSymbol command.
Browse files Browse the repository at this point in the history
Signed-off-by: Sven Efftinge <sven.efftinge@typefox.io>
  • Loading branch information
svenefftinge committed Sep 29, 2019
1 parent 02c5c1d commit 8a3f2ca
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 12 deletions.
6 changes: 6 additions & 0 deletions packages/monaco/src/typings/monaco/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

declare module monaco.instantiation {
export interface IInstantiationService {
invokeFunction: (fn: any, ...args: any) => any
}
}

Expand Down Expand Up @@ -273,6 +274,10 @@ declare module monaco.editor {

declare module monaco.commands {

export const CommandsRegistry: {
getCommands(): Map<string, { id: string, handler: (...args: any) => any }>;
};

export interface ICommandEvent {
commandId: string;
}
Expand Down Expand Up @@ -514,6 +519,7 @@ declare module monaco.services {
export const codeEditorService: LazyStaticService<monaco.editor.ICodeEditorService>;
export const configurationService: LazyStaticService<IConfigurationService>;
export const resourcePropertiesService: LazyStaticService<ITextResourcePropertiesService>;
export const instantiationService: LazyStaticService<monaco.instantiation.IInstantiationService>;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,24 +14,23 @@
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
********************************************************************************/

import { injectable, inject } from 'inversify';
import { CommandContribution, CommandRegistry, Command } from '@theia/core';
import { Command, CommandContribution, CommandRegistry, ResourceProvider } from '@theia/core';
import { ApplicationShell, NavigatableWidget, open, OpenerService, Saveable } from '@theia/core/lib/browser';
import { ContextKeyService } from '@theia/core/lib/browser/context-key-service';
import { ApplicationShellMouseTracker } from '@theia/core/lib/browser/shell/application-shell-mouse-tracker';
import { CommandService } from '@theia/core/lib/common/command';
import TheiaURI from '@theia/core/lib/common/uri';
import URI from 'vscode-uri';
import { ContextKeyService } from '@theia/core/lib/browser/context-key-service';
import { DiffService } from '@theia/workspace/lib/browser/diff-service';
import { EditorManager } from '@theia/editor/lib/browser';
import { TextDocumentShowOptions } 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 { WebviewWidget } from '@theia/plugin-ext/lib/main/browser/webview/webview';
import { ApplicationShell, NavigatableWidget, OpenerService, open, Saveable } from '@theia/core/lib/browser';
import { ResourceProvider } from '@theia/core';
import { fromViewColumn, toDocumentSymbol } from '@theia/plugin-ext/lib/plugin/type-converters';
import { ViewColumn } from '@theia/plugin-ext/lib/plugin/types-impl';
import { TextDocumentShowOptions } from '@theia/plugin-ext/lib/common/plugin-api-rpc-model';
import { fromViewColumn } from '@theia/plugin-ext/lib/plugin/type-converters';
import { WorkspaceCommands } from '@theia/workspace/lib/browser';
import { createUntitledResource } from '@theia/plugin-ext/lib/main/browser/editor/untitled-resource';
import { DocumentsMainImpl } from '@theia/plugin-ext/lib/main/browser/documents-main';
import { ApplicationShellMouseTracker } from '@theia/core/lib/browser/shell/application-shell-mouse-tracker';
import { DiffService } from '@theia/workspace/lib/browser/diff-service';
import { inject, injectable } from 'inversify';
import URI from 'vscode-uri';

export namespace VscodeCommands {
export const OPEN: Command = {
Expand Down Expand Up @@ -315,6 +314,31 @@ export class PluginVscodeCommandsContribution implements CommandContribution {
* Show Opened File in New Window workbench.action.files.showOpenedFileInNewWindow
* Compare Opened File With workbench.files.action.compareFileWith
*/

// Register built-in language service commands
// see https://code.visualstudio.com/api/references/commands
// see https://github.com/microsoft/vscode/blob/master/src/vs/workbench/api/common/extHostApiCommands.ts
// tslint:disable: no-any
const instantiationService = monaco.services.StaticServices.instantiationService.get();
const monacoCommands = monaco.commands.CommandsRegistry.getCommands();
commands.registerCommand(
{
id: 'vscode.executeDocumentSymbolProvider'
},
{
execute: (resource: URI) => instantiationService.invokeFunction(
monacoCommands.get('_executeDocumentSymbolProvider')!.handler,
{ resource: monaco.Uri.parse(resource.toString()) }
).then((value: any) => {
if (!Array.isArray(value) || value === undefined) {
return undefined;
}
return value.map(loc => toDocumentSymbol(loc));
})
}
);
// TODO register other `vscode.execute...` commands.

}

private getHtml(body: String): string {
Expand Down
11 changes: 11 additions & 0 deletions packages/plugin-ext/src/plugin/type-converters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -642,6 +642,17 @@ export function fromDocumentSymbol(info: theia.DocumentSymbol): model.DocumentSy
return result;
}

export function toDocumentSymbol(symbol: model.DocumentSymbol): theia.DocumentSymbol {
return {
name: symbol.name,
detail: symbol.detail,
range: toRange(symbol.range)!,
selectionRange: toRange(symbol.selectionRange)!,
children: symbol.children ? symbol.children.map(toDocumentSymbol) : [],
kind: SymbolKind.toSymbolKind(symbol.kind)
};
}

export function toWorkspaceFolder(folder: model.WorkspaceFolder): theia.WorkspaceFolder {
return {
uri: URI.revive(folder.uri),
Expand Down

0 comments on commit 8a3f2ca

Please sign in to comment.