Powershell: Feature Request: include language keywords in command completion results

Created on 24 Jul 2019  路  4Comments  路  Source: PowerShell/PowerShell

Summary of the new feature/enhancement

Include language keywords, such as 'continue', 'switch', 'foreach', etc... in with the command completions offered by intellisense/tab completion.

Proposed technical implementation details (optional)

I don't yet know if its possible to restrict the keywords when the insertion point is not the first command in a pipeline, but there is already 1 case in the completion logic that has decided that foreach should not have an ampersand & (invoke) operator inserted before it (its actually in the completions because its an alias for ForEach-Object) because its more likely what the user wanted, but none of the other keywords get this treatment. Including the keywords would actually eliminate this special case.

I am sure somewhere there is a complete list of keywords in the code, I'm just not sure if there is anything to use as a tooltip text readily available.

I may experiment on this while working the other bugs out of the completion code.

Issue-Enhancement WG-Interactive-IntelliSense

Most helpful comment

Thanks, @vexx32, sometimes I speak better computer than English. :)

All 4 comments

Might want to clarify your issue title; it seems the request is for language keywords to show in tab-completion results where appropriate, rather than for commands to show (which they already do). 馃檪

But yep, agreed, not sure why we don't include keywords.

Thanks, @vexx32, sometimes I speak better computer than English. :)

I am sure somewhere there is a complete list of keywords in the code

Yes, here in the tokenizer. Copying it in:

private static readonly string[] s_keywordText = new string[] {
    /*1*/    "elseif",                  "if",               "else",             "switch",                     /*1*/
    /*2*/    "foreach",                 "from",             "in",               "for",                        /*2*/
    /*3*/    "while",                   "until",            "do",               "try",                        /*3*/
    /*4*/    "catch",                   "finally",          "trap",             "data",                       /*4*/
    /*5*/    "return",                  "continue",         "break",            "exit",                       /*5*/
    /*6*/    "throw",                   "begin",            "process",          "end",                        /*6*/
    /*7*/    "dynamicparam",            "function",         "filter",           "param",                      /*7*/
    /*8*/    "class",                   "define",           "var",              "using",                      /*8*/
    /*9*/    "workflow",                "parallel",         "sequence",         "inlinescript",               /*9*/
    /*A*/    "configuration",           "public",           "private",          "static",                     /*A*/
    /*B*/    "interface",               "enum",             "namespace",        "module",                     /*B*/
    /*C*/    "type",                    "assembly",         "command",          "hidden",                     /*C*/
    /*D*/    "base",                                                                                          /*D*/
};

I'm just not sure if there is anything to use as a tooltip text readily available.

Would that be beneficial? If you autocomplete notepad.exe you don't get very useful tooltip information.

Would that be beneficial? If you autocomplete notepad.exe you don't get very useful tooltip information.

That's because notepad.exe isn't part of PowerShell. You do on the other hand still get the complete path to notepad.exe in the tooltip. I think something in the tooltip needs to let the user know that this is the keyword, vs the function. Some functions do not show anything in their tooltip, so if both functions and keywords both showed nothing in the tooltip it might be slightly confusing, however, at least a command with the same name as a keyword requires the & and that will show when its selected.

Interestingly I see the operators are already included in completions, and they have tooltips.

Any data kept on whether these keywords are available, or better, available in a given context? I would think that reserved keywords should probably not have completions offered, so that a user doesn't have as much clutter to sort through, and keywords that are not available in the current context should not be offered.

I suppose that last part is what has kept keyword completion from being implemented so far.

Was this page helpful?
0 / 5 - 0 ratings