Skip to content

Commit

Permalink
Merge pull request #47 from neild3r/author
Browse files Browse the repository at this point in the history
Add default author config
  • Loading branch information
neild3r committed Mar 24, 2018
2 parents c985feb + f0d21c9 commit 18eb459
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 3 deletions.
8 changes: 8 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,14 @@
"type": "boolean",
"default": false,
"description": "Wether you want to use integer instead of int and boolean instead of bool."
},
"php-docblocker.author": {
"type": "object",
"default": {
"name": "Name",
"email": "email@email.com"
},
"description": "Default author tag"
}
}
}
Expand Down
65 changes: 62 additions & 3 deletions src/completions.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
import {TextDocument, Position, CancellationToken, ProviderResult, CompletionItem, CompletionItemProvider, Range, SnippetString, CompletionItemKind, window} from "vscode";
import {workspace, TextDocument, Position, CancellationToken, ProviderResult, CompletionItem, CompletionItemProvider, Range, SnippetString, CompletionItemKind, window} from "vscode";
import Documenter from "./documenter";

/**
* Completions provider that can be registered to the language
*/
export default class Completions implements CompletionItemProvider
{
/**
* A config which will modify the result of the docblock
*
* @type {{}}
*/
protected config:{};

/**
* List of tags and snippets that are filled in docblocks
*
Expand All @@ -22,7 +29,7 @@ export default class Completions implements CompletionItemProvider
},
{
tag: '@author',
snippet: '@author ${1:Name} <${2:email@email.com}>'
snippet: '@author ${1:{{name}}} <${2:{{email}}}>'
},
{
tag: '@category',
Expand Down Expand Up @@ -146,6 +153,36 @@ export default class Completions implements CompletionItemProvider
}
];

/**
* Have we injected in tag data yet
*
* @type {{}}
*/
protected formatted = false;

/**
* Get the config from either vs code or the manually set one
*
* @returns {*}
*/
public getConfig():any
{
if (this.config == null) {
this.setConfig(workspace.getConfiguration().get('php-docblocker'));
}
return this.config;
}

/**
* Set the config object
*
* @param {*} config
*/
public setConfig(config:any):void
{
this.config = config;
}

/**
* Implemented function to find and return completions either from
* the tag list or initiate a complex completion
Expand Down Expand Up @@ -178,7 +215,7 @@ export default class Completions implements CompletionItemProvider

let search = document.getText(match);

let potential = this.tags.filter((tag) => {
let potential = this.getTags().filter((tag) => {
return tag.tag.match(search) !== null;
});

Expand All @@ -192,4 +229,26 @@ export default class Completions implements CompletionItemProvider

return result;
}

/**
* Get the tag list for completions
*
* @returns {Array<{tag:string, snippet:string}>}
*/
protected getTags():Array<{tag:string, snippet:string}>
{
if (!this.formatted) {
this.tags.forEach((tag, index) => {
if (tag.tag == '@author') {
tag.snippet = tag.snippet.replace("{{name}}", this.getConfig().author.name);
tag.snippet = tag.snippet.replace("{{email}}", this.getConfig().author.email);
this.tags[index] = tag;
}
});

this.formatted = true;
}

return this.tags;
}
}

0 comments on commit 18eb459

Please sign in to comment.