Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Proposal: LSP Client intiated function injection #435

Closed
nathanielc opened this issue Apr 4, 2022 · 0 comments · Fixed by #538
Closed

Proposal: LSP Client intiated function injection #435

nathanielc opened this issue Apr 4, 2022 · 0 comments · Fixed by #538

Comments

@nathanielc
Copy link
Contributor

nathanielc commented Apr 4, 2022

The UI currently has a feature that lets users inject a function call into their script. This mechanism is currently not scalable, meaning for a set of function a hard-coded string was saved and when the inject action is taken that string is inserted into the Flux script. This does not scale as new functions are regularly added to Flux and this will not work for user defined function.

We need a new solution. One possible solution is to have the LSP suggest auto-completions of these functions and use the snippets feature of the LSP. This will allow the functions to be injected when desired and allow the user to cycle through the placeholder elements for the various parameters to the function.

One challenge with this approach is its not currently possible (within the LSP) to use the snippets features outside the context of an auto-completion. This means that the function injection cannot be initialed by clicking a button in the UI. However the injection can be initiated by typing in the Flux editor. The LSP has an open issue to address this limitation.

Examples:

Say a users has this script and they want to inject the to function call:

from(bucket: "raw")
    |> range(start: -1h)
    |> filter(fn: (r) => r._measurement == "cpu")
    |> mean()
    // user want to inject "to" right here....

We can offer a code completion that would complete the above to this:

from(bucket: "raw")
    |> range(start: -1h)
    |> filter(fn: (r) => r._measurement == "cpu")
    |> mean()
    |> to(bucket: $1, host: $2, token: $3)

Note the $* text would not actually be shown to the user, but the user will be able to navigate from $1 to $2 to $3 inserting the desired values for each argument. The exact details of how this works will depend on the user's editor, meaning it will be familiar to how the user normally auto-completes snippets.

rockstar added a commit that referenced this issue Jul 20, 2022
This patch adds real snippet support to function parameter completion.
This means that one could potentially tab through each parameter in the
parameter list and add their associated values.

This patch is hilariously small and direct now that all the refactoring is
done.

Fixes #435
Fixes #431
rockstar added a commit that referenced this issue Jul 20, 2022
This patch adds real snippet support to function parameter completion.
This means that one could potentially tab through each parameter in the
parameter list and add their associated values.

This patch is hilariously small and direct now that all the refactoring is
done.

Fixes #435
Fixes #431
rockstar added a commit that referenced this issue Jul 20, 2022
This patch adds real snippet support to function parameter completion.
This means that one could potentially tab through each parameter in the
parameter list and add their associated values.

This patch is hilariously small and direct now that all the refactoring is
done.

Fixes #435
Fixes #431
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant