Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support for experimental evaluatable expressions #167

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions src/extension.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { LanguageClient, ServerOptions, LanguageClientOptions, StreamInfo } from 'vscode-languageclient'
import { EvaluatableExpressionRequest } from './protocol'

import * as vscode from 'vscode'
import { join } from 'path'
Expand Down Expand Up @@ -50,6 +51,29 @@ export function activate(context: vscode.ExtensionContext): void {

languageClient = createClient(config)
languageClient.start()

context.subscriptions.push(
vscode.languages.registerEvaluatableExpressionProvider('php', {
async provideEvaluatableExpression(
document: vscode.TextDocument,
position: vscode.Position,
token: vscode.CancellationToken
): Promise<vscode.EvaluatableExpression | undefined> {
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
if (languageClient.initializeResult?.capabilities.experimental?.xevaluatableExpressionProvider) {
const eer = await languageClient.sendRequest(
EvaluatableExpressionRequest.type,
languageClient.code2ProtocolConverter.asTextDocumentPositionParams(document, position),
token
)
if (eer && eer.expression) {
return new vscode.EvaluatableExpression(eer.range, eer.expression)
}
}
return undefined
},
})
)
}

export function deactivate(): Promise<void> | undefined {
Expand Down
35 changes: 35 additions & 0 deletions src/protocol.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/* eslint @typescript-eslint/no-empty-object-type: 0 */
/* eslint @typescript-eslint/no-namespace: 0 */
import { Range } from 'vscode'
// import { Range } from 'vscode-languageserver-types'
import { ProtocolRequestType } from 'vscode-languageserver-protocol/lib/messages'
import {
TextDocumentPositionParams,
TextDocumentRegistrationOptions,
WorkDoneProgressOptions,
WorkDoneProgressParams,
} from 'vscode-languageclient'

interface EvaluatableExpression {
expression?: string
range: Range
}

export interface EvaluatableExpressionOptions extends WorkDoneProgressOptions {}

interface EvaluatableExpressionParams extends TextDocumentPositionParams, WorkDoneProgressParams {}

interface EvaluatableExpressionRegistrationOptions
extends TextDocumentRegistrationOptions,
EvaluatableExpressionOptions {}

export namespace EvaluatableExpressionRequest {
export const method = 'textDocument/xevaluatableExpression'
export const type = new ProtocolRequestType<
EvaluatableExpressionParams,
EvaluatableExpression | null,
never,
void,
EvaluatableExpressionRegistrationOptions
>(method)
}
Loading