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 f66dd74
Show file tree
Hide file tree
Showing 5 changed files with 76 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
1 change: 1 addition & 0 deletions packages/plugin-ext-vscode/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"dependencies": {
"@theia/core": "^0.11.0",
"@theia/editor": "^0.11.0",
"@theia/monaco": "^0.11.0",
"@theia/plugin": "^0.11.0",
"@theia/plugin-ext": "^0.11.0",
"@theia/workspace": "^0.11.0",
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,34 @@ 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
// tslint:disable: no-any
const instantiationService = monaco.services.StaticServices.instantiationService.get();
const monacoCommands = monaco.commands.CommandsRegistry.getCommands();
const documentSymbolProviderCommand = monacoCommands.get('_executeDocumentSymbolProvider');
if (documentSymbolProviderCommand) {
commands.registerCommand(
{
id: 'vscode.executeDocumentSymbolProvider'
},
{
execute: (resource: URI) => instantiationService.invokeFunction(
documentSymbolProviderCommand.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.
// see https://github.com/microsoft/vscode/blob/master/src/vs/workbench/api/common/extHostApiCommands.ts

}

private getHtml(body: String): string {
Expand Down
19 changes: 19 additions & 0 deletions packages/plugin-ext-vscode/src/typings/monaco/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/********************************************************************************
* Copyright (C) 2018 Red Hat, Inc. and others.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0.
*
* This Source Code may also be made available under the following Secondary
* Licenses when the conditions for such availability set forth in the Eclipse
* Public License v. 2.0 are satisfied: GNU General Public License, version 2
* with the GNU Classpath Exception which is available at
* https://www.gnu.org/software/classpath/license.html.
*
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
********************************************************************************/

/// <reference types='@theia/monaco/src/typings/monaco'/>

/* expose internal APIs in @theia/monaco/src/typings/monaco */
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 f66dd74

Please sign in to comment.