Skip to content

Commit

Permalink
Merge branch 'codelens'. 1.12.2
Browse files Browse the repository at this point in the history
  • Loading branch information
bmewburn committed Aug 8, 2024
2 parents 5ea7ebb + 9effc89 commit 7c7eecb
Show file tree
Hide file tree
Showing 5 changed files with 97 additions and 48 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Change Log

## [1.12.2 - 2024-08-08]

#### Fixed
- Added missing code lens middleware
- TypeError: Cannot read properties of undefined (reading 'scopeTypeDefinition')

## [1.12.1 - 2024-08-08]

#### Fixed
Expand Down
75 changes: 36 additions & 39 deletions package-lock.json

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

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"sponsor": {
"url": "https://intelephense.com"
},
"version": "1.12.1",
"version": "1.12.2",
"publisher": "bmewburn",
"engines": {
"vscode": "^1.82.0"
Expand Down Expand Up @@ -886,7 +886,7 @@
},
"dependencies": {
"fs-extra": "~11.2.0",
"intelephense": "1.12.1",
"intelephense": "1.12.2",
"semver": "~7.6.2",
"vscode-languageclient": "9.0.1"
},
Expand Down
2 changes: 1 addition & 1 deletion src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import { createMiddleware, IntelephenseMiddleware } from './middleware';
import * as fs from 'fs-extra';

const PHP_LANGUAGE_ID = 'php';
const VERSION = '1.12.1';
const VERSION = '1.12.2';
const INDEXING_STARTED_NOTIFICATION = new NotificationType('indexingStarted');
const INDEXING_ENDED_NOTIFICATION = new NotificationType('indexingEnded');
const CANCEL_INDEXING_REQUEST = new RequestType('cancelIndexing');
Expand Down
58 changes: 52 additions & 6 deletions src/middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,17 @@
'use strict';

import {
Middleware, HandleDiagnosticsSignature, ConfigurationParams, RequestHandler
Middleware, HandleDiagnosticsSignature, ConfigurationParams, RequestHandler,
CodeLens, Location as ILocation, Position as IPosition
} from 'vscode-languageclient';
import {
CancellationToken, workspace, Disposable, Uri,
Diagnostic, DiagnosticTag
Diagnostic, DiagnosticTag,
Command,
Position,
Location,
Range,
CodeLens as VCodeLens
} from 'vscode';

export interface IntelephenseMiddleware extends Middleware, Disposable { }
Expand All @@ -25,7 +31,7 @@ export function createMiddleware(): IntelephenseMiddleware {

function mergeAssociations(intelephenseAssociations: string[]) {
let vscodeConfig = workspace.getConfiguration('files');
if(!vscodeConfig) {
if (!vscodeConfig) {
return intelephenseAssociations;
}
let vscodeAssociations = vscodeConfig.get('associations') || {};
Expand Down Expand Up @@ -81,6 +87,39 @@ export function createMiddleware(): IntelephenseMiddleware {
return settings;
}

function transformCodeLensResolveResult(lens: CodeLens): CodeLens {

if (
lens.command &&
lens.command.command === 'editor.action.peekLocations' &&
lens.command.arguments
) {
if (typeof lens.command.arguments[0] === 'string') {
lens.command.arguments[0] = Uri.parse(lens.command.arguments[0]);
}

if (IPosition.is(lens.command.arguments[1])) {
lens.command.arguments[1] = new Position(lens.command.arguments[1].line, lens.command.arguments[1].character);
}

if (Array.isArray(lens.command.arguments[2])) {
lens.command.arguments[2] = lens.command.arguments[2].map(
l => ILocation.is(l)
? new Location(
Uri.parse(l.uri),
new Range(new Position(l.range.start.line, l.range.start.character), new Position(l.range.end.line, l.range.end.character))
)
: l
);
}
}
console.log('transformCodeLensResolveResult');
return new VCodeLens(
new Range(new Position(lens.range.start.line, lens.range.start.character), new Position(lens.range.end.line, lens.range.end.character)),
lens.command
);
}

let middleware = <IntelephenseMiddleware>{
workspace: {
configuration: (
Expand All @@ -91,14 +130,21 @@ export function createMiddleware(): IntelephenseMiddleware {

let result = next(params, token);
if (!isThenable(result)) {
return Array.isArray(result) ? mergeSettings(result, params): result;
return Array.isArray(result) ? mergeSettings(result, params) : result;
}

return (<Thenable<any>>result).then(r => {
return Array.isArray(result) ? mergeSettings(result, params): result;
return Array.isArray(result) ? mergeSettings(result, params) : result;
});
}
},
resolveCodeLens: (codeLens, token, next) => {
let result = next(codeLens, token);
if (!isThenable(result)) {
return result ? transformCodeLensResolveResult(result) : result;
}
return result.then(r => r ? transformCodeLensResolveResult(r) : r);
},

dispose: Disposable.from(...toDispose).dispose
}
Expand All @@ -107,6 +153,6 @@ export function createMiddleware(): IntelephenseMiddleware {

}

function isThenable(obj: any) {
function isThenable(obj: any): obj is Thenable<any> {
return obj && obj.then !== undefined;
}

0 comments on commit 7c7eecb

Please sign in to comment.