@vue/language-service
Advanced tools
Comparing version 2.1.5 to 2.1.6
@@ -68,3 +68,3 @@ "use strict"; | ||
if (componentName) { | ||
const props = await tsPluginClient?.getComponentProps(rootCode.fileName, componentName) ?? []; | ||
const props = (await tsPluginClient?.getComponentProps(rootCode.fileName, componentName) ?? []).map(prop => prop.name); | ||
for (const [attrName, { offsets }] of attrs) { | ||
@@ -71,0 +71,0 @@ const propName = props.find(prop => prop === attrName || (0, language_core_1.hyphenateAttr)(prop) === attrName); |
@@ -6,3 +6,3 @@ "use strict"; | ||
const shared_1 = require("@vue/shared"); | ||
const path = require("path-browserify"); | ||
const path_browserify_1 = require("path-browserify"); | ||
const getUserPreferences_1 = require("volar-service-typescript/lib/configs/getUserPreferences"); | ||
@@ -71,3 +71,3 @@ const vscode_uri_1 = require("vscode-uri"); | ||
if (!importPath) { | ||
importPath = path.relative(path.dirname(vueVirtualCode.fileName), incomingFileName) | ||
importPath = path_browserify_1.posix.relative(path_browserify_1.posix.dirname(vueVirtualCode.fileName), incomingFileName) | ||
|| importUri.substring(importUri.lastIndexOf('/') + 1); | ||
@@ -74,0 +74,0 @@ if (!importPath.startsWith('./') && !importPath.startsWith('../')) { |
@@ -22,2 +22,3 @@ "use strict"; | ||
let lastCompletionComponentNames = new Set(); | ||
const tsDocumentations = new Map(); | ||
const onDidChangeCustomDataListeners = new Set(); | ||
@@ -186,3 +187,3 @@ const onDidChangeCustomData = (listener) => { | ||
if (checkTag) { | ||
componentProps[checkTag] ??= await tsPluginClient?.getComponentProps(code.fileName, checkTag, true) ?? []; | ||
componentProps[checkTag] ??= (await tsPluginClient?.getComponentProps(code.fileName, checkTag, true) ?? []).map(prop => prop.name); | ||
current = { | ||
@@ -362,7 +363,7 @@ unburnedRequiredProps: [...componentProps[checkTag]], | ||
for (const tag of builtInData.tags) { | ||
if (isInternalItemId(tag.name)) { | ||
if (isItemKey(tag.name)) { | ||
continue; | ||
} | ||
if (specialTags.has(tag.name)) { | ||
tag.name = createInternalItemId('specialTag', [tag.name]); | ||
tag.name = parseItemKey('specialTag', tag.name, ''); | ||
} | ||
@@ -382,2 +383,3 @@ else if (casing.tag === types_1.TagNameCasing.Kebab) { | ||
let templateContextProps; | ||
tsDocumentations.clear(); | ||
updateExtraCustomData([ | ||
@@ -437,7 +439,7 @@ html.newHTMLDataProvider('vue-template-built-in', builtInData), | ||
const attrs = await tsPluginClient?.getElementAttrs(vueCode.fileName, tag) ?? []; | ||
const props = await tsPluginClient?.getComponentProps(vueCode.fileName, tag) ?? []; | ||
const propsInfo = await tsPluginClient?.getComponentProps(vueCode.fileName, tag) ?? []; | ||
const events = await tsPluginClient?.getComponentEvents(vueCode.fileName, tag) ?? []; | ||
tagInfos.set(tag, { | ||
attrs, | ||
props: props.filter(prop => !prop.startsWith('ref_')), | ||
propsInfo: propsInfo.filter(prop => !prop.name.startsWith('ref_')), | ||
events, | ||
@@ -449,3 +451,4 @@ }); | ||
} | ||
const { attrs, props, events } = tagInfo; | ||
const { attrs, propsInfo, events } = tagInfo; | ||
const props = propsInfo.map(prop => prop.name); | ||
const attributes = []; | ||
@@ -483,3 +486,3 @@ const _tsCodegen = language_core_1.tsCodegen.get(vueCode.sfc); | ||
: (name['on'.length].toLowerCase() + name.slice('onX'.length)); | ||
const propKey = createInternalItemId('componentEvent', [isGlobal ? '*' : tag, propNameBase]); | ||
const propKey = parseItemKey('componentEvent', isGlobal ? '*' : tag, propNameBase); | ||
attributes.push({ | ||
@@ -495,3 +498,10 @@ name: 'v-on:' + propNameBase, | ||
const propName = name; | ||
const propKey = createInternalItemId('componentProp', [isGlobal ? '*' : tag, propName]); | ||
const propKey = parseItemKey('componentProp', isGlobal ? '*' : tag, propName); | ||
const propDescription = propsInfo.find(prop => { | ||
const name = casing.attr === types_1.AttrNameCasing.Camel ? prop.name : (0, language_core_1.hyphenateAttr)(prop.name); | ||
return name === propName; | ||
})?.commentMarkdown; | ||
if (propDescription) { | ||
tsDocumentations.set(propName, propDescription); | ||
} | ||
attributes.push({ | ||
@@ -511,3 +521,3 @@ name: propName, | ||
const name = casing.attr === types_1.AttrNameCasing.Camel ? event : (0, language_core_1.hyphenateAttr)(event); | ||
const propKey = createInternalItemId('componentEvent', [tag, name]); | ||
const propKey = parseItemKey('componentEvent', tag, name); | ||
attributes.push({ | ||
@@ -535,3 +545,3 @@ name: 'v-on:' + name, | ||
const name = casing.attr === types_1.AttrNameCasing.Camel ? model : (0, language_core_1.hyphenateAttr)(model); | ||
const propKey = createInternalItemId('componentProp', [isGlobal ? '*' : tag, name]); | ||
const propKey = parseItemKey('componentProp', isGlobal ? '*' : tag, name); | ||
attributes.push({ | ||
@@ -619,10 +629,14 @@ name: 'v-model:' + name, | ||
} | ||
const originals = new Map(); | ||
completionList.items = completionList.items.filter(item => !specialTags.has(item.label)); | ||
const htmlDocumentations = new Map(); | ||
for (const item of completionList.items) { | ||
if (specialTags.has(item.label)) { | ||
completionList.items = completionList.items.filter(i => i !== item); | ||
const documentation = typeof item.documentation === 'string' ? item.documentation : item.documentation?.value; | ||
if (documentation && !isItemKey(documentation) && item.documentation) { | ||
htmlDocumentations.set(item.label, documentation); | ||
} | ||
const nameId = readInternalItemId(item.label); | ||
if (nameId) { | ||
const name = nameId.args[0]; | ||
} | ||
for (const item of completionList.items) { | ||
const resolvedLabelKey = resolveItemKey(item.label); | ||
if (resolvedLabelKey) { | ||
const name = resolvedLabelKey.tag; | ||
item.label = name; | ||
@@ -640,16 +654,31 @@ if (item.textEdit) { | ||
} | ||
const itemIdKey = typeof item.documentation === 'string' ? item.documentation : item.documentation?.value; | ||
let itemId = itemIdKey ? readInternalItemId(itemIdKey) : undefined; | ||
if (itemId) { | ||
let [isEvent, name] = tryGetEventName(itemId); | ||
const itemKeyStr = typeof item.documentation === 'string' ? item.documentation : item.documentation?.value; | ||
let resolvedKey = itemKeyStr ? resolveItemKey(itemKeyStr) : undefined; | ||
if (resolvedKey) { | ||
const documentations = []; | ||
if (tsDocumentations.has(resolvedKey.prop)) { | ||
documentations.push(tsDocumentations.get(resolvedKey.prop)); | ||
} | ||
let { isEvent, propName } = getPropName(resolvedKey); | ||
if (isEvent) { | ||
name = 'on' + name; | ||
// click -> onclick | ||
propName = 'on' + propName; | ||
} | ||
const original = originals.get(name); | ||
item.documentation = original?.documentation; | ||
if (htmlDocumentations.has(propName)) { | ||
documentations.push(htmlDocumentations.get(propName)); | ||
} | ||
if (documentations.length) { | ||
item.documentation = { | ||
kind: 'markdown', | ||
value: documentations.join('\n\n'), | ||
}; | ||
} | ||
else { | ||
item.documentation = undefined; | ||
} | ||
} | ||
else { | ||
let name = item.label; | ||
const isVBind = name.startsWith('v-bind:') ? (name = name.slice('v-bind:'.length), true) : false; | ||
const isVBindAbbr = name.startsWith(':') && name !== ':' ? (name = name.slice(':'.length), true) : false; | ||
let propName = item.label; | ||
const isVBind = propName.startsWith('v-bind:') ? (propName = propName.slice('v-bind:'.length), true) : false; | ||
const isVBindAbbr = propName.startsWith(':') && propName !== ':' ? (propName = propName.slice(':'.length), true) : false; | ||
/** | ||
@@ -660,9 +689,17 @@ * for `is`, `key` and `ref` starting with `v-bind:` or `:` | ||
if (isVBind || isVBindAbbr) { | ||
itemId = { | ||
resolvedKey = { | ||
type: 'componentProp', | ||
args: ['^', name] | ||
tag: '^', | ||
prop: propName, | ||
}; | ||
} | ||
else if (!originals.has(item.label)) { | ||
originals.set(item.label, item); | ||
if (tsDocumentations.has(propName)) { | ||
const originalDocumentation = typeof item.documentation === 'string' ? item.documentation : item.documentation?.value; | ||
item.documentation = { | ||
kind: 'markdown', | ||
value: [ | ||
tsDocumentations.get(propName), | ||
originalDocumentation, | ||
].filter(str => !!str).join('\n\n'), | ||
}; | ||
} | ||
@@ -675,7 +712,7 @@ } | ||
} | ||
else if (itemId) { | ||
const isComponent = itemId.args[0] !== '*'; | ||
const [isEvent, name] = tryGetEventName(itemId); | ||
if (itemId.type === 'componentProp') { | ||
if (isComponent || specialProps.has(name)) { | ||
else if (resolvedKey) { | ||
const isComponent = resolvedKey.tag !== '*'; | ||
const { isEvent, propName } = getPropName(resolvedKey); | ||
if (resolvedKey.type === 'componentProp') { | ||
if (isComponent || specialProps.has(propName)) { | ||
item.kind = 5; | ||
@@ -686,3 +723,3 @@ } | ||
item.kind = 23; | ||
if (name.startsWith('vnode-')) { | ||
if (propName.startsWith('vnode-')) { | ||
tokens.push('\u0004'); | ||
@@ -693,3 +730,3 @@ } | ||
|| (isComponent && isEvent) | ||
|| specialProps.has(name)) { | ||
|| specialProps.has(propName)) { | ||
tokens.push('\u0000'); | ||
@@ -711,3 +748,3 @@ if (item.label.startsWith(':')) { | ||
} | ||
if (specialProps.has(name)) { | ||
if (specialProps.has(propName)) { | ||
tokens.push('\u0001'); | ||
@@ -792,14 +829,15 @@ } | ||
; | ||
function createInternalItemId(type, args) { | ||
return '__VLS_::' + type + '::' + args.join(','); | ||
function parseItemKey(type, tag, prop) { | ||
return '__VLS_data=' + type + ',' + tag + ',' + prop; | ||
} | ||
function isInternalItemId(key) { | ||
return key.startsWith('__VLS_::'); | ||
function isItemKey(key) { | ||
return key.startsWith('__VLS_data='); | ||
} | ||
function readInternalItemId(key) { | ||
if (isInternalItemId(key)) { | ||
const strs = key.split('::'); | ||
function resolveItemKey(key) { | ||
if (isItemKey(key)) { | ||
const strs = key.slice('__VLS_data='.length).split(','); | ||
return { | ||
type: strs[1], | ||
args: strs[2].split(','), | ||
type: strs[0], | ||
tag: strs[1], | ||
prop: strs[2], | ||
}; | ||
@@ -819,12 +857,12 @@ } | ||
} | ||
function tryGetEventName(itemId) { | ||
const name = (0, language_core_1.hyphenateAttr)(itemId.args[1]); | ||
function getPropName(itemKey) { | ||
const name = (0, language_core_1.hyphenateAttr)(itemKey.prop); | ||
if (name.startsWith('on-')) { | ||
return [true, name.slice('on-'.length)]; | ||
return { isEvent: true, propName: name.slice('on-'.length) }; | ||
} | ||
else if (itemId.type === 'componentEvent') { | ||
return [true, name]; | ||
else if (itemKey.type === 'componentEvent') { | ||
return { isEvent: true, propName: name }; | ||
} | ||
return [false, name]; | ||
return { isEvent: false, propName: name }; | ||
} | ||
//# sourceMappingURL=vue-template.js.map |
{ | ||
"name": "@vue/language-service", | ||
"version": "2.1.5", | ||
"version": "2.1.6", | ||
"license": "MIT", | ||
@@ -23,5 +23,5 @@ "files": [ | ||
"@vue/compiler-dom": "^3.4.0", | ||
"@vue/language-core": "2.1.5", | ||
"@vue/language-core": "2.1.6", | ||
"@vue/shared": "^3.4.0", | ||
"@vue/typescript-plugin": "2.1.5", | ||
"@vue/typescript-plugin": "2.1.6", | ||
"computeds": "^0.0.1", | ||
@@ -47,3 +47,3 @@ "path-browserify": "^1.0.1", | ||
}, | ||
"gitHead": "a95b51ac0b0db8825f77fbba37e29932b5be61e4" | ||
"gitHead": "fd61953ce9eb924eeaf4df0bf8d2237267321194" | ||
} |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Deprecated
MaintenanceThe maintainer of the package marked it as deprecated. This could indicate that a single version should not be used, or that the package is no longer maintained and any new vulnerabilities will not be fixed.
Found 1 instance in 1 package
1574054
34043
0
+ Added@vue/language-core@2.1.6(transitive)
+ Added@vue/typescript-plugin@2.1.6(transitive)
- Removed@vue/language-core@2.1.5(transitive)
- Removed@vue/typescript-plugin@2.1.5(transitive)
Updated@vue/language-core@2.1.6
Updated@vue/typescript-plugin@2.1.6