Skip to content

Migrate to Volar #388

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

Migrate to Volar #388

wants to merge 1 commit into from

Conversation

AngusMorton
Copy link

This is a clean version of #294.

This is a proof of concept that shows what it might look like if the Marko Language Tools migrated to Volar as a base.

This proof-of-concept is roughly complete for our purposes, we've been using it for the past few months.

Motivation and Context

Migrating to Volar resolves the issues we've had with the VSCode plugin on Windows (#240), and it improves the responsiveness of the plugin on Windows.

Why Volar?

  • Volar provides the glue code that the Marko Langauge Tools currently implement themselves, which means we could potentially shift the maintenance/implementation burden off the Marko team.
  • Vue and Astro use Volar for their Language Tools, so it's fairly well used.
  • The patterns in Volar are very similar to what is already here, so the migration is relatively straightforward.
    • MarkoFile -> MarkoVirtualCode
    • Plugin -> LanguageServicePlugin

TODO

This is fairly untested, I mostly hacked it up so it works with our project.

  • Test with non-TS projects / more project structures.
    • It doesn't appear to work with Node type stripping - Discord?
  • Improve diagnostic mapping?
    • Currently, Volar appears to only map diagnostics if they're wholly contained by a source span, which means we need to do some manual adjustments of diagnostic ranges, which can be less than ideal.

Questions

  • How do Processors fit with Volar? Is there an idiomatic way to do that in Volar?
  • Could we use Volar for marko-type-check? @volar/kit?

Copy link

changeset-bot bot commented Jul 30, 2025

⚠️ No Changeset found

Latest commit: e2bd9fe

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@@ -161,12 +163,12 @@ export class Extracted {
* on the view type.
*/
abstract class TokenView {
#tokens: Token[];
tokens: Token[];
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is an awful hack so that I can generate Volar CodeMapping objects from Tokens.

A better solution would be to have the extractor be able to generate CodeMappings itself...

Comment on lines +28 to +30
"command": "marko.debug.showScriptOutput",
"title": "Show Extracted Script Output",
"category": "Marko (Debug)"
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Small QOL improvement, could be split into a separate PR

image

Comment on lines +53 to +59
// TODO: Is this necessary?
// provideDocumentSymbols(document, token) {
// if (token.isCancellationRequested) return;
// return worker(document, (virtualCode) => {
// return provideDocumentSymbols(virtualCode);
// });
// },
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm probably missing something - but I wasn't sure if Marko specific document symbols were still necessary and that couldn't be provided by TS or HTML.

import type { Diagnostic } from "@volar/language-server";
import { TextDocument } from "vscode-languageserver-textdocument";

export function enhanceDiagnosticPositions(
Copy link
Author

@AngusMorton AngusMorton Jul 30, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is necessary to ensure we show diagnostics. Volar doesn't seem to display them when they are larger than the code mappings, so I clamp the diagnostics to the most reasonable code mapping we can find...

There is almost certainly a better way, but this seems good enough for now?

// This will cause the plugin to be called again, so we check that the extension is not already added.
ps.setHostConfiguration({
extraFileExtensions: extraExtensions.concat(
Processors.extensions.map((extension) => ({
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I notice we're using Processors here, but extractors elsewhere... I'm wondering if we should be using Processors in the MarkoVirtualCode?

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 this pull request may close these issues.

1 participant