支持对自定义块的 typescript 识别和校验? #3828
Unanswered
linpengteng
asked this question in
Q&A
Replies: 5 comments 1 reply
-
Use a language plugin. For reference, see #3761 |
Beta Was this translation helpful? Give feedback.
0 replies
-
I tried, but it didn't work. ./src/views/PartIndex.vue <template>
<div />
</template>
<script setup lang="ts">
</script>
<starter lang="ts">
const message = ref('message')
export default {
message
}
</starter> ./pluginer.ts import type { VueLanguagePlugin } from "@vue/language-core"
const plugin: VueLanguagePlugin = () => {
return {
name: "sfc-starter-volar",
version: 1,
resolveEmbeddedFile(fileName, sfc, embeddedFile) {
if (embeddedFile.fileName.replace(fileName, "").match(/^\.(js|ts|jsx|tsx)$/)) {
for (const block of sfc.customBlocks) {
const content = embeddedFile.content
if (block.type === "starter") {
content.push([
block.content, // text to add
block.name, // source
0, // content offset in source
{
// language capabilities to enable in this segment
hover: true,
references: true,
definition: true,
diagnostic: true,
rename: true,
completion: true,
semanticTokens: true
}
])
}
}
}
}
}
}
export default plugin ./tsconfig.json {
"vueCompilerOptions": {
"plugins": [
"./pluginer.ts"
]
},
"compilerOptions": {
"baseUrl": "./",
"target": "esnext",
"module": "esnext",
"moduleResolution": "node",
"jsx": "preserve",
"strict": true,
"allowJs": false,
"sourceMap": true,
"skipLibCheck": true,
"isolatedModules": true,
"esModuleInterop": true,
"resolveJsonModule": true,
"useDefineForClassFields": true,
"allowSyntheticDefaultImports": true,
"paths": {
"@/*": [
"src/*"
]
},
"lib": [
"esnext",
"dom"
]
},
"include": [
"**/*.ts",
"**/*.js",
"**/*.tsx",
"**/*.jsx",
"**/*.mjs",
"**/*.vue"
],
"references": [
{
"path": "./tsconfig.node.json"
}
]
} |
Beta Was this translation helpful? Give feedback.
0 replies
-
Which step am I missing? Help! |
Beta Was this translation helpful? Give feedback.
0 replies
-
Could you please provide a repo? Thanks! |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
我在 Vue 单文件定义了自定义块 <setup-starter lang="ts"> ,在VSCODE中,我如何让它进行等同于 <script lang="ts"> 的 TypeScript 的识别和校验?
Beta Was this translation helpful? Give feedback.
All reactions