Skip to content

Commit

Permalink
fix: add setting to enable/disable code lens
Browse files Browse the repository at this point in the history
  • Loading branch information
elonmallin committed Nov 23, 2023
1 parent c39237d commit b911d96
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 3 deletions.
5 changes: 5 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,11 @@
"phpunit.envVars": {
"type": "object",
"title": "Set environment variables before running the phpunit command"
},
"phpunit.codeLens.enabled": {
"type": "boolean",
"default": true,
"title": "Enable/disable code lens for phpunit tests"
}
}
},
Expand Down
6 changes: 5 additions & 1 deletion src/CodeLens/PhpCodeLensProvider.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { CodeLensProvider, CodeLens, CancellationToken, TextDocument, Range } from 'vscode';
import { CodeLensProvider, CodeLens, CancellationToken, TextDocument, Range, workspace } from 'vscode';
import { Class, CommentBlock, Engine, Identifier, Method, Namespace } from 'php-parser';
import { PhpunitArgBuilder } from '../PhpunitCommand/PhpunitArgBuilder';

Expand All @@ -7,6 +7,10 @@ let lastCodeLenses: Array<CodeLens> = [];

export class PhpCodeLensProvider implements CodeLensProvider {
public provideCodeLenses(document: TextDocument, token: CancellationToken): Array<CodeLens> | Thenable<Array<CodeLens>> {
if (!workspace.getConfiguration("phpunit").get<boolean>("codeLens.enabled")) {
return [];
}

if (document.getText() === lastDocumentText) {
return lastCodeLenses;
}
Expand Down
6 changes: 5 additions & 1 deletion src/CodeLens/PhpunitXmlCodeLensProvider.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { CodeLensProvider, CodeLens, CancellationToken, TextDocument, Range } from 'vscode';
import { CodeLensProvider, CodeLens, CancellationToken, TextDocument, Range, workspace } from 'vscode';
import { parse, DocumentCstNode } from '@xml-tools/parser';
import { buildAst, XMLElement, } from '@xml-tools/ast';
import { PhpunitArgBuilder } from '../PhpunitCommand/PhpunitArgBuilder';
Expand All @@ -8,6 +8,10 @@ let lastCodeLenses: Array<CodeLens> = [];

export class PhpunitXmlCodeLensProvider implements CodeLensProvider {
public provideCodeLenses(document: TextDocument, token: CancellationToken): Array<CodeLens> | Thenable<Array<CodeLens>> {
if (!workspace.getConfiguration("phpunit").get<boolean>("codeLens.enabled")) {
return [];
}

if (!/phpunit\.xml(\.dist)?/.test(document.fileName)) {
return [];
}
Expand Down
1 change: 0 additions & 1 deletion src/phpunittest.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
"use strict";

import { ChildProcess } from "child_process";
import escapeStringRegexp from "./Utils/escape-string-regexp";
import * as fs from "fs";
import * as vscode from "vscode";
import Command from "./Command";
Expand Down

0 comments on commit b911d96

Please sign in to comment.