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: Add support for EvaluatableExpression #64

Merged
merged 3 commits into from
Jul 26, 2023
Merged
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
27 changes: 14 additions & 13 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 24 additions & 0 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import * as semver from 'semver'
import * as url from 'url'
import * as vscode from 'vscode'
import { LanguageClient, LanguageClientOptions, RevealOutputChannelOn, StreamInfo } from 'vscode-languageclient/node'
import { EvaluatableExpressionRequest } from './protocol'

const composerJson = require('../composer.json')

export async function activate(context: vscode.ExtensionContext): Promise<void> {
Expand Down Expand Up @@ -139,4 +141,26 @@ export async function activate(context: vscode.ExtensionContext): Promise<void>
// Push the disposable to the context's subscriptions so that the
// client can be deactivated on extension deactivation
context.subscriptions.push(disposable)

context.subscriptions.push(
vscode.languages.registerEvaluatableExpressionProvider('php', {
async provideEvaluatableExpression(
document: vscode.TextDocument,
position: vscode.Position,
token: vscode.CancellationToken
): Promise<vscode.ProviderResult<vscode.EvaluatableExpression>> {
if (client.initializeResult?.capabilities.experimental.xevaluatableExpressionProvider) {
const eer = await client.sendRequest(
EvaluatableExpressionRequest.type,
client.code2ProtocolConverter.asTextDocumentPositionParams(document, position),
token
)
if (eer && eer.expression) {
return new vscode.EvaluatableExpression(eer.range, eer.expression)
}
}
return undefined
},
})
)
}
32 changes: 32 additions & 0 deletions src/protocol.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import * as vscode from 'vscode'
import {
ProtocolRequestType,
TextDocumentPositionParams,
TextDocumentRegistrationOptions,
WorkDoneProgressOptions,
WorkDoneProgressParams,
} from 'vscode-languageclient/node'

interface EvaluatableExpression {
expression?: string
range: vscode.Range
}

interface EvaluatableExpressionOptions extends WorkDoneProgressOptions {}

interface EvaluatableExpressionParams extends TextDocumentPositionParams, WorkDoneProgressParams {}

interface EvaluatableExpressionRegistrationOptions
extends TextDocumentRegistrationOptions,
EvaluatableExpressionOptions {}

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