Skip to content

Integrate with bash-completion, if available #117

Closed
@ebkalderon

Description

@ebkalderon

It would be helpful if bash-language-server could utilize bash-completion to fetch the available switches and arguments for certain commands. I'm not familiar with Typescript myself, unfortunately, so I cannot determine the feasibility of implementing such a feature at this time.

Subcommand and switch completion

For example, if git and its associated Bash completions are installed on the machine, then typing the following into a buffer:

git <ctrl+space>

would yield the following completions from the language server:

add
am
archive
bisect
etc...

Similarly, typing the following:

git --<ctrl+space>

would yield the following completions:

--bare
--exec-path
--exec-path=
--git-dir=
--help
etc...

Optionally, the server could attempt to fetch results for both git , git -, and git -- (in that order) and show completions for all three possibilities such that they can be easily filtered and selected at a glance. I'm not sure about the performance implications of this behavior, however.

Argument completion

A similar process could allow for argument completion, if the completion function provides it. For example, if openssh and its associated Bash completions are installed, then typing the following:

ssh <ctrl+space>

would possibly yield the following completions:

127.0.0.1
12.123.123.123
::1
bar
baz.com
foo.local
github.com
localhost

Future work

If a manpage exists on the system for a specific command (the same one manpage currently used for documentation suggestions in bash-language-server), we could potentially search the manpage for the subcommands/switches provided to us by bash-completion, such that entering the following:

git --h<ctrl+space>

would allow the user to select --help from the list, and hovering over the --help would parse the git manpage for a section titled --help and display the following:

--help
           Prints the synopsis and a list of the most commonly used commands. If the option --all or -a is given then all available commands are printed. If a
           Git command is named this option will bring up the manual page for that command.

           Other options are available to control how the manual page is displayed. See git-help(1) for more information, because git --help ...  is converted
           internally into git help ....

This could be done using explainshell for help, as also suggested in #107.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions