-
Notifications
You must be signed in to change notification settings - Fork 29
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
Add volar-service-yaml #45
Conversation
This provides all features from the YAML language service through Volar.
This provides better tree shaking and fewer quirks when bundling.
Co-authored-by: Erika <[email protected]>
packages/yaml/src/index.ts
Outdated
} | ||
|
||
// @ts-expect-error This exists as an experimental API in Node 16. | ||
const response = await fetch(uri); |
There was a problem hiding this comment.
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)); |
There was a problem hiding this comment.
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.
services/packages/json/src/index.ts
Lines 21 to 32 in a2eee58
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); | |
}, |
packages/yaml/src/index.ts
Outdated
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'; |
There was a problem hiding this comment.
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.
Sorry for the long delay, thanks a lot for the work! |
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.