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

Add volar-service-yaml #45

Merged
merged 12 commits into from
Sep 3, 2023
Merged

Add volar-service-yaml #45

merged 12 commits into from
Sep 3, 2023

Conversation

remcohaszing
Copy link
Member

This provides all features from the YAML language service through Volar.

It could be interesting to add support for the JSON schemastore later. I omitted this for now, as that’s part of the language server, not the language service.

This provides all features from the YAML language service through Volar.
This provides better tree shaking and fewer quirks when bundling.
}

// @ts-expect-error This exists as an experimental API in Node 16.
const response = await fetch(uri);
Copy link
Member

@johnsoncodehk johnsoncodehk Sep 3, 2023

Choose a reason for hiding this comment

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

We don't need to handle http requests in the service because it is already handled in language server: https://github.com/volarjs/volar.js/blob/fc0bc2c262e693b6d41e87bff758ac1eb6eeb8c9/packages/language-server/src/node/index.ts#L54

clientCapabilities: context?.env?.clientCapabilities,
workspaceContext: {
resolveRelativePath(relativePath, resource) {
return String(new URL(relativePath, resource));
Copy link
Member

@johnsoncodehk johnsoncodehk Sep 3, 2023

Choose a reason for hiding this comment

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

I found this is simpler than json service. The following code of json service is modified from vscode implementation. But I think your implementation also works, let's keep it.

resolveRelativePath: (ref: string, base: string) => {
if (ref.match(/^\w[\w\d+.-]*:/)) {
// starts with a schema
return ref;
}
if (ref[0] === '/') { // resolve absolute path against the current workspace folder
return base + ref;
}
const baseUri = URI.parse(base);
const baseUriDir = baseUri.path.endsWith('/') ? baseUri : Utils.dirname(baseUri);
return Utils.resolvePath(baseUriDir, ref).toString(true);
},

import { type Service } from '@volar/language-service';
import { type TextDocument } from 'vscode-languageserver-textdocument';
import { type LanguageSettings, type LanguageService } from 'yaml-language-server';
import { getLanguageService } from 'yaml-language-server/lib/umd/languageservice/yamlLanguageService.js';
Copy link
Member

Choose a reason for hiding this comment

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

This is a good way to avoid downstream bundling hack! But since this is inconsistent with other services, I will temporarily change it to import from 'yaml-language-server' and change to import from umd path for all services in a separate PR, so we can retrace the reason.

@johnsoncodehk
Copy link
Member

Sorry for the long delay, thanks a lot for the work!

@johnsoncodehk johnsoncodehk merged commit 6a13528 into volarjs:master Sep 3, 2023
@remcohaszing remcohaszing deleted the yaml-language-server branch September 3, 2023 08:12
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.

3 participants