-
-
Notifications
You must be signed in to change notification settings - Fork 494
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
☂️ Partial support for .vue
, .svelte
and .astro
files
#1719
Comments
Vue files can have multiple script tags afaik. Not sure about the others. |
I will try implementing the Vue support. I'll open a draft PR soon |
Is it safe to assume, that Astro JS Files are always Typescript? If you include something like define:vars prop to script, it becomes client-side only -> js. |
The initial objective is to parse only the frontmatter of the file, which is TypeScript. I got confirmation from Nate, who wrote the compiler. The |
All of them (Vue, Svelte and Astro) uses Volar. They might have solutions for most of your problems. |
Do you have more information to help us understand how Volar can help us? |
@ematipico While updating the VS Code extension to handle the additional file types, I've discovered that formatting works correctly when using the CLI, but does not work as expected when going through the LSP. Given the following Astro file (but applies to others too), the formatted, when invoked via the LSP will return only the "script" part, and remove everything else from the file. - ---
- statement ( );
- statement();
- ---
-
- <div></div>
+ statement();
+ statement(); Not sure if something more needs to be done here biome/crates/biome_lsp/src/handlers/formatting.rs Lines 14 to 54 in 8ea90d9
|
Yeah that makes sense. We still need to update the LSP side to stitch up the original content with the new content, like we do in the CLI |
Now the LSP supports diagnostics and code actions for these files. We just need to implement the rest of the features, which is going to be very straightforward. If anyone wants help, this is going be very easy, even for new contributors. Feel free to comment here and I'll tell you how to land the support of the missing features. |
I wouldn't mind helping out with the above, not sure where to start though |
You could start with https://github.com/biomejs/biome/tree/main/crates/biome_service/src/file_handlers To implement the handler for a file - for example Astro, we have to create the new handlers. Let's do it for And update the capabilities here, with
The types of the functions can be found here: biome/crates/biome_service/src/file_handlers/mod.rs Lines 376 to 380 in 06e6476
The content of this new
The content of the function javascript::format_range( ) // pass the payload here Take inspiration from this function: biome/crates/biome_service/src/file_handlers/astro.rs Lines 127 to 133 in 06e6476
|
@ematipico quick question. Svelte script code blocks should have everything spaced but these changes move the entire block back a space to the start of the line. Can I have it add a space to the block? <script>
const foo = …
</script> Instead of <script>
const foo = …
</script> |
That's part of the limitations and expectations. This will get solved once we will support these files fully |
Has it been released? // package.json
"@biomejs/biome": "^1.5.3-nightly.69f9031", // biome.json
{
"formatter": {
"indentStyle": "space",
"lineWidth": 120
},
"javascript": {
"formatter": {
"quoteStyle": "single"
}
}
} > biome check --apply ./src
Fixed 4 file(s) in 16ms Only able to scan |
@ematipico okay. I just gave this a try out of excitement and noticed it as the PR references what I'd expect out of the formatting. |
@Shyam-Chen No, it will be released in the next minor |
@ematipico Svelte files still are getting formatting without the leading indentation: <script>
const foo = …
</script> |
@twonil-jordan-stout that's expected, please find more here: https://biomejs.dev/internals/language-support/#html-super-languages-support |
Couldn't this be an option? or changed for .svelte files? I think in Svelte the common style has indentation: https://svelte.dev/examples/hello-world |
Still waiting for the full support of svelte. Until then, I cannot use this wonderful tool :( |
Strangely its auto-inserting semicolon on save with svelte. Even though the config has been set specifically not to for JavaScript. I guess It doesn't have svelte support yet. |
Description
What does partial support mean? It means that the objective is to parse only the JavaScript portions of the files, and ignore the rest.
Since everything works at workspace level, the support of these three files is pretty straightforward:
Astro
Parsing and capabilities
It's safe to assume that Astro files are always TypeScript files. So it should be parsed and handled as a
JsFileSource::ts()
Vue
Parsing and capabilities
The JavaScript code is inside the `<script></script> tag. Let's use a regex to compile the start/end of the tags.
Let's use a simple check to understand the language, e.g.
<script lang="ts">
. Based on its value, we can compute the correctJsFileSource
Svelte
Parsing and capabilities
The JavaScript code is inside the `<script></script> tag. Let's use a regex to compile the start/end of the tags.
Let's use a simple check to understand the language, e.g.
<script lang="ts">
. Based on its value, we can compute the correctJsFileSource
How to help/contribute
First, each language must have implemented capabilities and parsing. With those two, we can implement the rest of the features.
Use this PR as a blueprint to understand how to add handling of files with a particular extension: #1718
file_handlers/mod.rs
, you'll have to add a new extension;file_handlers/
, you'll have to create a new file with the name of the extension to handle;None
at the beginning, then we will add functions as we go, to handle all the various cases.Please comment if you want to help, and with what. We want to have only one person working on the same thing.
For testing, use #1718 as a reference. And if you require more information, you can create a draft PR and follow up there with questions you might have.
The text was updated successfully, but these errors were encountered: