|
1 |
| -import type { Disposable, LanguageServiceContext, LanguageServicePluginInstance } from '@volar/language-service'; |
| 1 | +import type { Disposable, LanguageServiceContext } from '@volar/language-service'; |
2 | 2 | import { VueVirtualCode, hyphenateAttr, hyphenateTag, tsCodegen } from '@vue/language-core';
|
3 | 3 | import { camelize, capitalize } from '@vue/shared';
|
4 | 4 | import { getComponentSpans } from '@vue/typescript-plugin/lib/common';
|
@@ -198,139 +198,6 @@ export function create(
|
198 | 198 | return htmlComplete;
|
199 | 199 | },
|
200 | 200 |
|
201 |
| - async provideInlayHints(document) { |
202 |
| - |
203 |
| - if (!isSupportedDocument(document)) { |
204 |
| - return; |
205 |
| - } |
206 |
| - |
207 |
| - if (!context.project.vue) { |
208 |
| - return; |
209 |
| - } |
210 |
| - const vueCompilerOptions = context.project.vue.compilerOptions; |
211 |
| - |
212 |
| - const enabled = await context.env.getConfiguration?.<boolean>('vue.inlayHints.missingProps') ?? false; |
213 |
| - if (!enabled) { |
214 |
| - return; |
215 |
| - } |
216 |
| - |
217 |
| - const uri = URI.parse(document.uri); |
218 |
| - const decoded = context.decodeEmbeddedDocumentUri(uri); |
219 |
| - const sourceScript = decoded && context.language.scripts.get(decoded[0]); |
220 |
| - const virtualCode = decoded && sourceScript?.generated?.embeddedCodes.get(decoded[1]); |
221 |
| - if (!virtualCode) { |
222 |
| - return; |
223 |
| - } |
224 |
| - |
225 |
| - const root = sourceScript?.generated?.root; |
226 |
| - if (!(root instanceof VueVirtualCode)) { |
227 |
| - return; |
228 |
| - } |
229 |
| - |
230 |
| - const scanner = getScanner(baseServiceInstance, document); |
231 |
| - if (!scanner) { |
232 |
| - return; |
233 |
| - } |
234 |
| - |
235 |
| - const result: vscode.InlayHint[] = []; |
236 |
| - |
237 |
| - // visualize missing required props |
238 |
| - const casing = await getNameCasing(context, decoded[0]); |
239 |
| - const components = await tsPluginClient?.getComponentNames(root.fileName) ?? []; |
240 |
| - const componentProps: Record<string, string[]> = {}; |
241 |
| - let token: html.TokenType; |
242 |
| - let current: { |
243 |
| - unburnedRequiredProps: string[]; |
244 |
| - labelOffset: number; |
245 |
| - insertOffset: number; |
246 |
| - } | undefined; |
247 |
| - |
248 |
| - while ((token = scanner.scan()) !== html.TokenType.EOS) { |
249 |
| - if (token === html.TokenType.StartTag) { |
250 |
| - const tagName = scanner.getTokenText(); |
251 |
| - const checkTag = tagName.includes('.') |
252 |
| - ? tagName |
253 |
| - : components.find(component => component === tagName || hyphenateTag(component) === tagName); |
254 |
| - if (checkTag) { |
255 |
| - componentProps[checkTag] ??= (await tsPluginClient?.getComponentProps(root.fileName, checkTag) ?? []) |
256 |
| - .filter(prop => prop.required) |
257 |
| - .map(prop => prop.name); |
258 |
| - current = { |
259 |
| - unburnedRequiredProps: [...componentProps[checkTag]], |
260 |
| - labelOffset: scanner.getTokenOffset() + scanner.getTokenLength(), |
261 |
| - insertOffset: scanner.getTokenOffset() + scanner.getTokenLength(), |
262 |
| - }; |
263 |
| - } |
264 |
| - } |
265 |
| - else if (token === html.TokenType.AttributeName) { |
266 |
| - if (current) { |
267 |
| - let attrText = scanner.getTokenText(); |
268 |
| - |
269 |
| - if (attrText === 'v-bind') { |
270 |
| - current.unburnedRequiredProps = []; |
271 |
| - } |
272 |
| - else { |
273 |
| - // remove modifiers |
274 |
| - if (attrText.includes('.')) { |
275 |
| - attrText = attrText.split('.')[0]; |
276 |
| - } |
277 |
| - // normalize |
278 |
| - if (attrText.startsWith('v-bind:')) { |
279 |
| - attrText = attrText.slice('v-bind:'.length); |
280 |
| - } |
281 |
| - else if (attrText.startsWith(':')) { |
282 |
| - attrText = attrText.slice(':'.length); |
283 |
| - } |
284 |
| - else if (attrText.startsWith('v-model:')) { |
285 |
| - attrText = attrText.slice('v-model:'.length); |
286 |
| - } |
287 |
| - else if (attrText === 'v-model') { |
288 |
| - attrText = vueCompilerOptions.target >= 3 ? 'modelValue' : 'value'; // TODO: support for experimentalModelPropName? |
289 |
| - } |
290 |
| - else if (attrText.startsWith('v-on:')) { |
291 |
| - attrText = 'on-' + hyphenateAttr(attrText.slice('v-on:'.length)); |
292 |
| - } |
293 |
| - else if (attrText.startsWith('@')) { |
294 |
| - attrText = 'on-' + hyphenateAttr(attrText.slice('@'.length)); |
295 |
| - } |
296 |
| - |
297 |
| - current.unburnedRequiredProps = current.unburnedRequiredProps.filter(propName => { |
298 |
| - return attrText !== propName |
299 |
| - && attrText !== hyphenateAttr(propName); |
300 |
| - }); |
301 |
| - } |
302 |
| - } |
303 |
| - } |
304 |
| - else if (token === html.TokenType.StartTagSelfClose || token === html.TokenType.StartTagClose) { |
305 |
| - if (current) { |
306 |
| - for (const requiredProp of current.unburnedRequiredProps) { |
307 |
| - result.push({ |
308 |
| - label: `${requiredProp}!`, |
309 |
| - paddingLeft: true, |
310 |
| - position: document.positionAt(current.labelOffset), |
311 |
| - kind: 2 satisfies typeof vscode.InlayHintKind.Parameter, |
312 |
| - textEdits: [{ |
313 |
| - range: { |
314 |
| - start: document.positionAt(current.insertOffset), |
315 |
| - end: document.positionAt(current.insertOffset), |
316 |
| - }, |
317 |
| - newText: ` :${casing.attr === AttrNameCasing.Kebab ? hyphenateAttr(requiredProp) : requiredProp}=`, |
318 |
| - }], |
319 |
| - }); |
320 |
| - } |
321 |
| - current = undefined; |
322 |
| - } |
323 |
| - } |
324 |
| - if (token === html.TokenType.AttributeName || token === html.TokenType.AttributeValue) { |
325 |
| - if (current) { |
326 |
| - current.insertOffset = scanner.getTokenOffset() + scanner.getTokenLength(); |
327 |
| - } |
328 |
| - } |
329 |
| - } |
330 |
| - |
331 |
| - return result; |
332 |
| - }, |
333 |
| - |
334 | 201 | provideHover(document, position, token) {
|
335 | 202 |
|
336 | 203 | if (!isSupportedDocument(document)) {
|
@@ -993,18 +860,6 @@ export function create(
|
993 | 860 | },
|
994 | 861 | };
|
995 | 862 |
|
996 |
| - function getScanner(service: LanguageServicePluginInstance, document: TextDocument) { |
997 |
| - if (mode === 'html') { |
998 |
| - return service.provide['html/languageService']().createScanner(document.getText()); |
999 |
| - } |
1000 |
| - else { |
1001 |
| - const pugDocument = service.provide['pug/pugDocument'](document); |
1002 |
| - if (pugDocument) { |
1003 |
| - return service.provide['pug/languageService']().createScanner(pugDocument); |
1004 |
| - } |
1005 |
| - } |
1006 |
| - } |
1007 |
| - |
1008 | 863 | function updateExtraCustomData(extraData: html.IHTMLDataProvider[]) {
|
1009 | 864 | extraCustomData = extraData;
|
1010 | 865 | onDidChangeCustomDataListeners.forEach(l => l());
|
|
0 commit comments