Skip to content

Commit

Permalink
Merge branch 'master' into auto-closing-brackets
Browse files Browse the repository at this point in the history
  • Loading branch information
neild3r committed Oct 12, 2021
2 parents 3efaac8 + b9dce71 commit db39fd0
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 5 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Expand Up @@ -4,6 +4,8 @@ All notable changes to the "php-docblocker" extension will be documented in this

## [Unreleased]
- Fix double start delimeter when vscode setting `editor.autoClosingBrackets` is set to `never`
- Improve class head tolerance when there isn't one or it's too long
- Increased class head limit to 300 lines

## [2.6.0] - 2021-09-27

Expand Down
16 changes: 11 additions & 5 deletions src/block.ts
Expand Up @@ -212,15 +212,21 @@ export abstract class Block
*
* @returns {string}
*/
public getClassHead():string
public getClassHead(): string
{
if (this.classHead === undefined) {
let text = this.editor.document.getText(new Range(new Position(0, 0), new Position(150,0)));
let limit = this.editor.document.lineCount < 300 ? this.editor.document.lineCount - 1 : 300;
let text = this.editor.document.getText(new Range(new Position(0, 0), new Position(limit, 0)));
let regex = /\s*(abstract|final)?\s*(class|trait|interface)/gm;
let match = regex.exec(text);
let end = this.editor.document.positionAt(match.index);
let range = new Range(new Position(0, 0), end);
this.classHead = this.editor.document.getText(range);

if (match === null) {
this.classHead = null;
} else {
let end = this.editor.document.positionAt(match.index);
let range = new Range(new Position(0, 0), end);
this.classHead = this.editor.document.getText(range);
}
}

return this.classHead;
Expand Down
24 changes: 24 additions & 0 deletions test/TypeUtil.test.ts
Expand Up @@ -75,3 +75,27 @@ suite("TypeUtil tests: ", () => {
});

});

suite("TypeUtil issue test: ", () => {
let editor:TextEditor;

suiteSetup(function(done) {
workspace.openTextDocument(Helper.fixturePath+'namespace-issue.php').then(doc => {
window.showTextDocument(doc).then(textEditor => {
editor = textEditor;
done();
}, error => {
console.log(error);
})
}, error => {
console.log(error);
});
});

test("Ensure class head does not fail if there isn't one", () => {
let block = new FunctionBlock(new Position(0, 0), editor);
let head = block.getClassHead();

assert.equal(head, null);
});
});
7 changes: 7 additions & 0 deletions test/fixtures/namespace-issue.php
@@ -0,0 +1,7 @@
<?php



function testNoNamespace() {

}

0 comments on commit db39fd0

Please sign in to comment.