From fe8085e88dba003c9e5e40461467fa7f551d8991 Mon Sep 17 00:00:00 2001 From: Damjan Cvetko Date: Wed, 26 Jul 2023 10:41:54 +0200 Subject: [PATCH 1/3] feat: Add support for EvaluatableExpression --- src/extension.ts | 24 ++++++++++++++++++++++++ src/protocol.ts | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 57 insertions(+) create mode 100644 src/protocol.ts diff --git a/src/extension.ts b/src/extension.ts index 6604ae32..04436c8a 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -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 { @@ -139,4 +141,26 @@ export async function activate(context: vscode.ExtensionContext): Promise // 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> { + 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 + }, + }) + ) } diff --git a/src/protocol.ts b/src/protocol.ts new file mode 100644 index 00000000..5baa0577 --- /dev/null +++ b/src/protocol.ts @@ -0,0 +1,33 @@ +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' + //const messageDirection: MessageDirection = MessageDirection.clientToServer; + export const type = new ProtocolRequestType< + EvaluatableExpressionParams, + EvaluatableExpression | null, + never, + void, + EvaluatableExpressionRegistrationOptions + >(method) +} From 0ba379734ef37f9b766779b093989bfb24197fc9 Mon Sep 17 00:00:00 2001 From: Damjan Cvetko Date: Wed, 26 Jul 2023 11:02:51 +0200 Subject: [PATCH 2/3] tslint issues --- src/protocol.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/src/protocol.ts b/src/protocol.ts index 5baa0577..189449ce 100644 --- a/src/protocol.ts +++ b/src/protocol.ts @@ -22,7 +22,6 @@ interface EvaluatableExpressionRegistrationOptions export namespace EvaluatableExpressionRequest { export const method: 'textDocument/xevaluatableExpression' = 'textDocument/xevaluatableExpression' - //const messageDirection: MessageDirection = MessageDirection.clientToServer; export const type = new ProtocolRequestType< EvaluatableExpressionParams, EvaluatableExpression | null, From 40d16db35b07fd3ce608d8de0fe80175fdab4d38 Mon Sep 17 00:00:00 2001 From: Damjan Cvetko Date: Wed, 26 Jul 2023 14:40:49 +0200 Subject: [PATCH 3/3] Update LSP --- composer.lock | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/composer.lock b/composer.lock index cdf8a81f..97d99554 100644 --- a/composer.lock +++ b/composer.lock @@ -168,7 +168,7 @@ "source": { "type": "git", "url": "https://github.com/zobo/php-language-server", - "reference": "1f55e86e97f959d85808f17020794cb8d5829bfa" + "reference": "25eb2c947a2496b5367cfbb1a17a2edf9a19d6b0" }, "require": { "composer/xdebug-handler": "^1.0", @@ -191,6 +191,7 @@ "phpunit/phpunit": "^9.0", "squizlabs/php_codesniffer": "^3.6" }, + "default-branch": true, "bin": [ "bin/php-language-server.php" ], @@ -249,7 +250,7 @@ "studio", "visual" ], - "time": "2023-07-17T09:07:09+00:00" + "time": "2023-07-26T12:37:45+00:00" }, { "name": "felixfbecker/language-server-protocol", @@ -318,12 +319,12 @@ "source": { "type": "git", "url": "https://github.com/JetBrains/phpstorm-stubs.git", - "reference": "ac879a1b675e381326d3f2a440b81af3c1a7a374" + "reference": "0b9854c8ba932966f3cb1469a2d18ab9249272b9" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/JetBrains/phpstorm-stubs/zipball/ac879a1b675e381326d3f2a440b81af3c1a7a374", - "reference": "ac879a1b675e381326d3f2a440b81af3c1a7a374", + "url": "https://api.github.com/repos/JetBrains/phpstorm-stubs/zipball/0b9854c8ba932966f3cb1469a2d18ab9249272b9", + "reference": "0b9854c8ba932966f3cb1469a2d18ab9249272b9", "shasum": "" }, "require-dev": { @@ -359,7 +360,7 @@ "support": { "source": "https://github.com/JetBrains/phpstorm-stubs/tree/master" }, - "time": "2023-07-16T13:57:52+00:00" + "time": "2023-07-20T19:40:08+00:00" }, { "name": "microsoft/tolerant-php-parser", @@ -625,16 +626,16 @@ }, { "name": "phpstan/phpdoc-parser", - "version": "1.22.1", + "version": "1.23.0", "source": { "type": "git", "url": "https://github.com/phpstan/phpdoc-parser.git", - "reference": "65c39594fbd8c67abfc68bb323f86447bab79cc0" + "reference": "a2b24135c35852b348894320d47b3902a94bc494" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpstan/phpdoc-parser/zipball/65c39594fbd8c67abfc68bb323f86447bab79cc0", - "reference": "65c39594fbd8c67abfc68bb323f86447bab79cc0", + "url": "https://api.github.com/repos/phpstan/phpdoc-parser/zipball/a2b24135c35852b348894320d47b3902a94bc494", + "reference": "a2b24135c35852b348894320d47b3902a94bc494", "shasum": "" }, "require": { @@ -666,9 +667,9 @@ "description": "PHPDoc parser with support for nullable, intersection and generic types", "support": { "issues": "https://github.com/phpstan/phpdoc-parser/issues", - "source": "https://github.com/phpstan/phpdoc-parser/tree/1.22.1" + "source": "https://github.com/phpstan/phpdoc-parser/tree/1.23.0" }, - "time": "2023-06-29T20:46:06+00:00" + "time": "2023-07-23T22:17:56+00:00" }, { "name": "psr/log", @@ -1032,5 +1033,5 @@ "platform-overrides": { "php": "7.4.0" }, - "plugin-api-version": "2.1.0" + "plugin-api-version": "2.3.0" }