rokucommunity / vscode-brightscript-language

A Visual Studio Code extension for Roku's BrightScript language
MIT License
110 stars 41 forks source link

If and If Else snippets to include then #347

Closed DusanLesan closed 2 years ago

DusanLesan commented 2 years ago

I have seen that in most places adding then keyword in every if and else if is a standard. Could you update your snippets in vscode-brightscript-language/snippets/brightscript.json to include then keyword? Furthermore, If Else snippet should have a third jumping point after else.

Something like:

    "If": {
        "prefix": "if",
        "body": [
            "if ${1:condition} then",
            "\t$0",
            "end if"
        ],
        "description": "Simple if statement"
    },
    "If Else": {
        "prefix": "if-else",
        "body": [
            "if ${1:condition} then",
            "\t$2",
            "else",
            "\t$0",
            "end if"
        ],
        "description": "Simple if/else statement"
    },
chrisdp commented 2 years ago

I wouldn't consider the then statement as standard. It's an optional key word and really comes down to individual coding standards.

DusanLesan commented 2 years ago

@chrisdp You may be right. Is it possible then to make this part dynamic and set it based on user preference?

chrisdp commented 2 years ago

@TwitchBronBron would know more about if it could or could not be set dynamically.

As for a setting we would have to think how because this falls more in the territory of a linter like BSLint.

DusanLesan commented 2 years ago

Another possibility would be to override the snippet directory location in brightscript plugin settings.

TwitchBronBron commented 2 years ago

Snippets are defined statically in the extension's package.json so I don't think we can dynamically set these.

However, if you'd like, we can add another differently-named snippet which includes the then? The current trigger for an if statement without then is if. How about we add ift which would include the then?

Current: Trigger word Snippet
if if ${1:condition}
    $0
end if
if-else if ${1:condition}
    $0
else
    
end if
Proposed additions: Trigger word Snippet
ift if ${1:condition} then
    $0
end if
ift-else if ${1:condition} then
    $0
else
    
end if
DusanLesan commented 2 years ago

I do not like that as much as setting my own path to my snippets.json in plugin settings. Could I maybe give higher permissions to snippet folder and stop if from updating without causing plugin update to crash or something

TwitchBronBron commented 2 years ago

vscode requires that all extension-contributed snippets be defined in the package.json of the extension (here's the line in our project), and vscode does not allow us to reassign those paths at runtime.

You can add your own snippets in vscode directly without the need for any support from our extension.

Animation

DusanLesan commented 2 years ago

@TwitchBronBron That is what I need. It is bad experience to have duplicates I do not want but that is the same as if you add ift/ift-else. Thank you for the help and information

TwitchBronBron commented 2 years ago

You can hide unwanted snippets as well: Animation

DusanLesan commented 2 years ago

Awesome. All is great now