ipatalas / vscode-postfix-ts

Postfix notation for TypeScript/Javascript - extension for VS Code
MIT License
158 stars 43 forks source link

[proposal] Add more context to postfix: `exprRegex`, `exprLastRegex` #92

Open zardoy opened 2 years ago

zardoy commented 2 years ago

For now, we can only use when to narrow down locations, in which postfixes are suggested. However there are variable name conventions (such as Idx or Index). Just a few examples:

Code Examples

const dotIdx = 0
dotIdx.notFound
// =>
if (dotIdx === -1) return

Template Examples

{
    "name": "notFound",
    "body": "if ({{expr}} === -1) ${1:return}",
    "exprLastRegex": "(Idx|Index)$",
    "when": [
        "identifier",
        "expression"
    ]
},

Of course, I could use just exprRegex here, but exprLastRegex can be useful for method calls.

It is really cool, as we can use different postfixes with the same name for different variable name patterns.

Why regexs? Because there are easy to construct. Also as I know regex engine in JS is pretty fast.

zardoy commented 2 years ago

Of course it is also easy to implement, but I'll wait until https://github.com/ipatalas/vscode-postfix-ts/pull/91 is resolved ;)