vuejs / language-tools

⚡ High-performance Vue language tooling based-on Volar.js
https://marketplace.visualstudio.com/items?itemName=Vue.volar
MIT License
5.87k stars 404 forks source link

TypeError: Cannot read properties of undefined (reading 'label') & Server process exited with code 1 #4527

Closed ellermister closed 4 months ago

ellermister commented 4 months ago

Vue - Official extension or vue-tsc version

v2.0.24

VSCode version

1.91.0

Vue version

3.4.27

TypeScript version

@volar/typescript@^2.3.0 ?

System Info

System:
    OS: Linux 6.1 Debian GNU/Linux 11 (bullseye) 11 (bullseye)
    CPU: (4) x64 Intel(R) Core(TM) i3-3240 CPU @ 3.40GHz
    Memory: 7.30 GB / 11.58 GB
    Container: Yes
    Shell: 5.1.4 - /bin/bash
  Binaries:
    Node: 20.15.0 - /usr/local/share/nvm/versions/node/v20.15.0/bin/node
    Yarn: 1.22.22 - /usr/bin/yarn
    npm: 10.7.0 - /usr/local/share/nvm/versions/node/v20.15.0/bin/npm

Steps to reproduce

error output

Node.js v20.11.1
[Error - 4:37:39 AM] Server process exited with code 1.
[Info  - 4:37:39 AM] Connection to server got closed. Server will restart.
true
/home/vscode/.vscode-server/extensions/vue.volar-2.0.24/dist/server.js:13571
`)}})??{}}});return{...e,name:"vue-sfc",create(n){let r=e.create(n);return{...r,provide:{"vue/vueFile":s=>t(s,n,i=>i)},provideDocumentLinks:void 0,async resolveEmbeddedCodeFormattingOptions(s,i,o){return s.generated?.root instanceof IN.VueVirtualCode&&(i.id==="script_raw"||i.id==="scriptsetup_raw"?(await n.env.getConfiguration?.("vue.format.script.initialIndent")??!1)&&o.initialIndentLevel++:i.id.startsWith("style_")?(await n.env.getConfiguration?.("vue.format.style.initialIndent")??!1)&&o.initialIndentLevel++:i.id==="template"&&(await n.env.getConfiguration?.("vue.format.template.initialIndent")??!0)&&o.initialIndentLevel++),o},provideDocumentSymbols(s){return t(s,n,i=>{let o=[],a=i.sfc;a.template&&o.push({name:"template",kind:2,range:{start:s.positionAt(a.template.start),end:s.positionAt(a.template.end)},selectionRange:{start:s.positionAt(a.template.start),end:s.positionAt(a.template.startTagEnd)}}),a.script&&o.push({name:"script",kind:2,range:{start:s.positionAt(a.script.start),end:s.positionAt(a.script.end)},selectionRange:{start:s.positionAt(a.script.start),end:s.positionAt(a.script.startTagEnd)}}),a.scriptSetup&&o.push({name:"script setup",kind:2,range:{start:s.positionAt(a.scriptSetup.start),end:s.positionAt(a.scriptSetup.end)},selectionRange:{start:s.positionAt(a.scriptSetup.start),end:s.positionAt(a.scriptSetup.startTagEnd)}});for(let l of a.styles){let u="style";l.scoped&&(u+=" scoped"),l.module&&(u+=" module"),o.push({name:u,kind:2,range:{start:s.positionAt(l.start),end:s.positionAt(l.end)},selectionRange:{start:s.positionAt(l.start),end:s.positionAt(l.startTagEnd)}})}for(let l of a.customBlocks)o.push({name:`${l.type}`,kind:2,range:{start:s.positionAt(l.start),end:s.positionAt(l.end)},selectionRange:{start:s.positionAt(l.start),end:s.positionAt(l.startTagEnd)}});return o})},async provideCompletionItems(s,i,o,a){let l=await r.provideCompletionItems?.(s,i,o,a);if(l)return l.items=[...l.items.filter(u=>u.label!=="!DOCTYPE"&&u.label!=="Custom Blocks"),Dte(l.items.find(u=>u.label==="script")),Dte(l.items.find(u=>u.label==="script setup"))],l}}}};function t(n,r,s){let i=r.decodeEmbeddedDocumentUri(vt.parse(n.uri)),o=i&&r.language.scripts.get(i[0]),a=i&&o?.generated?.embeddedCodes.get(i[1]);if(a instanceof IN.VueVirtualCode)return s(a)}}function Dte(e){return{...e,label:e.label+' lang="ts"',textEdit:{...e.textEdit,newText:e.textEdit.newText+' lang="ts"'}}}var IN,Pte,Ate,Nte=re(()=>{"use strict";IN=Se(er()),Pte=Se(jS());jv();PN();Os()});var Ote={};qt(Ote,{_getComponentNames:()=>$Me,getComponentEvents:()=>zMe,getComponentNames:()=>BMe,getComponentProps:()=>LMe,getElementAttrs:()=>VMe,getTemplateContextProps:()=>qMe});function LMe(e,t,n=!1){let{typescript:r,language:s,languageService:i,getFileId:o}=this,a=s.scripts.get(o(e));if(!(a?.generated?.root instanceof mm.VueVirtualCode))return;let l=a.generated.root,u=i.getCurrentProgram();if(!u)return;let c=u.getTypeChecker(),p=Tv(r,i,l,"__VLS_components");if(!p)return[];let h=t.split("."),d=p.type.getProperty(h[0]);if(d||(d=p.type.getProperty((0,lc.camelize)(h[0]))??p.type.getProperty((0,lc.capitalize)((0,lc.camelize)(h[0])))),!d)return[];let m=c.getTypeOfSymbolAtLocation(d,p.node);for(let k=1;k<h.length;k++)if(d=m.getProperty(h[k]),d)m=c.getTypeOfSymbolAtLocation(d,p.node);else return[];let f=new Set;for(let k of m.getCallSignatures()){let w=k.parameters[0];if(w){let y=c.getTypeOfSymbolAtLocation(w,p.node).getProperties();for(let v of y)(!n||!(v.flags&r.SymbolFlags.Optional))&&f.add(v.name)}}for(let k of m.getConstructSignatures()){let b=k.getReturnType().getProperty("$props");if(b){let v=c.getTypeOfSymbolAtLocation(b,p.node).getProperties();for(let j of v)j.flags&r.SymbolFlags.Method||(!n||!(j.flags&r.SymbolFlags.Optional))&&f.add(j.name)}}return[...f]}function zMe(e,t){let{typescript:n,language:r,languageService:s,getFileId:i}=this,o=r.scripts.get(i(e));if(!(o?.generated?.root instanceof mm.VueVirtualCode))return;let a=o.generated.root,l=s.getCurrentProgram();if(!l)return;let u=l.getTypeChecker(),c=Tv(n,s,a,"__VLS_components");if(!c)return[];let p=t.split("."),h=c.type.getProperty(p[0]);if(h||(h=c.type.getProperty((0,lc.camelize)(p[0]))??c.type.getProperty((0,lc.capitalize)((0,lc.camelize)(p[0])))),!h)return[];let d=u.getTypeOfSymbolAtLocation(h,c.node);for(let f=1;f<p.length;f++)if(h=d.getProperty(p[f]),h)d=u.getTypeOfSymbolAtLocation(h,c.node);else return[];let m=new Set;for(let f of d.getConstructSignatures()){let w=f.getReturnType().getProperty("$emit");if(w){let b=u.getTypeOfSymbolAtLocation(w,c.node);for(let y of b.getCallSignatures()){let v=y.parameters[0];if(v){let j=u.getTypeOfSymbolAtLocation(v,c.node);j.isStringLiteral()&&m.add(j.value)}}}}return[...m]}function qMe(e){let{typescript:t,language:n,languageService:r,getFileId:s}=this,i=n.scripts.get(s(e));if(!(i?.generated?.root instanceof mm.VueVirtualCode))return;let o=i.generated.root;return Tv(t,r,o,"__VLS_ctx")?.type?.getProperties().map(a=>a.name)}function BMe(e){let{typescript:t,language:n,languageService:r,getFileId:s}=this,i=n.scripts.get(s(e));if(!(i?.generated?.root instanceof mm.VueVirtualCode))return;let o=i.generated.root;return Tv(t,r,o,"__VLS_components")?.type?.getProperties().map(a=>a.name).filter(a=>a.indexOf("$")===-1&&!a.startsWith("_"))??[]}function $Me(e,t,n){return Tv(e,t,n,"__VLS_components")?.type?.getProperties().map(r=>r.name).filter(r=>r.indexOf("$")===-1&&!r.startsWith("_"))??[]}function VMe(e,t){let{typescript:n,language:r,languageService:s,getFileId:i}=this;if(!(r.scripts.get(i(e))?.generated?.root instanceof mm.VueVirtualCode))return;let a=s.getCurrentProgram();if(!a)return;let l;if(l=a.getSourceFile(e)){let u=l.statements.find(p=>n.isTypeAliasDeclaration(p)&&p.name.getText()==="__VLS_IntrinsicElementsCompletion"),c=a.getTypeChecker();if(c&&u){let h=c.getTypeFromTypeNode(u.type).getProperty(t);if(h)return c.getTypeOfSymbolAtLocation(h,u).getProperties().map(m=>m.name)}}return[]}function Tv(e,t,n,r){let s=t.getCurrentProgram();if(!s)return;let i;if(i=s.getSourceFile(n.fileName)){let o=UMe(e,i,r),a=s.getTypeChecker();if(a&&o)return{node:o,type:a.getTypeAtLocation(o)}}}function UMe(e,t,n){let r;return s(t),r;function s(i){r||(e.isVariableDeclaration(i)&&i.name.getText()===n?r=i:i.forEachChild(s))}}var mm,lc,Rte=re(()=>{"use strict";mm=Se(er()),lc=Se(Vr())});var NN=M(ES=>{"use strict";Object.defineProperty(ES,"__esModule",{value:!0});ES.proxyLanguageServiceForVue=HMe;ES.getComponentSpans=Lte;var TS=er(),Fte=Vr(),WMe=(Rte(),Tt(Ote)),Mte=/\\/g;function HMe(e,t,n,r,s){let i=new Map,o=(a,l)=>{switch(l){case"getCompletionsAtPosition":return GMe(r,a[l]);case"getCompletionEntryDetails":return KMe(t,s,a[l]);case"getCodeFixesAtPosition":return JMe(a[l]);case"getQuickInfoAtPosition":return XMe(e,a,a[l]);case"getEncodedSemanticClassifications":return QMe(e,t,a,s,a[l])}};return new Proxy(n,{get(a,l,u){if(o){i.has(l)||i.set(l,o(a,l));let c=i.get(l);if(c)return c}return Reflect.get(a,l,u)},set(a,l,u,c){return Reflect.set(a,l,u,c)}})}function GMe(e,t){return(n,r,s,i)=>{let o=n.replace(Mte,"/"),a=t(o,r,s,i);if(a){a.entries=a.entries.filter(l=>l.name.indexOf("__VLS_")===-1&&(!l.labelDetails?.description||l.labelDetails.description.indexOf("__VLS_")===-1));for(let l of a.entries)if(l.source){let u=l.name;for(let c of e.extensions){let p=(0,Fte.capitalize)(c.slice(1));if(l.source.endsWith(c)&&l.name.endsWith(p)){l.name=(0,Fte.capitalize)(l.name.slice(0,-p.length)),l.insertText&&(l.insertText=l.insertText.replace(`${p}$1`,"$1")),l.data&&(l.data.__isComponentAutoImport={ext:c,suffix:p,originalName:u,newName:l.insertText});break}}l.data&&(l.data.__isAutoImport={fileName:o})}}return a}}function KMe(e,t,n){return(...r)=>{let s=n(...r);if(r[6]?.__isComponentAutoImport){let{ext:i,suffix:o,originalName:a,newName:l}=r[6]?.__isComponentAutoImport;for(let u of s?.codeActions??[])for(let c of u.changes)for(let p of c.textChanges)p.newText=p.newText.replace("import "+a+" from ","import "+l+" from ")}if(r[6]?.__isAutoImport){let{fileName:i}=r[6]?.__isAutoImport,o=e.scripts.get(t(i));if(o?.generated?.root instanceof TS.VueVirtualCode){let a=o.generated.root.getVueSfc();if(!a?.descriptor.script&&!a?.descriptor.scriptSetup)for(let l of s?.codeActions??[]){for(let u of l.changes){for(let c of u.textChanges){c.newText=`<script setup lang="ts">${c.newText}</script>

TypeError: Cannot read properties of undefined (reading 'label')
    at Dte (/home/vscode/.vscode-server/extensions/vue.volar-2.0.24/dist/server.js:13571:2319)
    at Object.provideCompletionItems (/home/vscode/.vscode-server/extensions/vue.volar-2.0.24/dist/server.js:13571:1995)
    at async m (/home/vscode/.vscode-server/extensions/vue.volar-2.0.24/dist/server.js:2:48796)
    at async Object.getCompletionItems (/home/vscode/.vscode-server/extensions/vue.volar-2.0.24/dist/server.js:2:49560)
    at async /home/vscode/.vscode-server/extensions/vue.volar-2.0.24/dist/server.js:66:20287
    at async Timeout.<anonymous> (/home/vscode/.vscode-server/extensions/vue.volar-2.0.24/dist/server.js:66:26830)

Node.js v20.11.1
[Error - 4:37:40 AM] Server process exited with code 1.
[Error - 4:37:40 AM] The Vue server crashed 5 times in the last 3 minutes. The server will not be restarted. See the output for more information.

What is expected?

provides syntax for .vue files

What is actually happening?

No syntax highlighting, no autocomplete

Link to minimal reproduction

No response

Any additional comments?

No response

RayGuo-ergou commented 4 months ago

duplicate of https://github.com/vuejs/language-tools/issues/4520, we better track in one issue.

johnsoncodehk commented 4 months ago

Duplicate of #4520