Skip to content

Commit

Permalink
Added getDocumentSymbols call to extension API (#1151)
Browse files Browse the repository at this point in the history
Signed-off-by: Ondřej Musil <[email protected]>
  • Loading branch information
Ondrej Musil authored and fbricon committed Nov 22, 2019
1 parent 368ca0f commit 84f4522
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 4 deletions.
23 changes: 23 additions & 0 deletions src/documentSymbols.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
'use strict';

import {
CancellationToken,
DocumentSymbol,
DocumentSymbolParams,
DocumentSymbolRequest,
LanguageClient,
SymbolInformation
} from "vscode-languageclient";

type DocumentSymbolsResponse = DocumentSymbol[] | SymbolInformation[] | null;

export type getDocumentSymbolsCommand = (params: DocumentSymbolParams, token?: CancellationToken) => Promise<DocumentSymbolsResponse>;

export function getDocumentSymbolsProvider(languageClient: LanguageClient): getDocumentSymbolsCommand {
return async (params: DocumentSymbolParams, token?: CancellationToken): Promise<DocumentSymbolsResponse> => {
if (token !== undefined) {
return languageClient.sendRequest(DocumentSymbolRequest.type, params, token);
}
return languageClient.sendRequest(DocumentSymbolRequest.type, params);
};
}
4 changes: 4 additions & 0 deletions src/extension.api.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
import { getDocumentSymbolsCommand } from './documentSymbols';
import { RequirementsData } from './requirements';
import { TextDocumentPositionParams } from 'vscode-languageclient';
import { CancellationToken, Command, ProviderResult } from 'vscode';

export type provideHoverCommandFn = (params: TextDocumentPositionParams, token: CancellationToken) => ProviderResult<Command[] | undefined>;
export type registerHoverCommand = (callback: provideHoverCommandFn) => void;

export const ExtensionApiVersion = '0.3';

export interface ExtensionAPI {
readonly apiVersion: string;
readonly javaRequirement: RequirementsData;
readonly status: "Started" | "Error";
readonly registerHoverCommand: registerHoverCommand;
readonly getDocumentSymbols: getDocumentSymbolsCommand;
}
10 changes: 7 additions & 3 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,14 @@ import { workspace, extensions, ExtensionContext, window, StatusBarAlignment, co
import { ExecuteCommandParams, ExecuteCommandRequest, LanguageClient, LanguageClientOptions, RevealOutputChannelOn, Position as LSPosition, Location as LSLocation, StreamInfo, VersionedTextDocumentIdentifier, ErrorHandler, Message, ErrorAction, CloseAction, InitializationFailedHandler } from 'vscode-languageclient';
import { onExtensionChange, collectJavaExtensions } from './plugin';
import { prepareExecutable, awaitServerConnection } from './javaServerStarter';
import { getDocumentSymbolsCommand, getDocumentSymbolsProvider } from './documentSymbols';
import * as requirements from './requirements';
import { Commands } from './commands';
import {
StatusNotification, ClassFileContentsRequest, ProjectConfigurationUpdateRequest, MessageType, ActionableNotification, FeatureStatus, CompileWorkspaceRequest, CompileWorkspaceStatus, ProgressReportNotification, ExecuteClientCommandRequest, SendNotificationRequest,
SourceAttachmentRequest, SourceAttachmentResult, SourceAttachmentAttribute
} from './protocol';
import { ExtensionAPI } from './extension.api';
import { ExtensionAPI, ExtensionApiVersion } from './extension.api';
import * as buildpath from './buildpath';
import * as hoverAction from './hoverAction';
import * as sourceAction from './sourceAction';
Expand Down Expand Up @@ -207,6 +208,7 @@ export function activate(context: ExtensionContext): Promise<ExtensionAPI> {
languageClient = new LanguageClient('java', extensionName, serverOptions, clientOptions);
languageClient.registerProposedFeatures();
const registerHoverCommand = hoverAction.registerClientHoverProvider(languageClient, context);
const getDocumentSymbols: getDocumentSymbolsCommand = getDocumentSymbolsProvider(languageClient);

languageClient.onReady().then(() => {
languageClient.onNotification(StatusNotification.type, (report) => {
Expand All @@ -217,10 +219,11 @@ export function activate(context: ExtensionContext): Promise<ExtensionAPI> {
lastStatus = item.text;
commands.executeCommand('setContext', 'javaLSReady', true);
resolve({
apiVersion: '0.2',
apiVersion: ExtensionApiVersion,
javaRequirement: requirements,
status: report.type,
registerHoverCommand,
getDocumentSymbols
});
break;
case 'Error':
Expand All @@ -229,10 +232,11 @@ export function activate(context: ExtensionContext): Promise<ExtensionAPI> {
p.report({ message: 'Finished with Error' });
toggleItem(window.activeTextEditor, item);
resolve({
apiVersion: '0.2',
apiVersion: ExtensionApiVersion,
javaRequirement: requirements,
status: report.type,
registerHoverCommand,
getDocumentSymbols
});
break;
case 'Starting':
Expand Down
14 changes: 13 additions & 1 deletion src/protocol.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,18 @@
'use strict';

import { RequestType, NotificationType, TextDocumentIdentifier, ExecuteCommandParams, CodeActionParams, WorkspaceEdit, FormattingOptions, WorkspaceSymbolParams, SymbolInformation, TextDocumentPositionParams, Location } from 'vscode-languageclient';
import {
CodeActionParams,
ExecuteCommandParams,
FormattingOptions,
Location,
NotificationType,
RequestType,
SymbolInformation,
TextDocumentIdentifier,
TextDocumentPositionParams,
WorkspaceEdit,
WorkspaceSymbolParams,
} from 'vscode-languageclient';
import { Command, Range } from 'vscode';

/**
Expand Down

0 comments on commit 84f4522

Please sign in to comment.