Open codevogel opened 3 months ago
I looked into it and the "ask where to create file" part requires custom code in the language server client. The language server protocol currently doesn't have a way for the server to ask user input either as part of code action or a standalone request. If we were to do this, it'll probably default to the same directory and the client can intercept it to replace the target file path/module specifier in CodeAction.data.
Description
I like to write out my HTML in a top-down direction. I start with a Parent component (say
BarGraph.svelte
) and then write out something like this:(Let's ignore the fact that in this case it might make more sense to use
<slot/>
to include theBar
components, this is just an illustrative example.)At this point,
Bar.svelte
does not exist, so I rightfully encounter the errors'Bar' is not defined
andCannot find name 'Bar'
.Now, I am used to language servers giving me the option to generate the undefined file. But I don't seem to get the same option when trying to add new Svelte components using this workflow. Instead, I have to manually create the Child component (
Bar
), then get back to the Parent (Chart.svelte
) to add the imports through a code action.Proposed solution
Input:
I perform a code action while my cursor is on the
<Bar \>
tag, I would like to be able to be offered an option that says something along the lines ofCreate Bar.svelte in ...
Output:
This is what I expect to happen when I select that code action:
neovim
, a floating window could pop up that asks me where I want to store the file. The default location could be the same directory as the Parent component. This is a path relative to thepwd
.$lib
.Return/Enter
I would i. create the file in the given directory, ii. add<script></script>
tags to the Parent component (Chart.svelte
) if not present already. iii. add an import statement using the exact path specified in the prompt to myChart.svelte
file.(optional: prefferably the import statement would autocorrect to the
$lib/
format if the file is in an aliased directory, but for now it would make most sense to just enter exactly what you entered in the prompt.)Alternatives
No response
Additional Information, eg. Screenshots
No response