Comments (2)
Hi @kingyue737, you don't need to use VueLanguagePlugin, please try https://github.com/johnsoncodehk/volar-plugins/tree/master/packages/vue-json.
from services.
Hi @johnsoncodehk , I'm learning how to write a volar plugin. I try to specify a Json schema for a specific custom block:
/** @type {import('@volar/vue-language-core').VueLanguagePlugin} */
const schemaUrl = 'https://json.schemastore.org/prettierrc.json'
const blockType = 'route'
const plugin = () => {
return {
name: 'example-volar-plugin-json-schema',
version: 1,
getEmbeddedFileNames(fileName, sfc) {
const names = []
for (let i = 0; i < sfc.customBlocks.length; i++) {
const customBlock = sfc.customBlocks[i]
names.push(
fileName +
'.customBlock_' +
customBlock.type +
'_' +
i +
'.' +
customBlock.lang
)
}
return names
},
resolveEmbeddedFile(fileName, sfc, embeddedFile) {
if (embeddedFile.fileName.replace(fileName, '').match(/^\.(jsx|tsx)$/)) {
for (const block of sfc.customBlocks) {
if (block.type === blockType) {
try {
block.content = block.content.replace(
'{',
`{"$schema":"${schemaUrl}",`
)
} catch {
/* continue regardless of error */
}
}
}
}
const match = embeddedFile.fileName.match(
/^(.*)\.customBlock_([^_]+)_(\d+)\.([^.]+)$/
)
if (match) {
embeddedFile.content[0][2] = -`"$schema":"${schemaUrl}",`.length
}
},
}
}
module.exports = plugin
I don't know if my thinking is correct. It seems that autocompletion, hover and validation, they all work!
But when I hover on a property, tip shows twice:
The second problem is that the relative path of Json schema in a SFC custom block is related to root of the disk instead of workspace:
Maybe we need to implement resolveRelativePath
like https://github.com/microsoft/vscode-json-languageservice/blob/e73082b16fe2c7c09ac24a35956efab1e88c699b/src/test/jsonSchemaTestSuite.test.ts#L28 in the built-in json plugin of volar?
Any guidance would be appreciated!
from services.
Related Issues (20)
- Display Error HOT 1
- How to disable the Duplicate attribute warning ? HOT 2
- Unable to set up ESLint plugin at all
- Implements built-in codeLens of typescript-language-features
- The Vue Semantic Server server crashed 5 times in the last 3 minutes. The server will not be restarted. See the output for more information.
- typescript service `jsonc-parser` dependency breaks browser runtime
- `prettier` peerDependency of `volar-service-prettier` should be optional
- [HELP] How do I control the tsconfig in TypeScript services? HOT 1
- Don’t compile default exports to CJS
- Using Prettier Service
- Prettier config is not found, when project is not in the root folder
- Code Action doesn't return correct document version
- [feature] Can you provide a prettier-eslint formatting tool? Thank you very much.
- When opening a huge d.ts file, there will be long periods of high CPU usage. HOT 2
- Integrating `volar-service-vetur` in a new Vue 3 + Vite Project HOT 2
- Improve document synchronization for Markdown Service Plugin
- LSP `Error: Could not load Prettier: Error: Cannot find module 'prettier'` when using `astro-ls` in `neovim`
- services in this repo do not work since vue-official v2 HOT 1
- Dedicated Sass language service support HOT 2
- HTML and CSS services should collect custom data added by other extensions
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from services.