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

Explicitly requesting a code snippet #1174

Closed
robertoaloi opened this issue Dec 27, 2020 · 4 comments
Closed

Explicitly requesting a code snippet #1174

robertoaloi opened this issue Dec 27, 2020 · 4 comments
Labels
info-needed Issue requires more information from poster

Comments

@robertoaloi
Copy link
Contributor

Snippets are a great LSP feature, but they are currently tightly coupled with completions. In the Erlang Language Server we would like to allow developers to use snippet even not in combination with completion.

A sample use case is to add edoc annotations (The Erlang equivalent of javadoc) to functions.

Say you have a sum/2 function:

sum(A, B) ->
  A + B.

We would like the user to request an "edoc snippet", which would add the following:

%%------------------------------------------------------------------------------
%% @doc Function name
%% Write some docs
%% @end
%%------------------------------------------------------------------------------
sum(A, B) ->
  A + B.

Today we are abusing a snippet_ prefix in the snippet label to achieve this (see https://erlang-ls.github.io/articles/snippets-are-here/), but it would be much cleaner for the client to be able to request a specific snippet.

This would also open to more powerful snippets. For example, the placeholders above could be automatically expanded to:

%%------------------------------------------------------------------------------
%% @doc sum/2
%% Write some docs
%% @end
%%------------------------------------------------------------------------------
sum(A, B) ->
  A + B.

Thoughts?

@mickaelistria
Copy link

It looks similar to #592 . I have the impression that basically any TextEdit sent from server to client should be able to define some snippets for client to enable after applying the text edit. Would that work in your case?

@dbaeumer
Copy link
Member

dbaeumer commented Jan 4, 2021

@robertoaloi how would a user trigger this. Via code actions as @mickaelistria pointed to?

@dbaeumer dbaeumer added the info-needed Issue requires more information from poster label Jan 4, 2021
@robertoaloi
Copy link
Contributor Author

Hi @dbaeumer a code action would be a good start.

@dbaeumer
Copy link
Member

In that case I argue that we fold this as a dup of #592

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
info-needed Issue requires more information from poster
Projects
None yet
Development

No branches or pull requests

3 participants