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
Changes from 1 commit
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
Next Next commit
Add support for experimental evaluatable expressions
zobo committed Dec 25, 2024
commit 088c44c25afa9a1e618ab988e643985a44b1a450
23 changes: 23 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'
@@ -50,6 +51,28 @@

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> {
if (languageClient.initializeResult?.capabilities.experimental?.xevaluatableExpressionProvider) {

Check failure on line 62 in src/extension.ts

GitHub Actions / build

Unsafe member access .xevaluatableExpressionProvider on an `any` value
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 {
33 changes: 33 additions & 0 deletions src/protocol.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
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
}

interface EvaluatableExpressionOptions extends WorkDoneProgressOptions {}

Check failure on line 16 in src/protocol.ts

GitHub Actions / build

An interface declaring no members is equivalent to its supertype

interface EvaluatableExpressionParams extends TextDocumentPositionParams, WorkDoneProgressParams {}

interface EvaluatableExpressionRegistrationOptions
extends TextDocumentRegistrationOptions,
EvaluatableExpressionOptions {}

export namespace EvaluatableExpressionRequest {

Check failure on line 24 in src/protocol.ts

GitHub Actions / build

ES2015 module syntax is preferred over namespaces
export const method: 'textDocument/xevaluatableExpression' = 'textDocument/xevaluatableExpression'

Check failure on line 25 in src/protocol.ts

GitHub Actions / build

Expected a `const` assertion instead of a literal type annotation
export const type = new ProtocolRequestType<
EvaluatableExpressionParams,
EvaluatableExpression | null,
never,
void,
EvaluatableExpressionRegistrationOptions
>(method)
}