Skip to content

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

@zardoy

Description

@zardoy

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions