@vue/language-service 3.0.0-alpha.4 → 3.0.0-alpha.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/index.d.ts CHANGED
@@ -3,7 +3,7 @@ export * from '@vue/language-core';
3
3
  export * from './lib/nameCasing';
4
4
  export * from './lib/types';
5
5
  import type { LanguageServicePlugin } from '@volar/language-service';
6
- import { VueCompilerOptions } from '@vue/language-core';
6
+ import { type VueCompilerOptions } from '@vue/language-core';
7
7
  declare module '@volar/language-service' {
8
8
  interface ProjectContext {
9
9
  vue?: {
@@ -0,0 +1,14 @@
1
+ import type { LanguageServiceContext } from '@volar/language-service';
2
+ import type * as vscode from 'vscode-languageserver-protocol';
3
+ import type { URI } from 'vscode-uri';
4
+ import { AttrNameCasing, TagNameCasing } from '../types';
5
+ export declare function convertTagName(context: LanguageServiceContext, uri: URI, casing: TagNameCasing, tsPluginClient: typeof import('@vue/typescript-plugin/lib/client') | undefined): Promise<vscode.TextEdit[] | undefined>;
6
+ export declare function convertAttrName(context: LanguageServiceContext, uri: URI, casing: AttrNameCasing, tsPluginClient?: typeof import('@vue/typescript-plugin/lib/client')): Promise<vscode.TextEdit[] | undefined>;
7
+ export declare function getNameCasing(context: LanguageServiceContext, uri: URI): Promise<{
8
+ tag: TagNameCasing;
9
+ attr: AttrNameCasing;
10
+ }>;
11
+ export declare function detect(context: LanguageServiceContext, uri: URI): Promise<{
12
+ tag: TagNameCasing[];
13
+ attr: AttrNameCasing[];
14
+ }>;
@@ -0,0 +1,202 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.convertTagName = convertTagName;
4
+ exports.convertAttrName = convertAttrName;
5
+ exports.getNameCasing = getNameCasing;
6
+ exports.detect = detect;
7
+ const vue = require("@vue/language-core");
8
+ const language_core_1 = require("@vue/language-core");
9
+ const alien_signals_1 = require("alien-signals");
10
+ const types_1 = require("../types");
11
+ async function convertTagName(context, uri, casing, tsPluginClient) {
12
+ const sourceFile = context.language.scripts.get(uri);
13
+ if (!sourceFile) {
14
+ return;
15
+ }
16
+ const root = sourceFile?.generated?.root;
17
+ if (!(root instanceof language_core_1.VueVirtualCode)) {
18
+ return;
19
+ }
20
+ const { template } = root.sfc;
21
+ if (!template) {
22
+ return;
23
+ }
24
+ const document = context.documents.get(sourceFile.id, sourceFile.languageId, sourceFile.snapshot);
25
+ const edits = [];
26
+ const components = await tsPluginClient?.getComponentNames(root.fileName) ?? [];
27
+ const tags = getTemplateTagsAndAttrs(root);
28
+ for (const [tagName, { offsets }] of tags) {
29
+ const componentName = components.find(component => component === tagName || (0, language_core_1.hyphenateTag)(component) === tagName);
30
+ if (componentName) {
31
+ for (const offset of offsets) {
32
+ const start = document.positionAt(template.startTagEnd + offset);
33
+ const end = document.positionAt(template.startTagEnd + offset + tagName.length);
34
+ const range = { start, end };
35
+ if (casing === types_1.TagNameCasing.Kebab && tagName !== (0, language_core_1.hyphenateTag)(componentName)) {
36
+ edits.push({ range, newText: (0, language_core_1.hyphenateTag)(componentName) });
37
+ }
38
+ if (casing === types_1.TagNameCasing.Pascal && tagName !== componentName) {
39
+ edits.push({ range, newText: componentName });
40
+ }
41
+ }
42
+ }
43
+ }
44
+ return edits;
45
+ }
46
+ async function convertAttrName(context, uri, casing, tsPluginClient) {
47
+ const sourceFile = context.language.scripts.get(uri);
48
+ if (!sourceFile) {
49
+ return;
50
+ }
51
+ const root = sourceFile?.generated?.root;
52
+ if (!(root instanceof language_core_1.VueVirtualCode)) {
53
+ return;
54
+ }
55
+ const { template } = root.sfc;
56
+ if (!template) {
57
+ return;
58
+ }
59
+ const document = context.documents.get(uri, sourceFile.languageId, sourceFile.snapshot);
60
+ const edits = [];
61
+ const components = await tsPluginClient?.getComponentNames(root.fileName) ?? [];
62
+ const tags = getTemplateTagsAndAttrs(root);
63
+ for (const [tagName, { attrs }] of tags) {
64
+ const componentName = components.find(component => component === tagName || (0, language_core_1.hyphenateTag)(component) === tagName);
65
+ if (componentName) {
66
+ const props = (await tsPluginClient?.getComponentProps(root.fileName, componentName) ?? []).map(prop => prop.name);
67
+ for (const [attrName, { offsets }] of attrs) {
68
+ const propName = props.find(prop => prop === attrName || (0, language_core_1.hyphenateAttr)(prop) === attrName);
69
+ if (propName) {
70
+ for (const offset of offsets) {
71
+ const start = document.positionAt(template.startTagEnd + offset);
72
+ const end = document.positionAt(template.startTagEnd + offset + attrName.length);
73
+ const range = { start, end };
74
+ if (casing === types_1.AttrNameCasing.Kebab && attrName !== (0, language_core_1.hyphenateAttr)(propName)) {
75
+ edits.push({ range, newText: (0, language_core_1.hyphenateAttr)(propName) });
76
+ }
77
+ if (casing === types_1.AttrNameCasing.Camel && attrName !== propName) {
78
+ edits.push({ range, newText: propName });
79
+ }
80
+ }
81
+ }
82
+ }
83
+ }
84
+ }
85
+ return edits;
86
+ }
87
+ async function getNameCasing(context, uri) {
88
+ const detected = await detect(context, uri);
89
+ const [attr, tag] = await Promise.all([
90
+ context.env.getConfiguration?.('vue.complete.casing.props', uri.toString()),
91
+ context.env.getConfiguration?.('vue.complete.casing.tags', uri.toString()),
92
+ ]);
93
+ const tagNameCasing = detected.tag.length === 1 && (tag === 'autoPascal' || tag === 'autoKebab') ? detected.tag[0] : (tag === 'autoKebab' || tag === 'kebab') ? types_1.TagNameCasing.Kebab : types_1.TagNameCasing.Pascal;
94
+ const attrNameCasing = detected.attr.length === 1 && (attr === 'autoCamel' || attr === 'autoKebab') ? detected.attr[0] : (attr === 'autoCamel' || attr === 'camel') ? types_1.AttrNameCasing.Camel : types_1.AttrNameCasing.Kebab;
95
+ return {
96
+ tag: tagNameCasing,
97
+ attr: attrNameCasing,
98
+ };
99
+ }
100
+ async function detect(context, uri) {
101
+ const rootFile = context.language.scripts.get(uri)?.generated?.root;
102
+ if (!(rootFile instanceof language_core_1.VueVirtualCode)) {
103
+ return {
104
+ tag: [],
105
+ attr: [],
106
+ };
107
+ }
108
+ return {
109
+ tag: await getTagNameCase(rootFile),
110
+ attr: getAttrNameCase(rootFile),
111
+ };
112
+ function getAttrNameCase(file) {
113
+ const tags = getTemplateTagsAndAttrs(file);
114
+ const result = [];
115
+ for (const [_, { attrs }] of tags) {
116
+ for (const [tagName] of attrs) {
117
+ // attrName
118
+ if (tagName !== (0, language_core_1.hyphenateTag)(tagName)) {
119
+ result.push(types_1.AttrNameCasing.Camel);
120
+ break;
121
+ }
122
+ }
123
+ for (const [tagName] of attrs) {
124
+ // attr-name
125
+ if (tagName.includes('-')) {
126
+ result.push(types_1.AttrNameCasing.Kebab);
127
+ break;
128
+ }
129
+ }
130
+ }
131
+ return result;
132
+ }
133
+ function getTagNameCase(file) {
134
+ const result = new Set();
135
+ if (file.sfc.template?.ast) {
136
+ for (const element of vue.forEachElementNode(file.sfc.template.ast)) {
137
+ if (element.tagType === 1) {
138
+ if (element.tag !== (0, language_core_1.hyphenateTag)(element.tag)) {
139
+ // TagName
140
+ result.add(types_1.TagNameCasing.Pascal);
141
+ }
142
+ else {
143
+ // Tagname -> tagname
144
+ // TagName -> tag-name
145
+ result.add(types_1.TagNameCasing.Kebab);
146
+ }
147
+ }
148
+ }
149
+ }
150
+ return [...result];
151
+ }
152
+ }
153
+ const map = new WeakMap();
154
+ function getTemplateTagsAndAttrs(sourceFile) {
155
+ if (!map.has(sourceFile)) {
156
+ const getter = (0, alien_signals_1.computed)(() => {
157
+ if (!(sourceFile instanceof vue.VueVirtualCode)) {
158
+ return;
159
+ }
160
+ const ast = sourceFile.sfc.template?.ast;
161
+ const tags = new Map();
162
+ if (ast) {
163
+ for (const node of vue.forEachElementNode(ast)) {
164
+ if (!tags.has(node.tag)) {
165
+ tags.set(node.tag, { offsets: [], attrs: new Map() });
166
+ }
167
+ const tag = tags.get(node.tag);
168
+ const startTagHtmlOffset = node.loc.start.offset + node.loc.source.indexOf(node.tag);
169
+ const endTagHtmlOffset = node.loc.start.offset + node.loc.source.lastIndexOf(node.tag);
170
+ tag.offsets.push(startTagHtmlOffset);
171
+ if (!node.isSelfClosing) {
172
+ tag.offsets.push(endTagHtmlOffset);
173
+ }
174
+ for (const prop of node.props) {
175
+ let name;
176
+ let offset;
177
+ if (prop.type === 7
178
+ && prop.arg?.type === 4
179
+ && prop.arg.isStatic) {
180
+ name = prop.arg.content;
181
+ offset = prop.arg.loc.start.offset;
182
+ }
183
+ else if (prop.type === 6) {
184
+ name = prop.name;
185
+ offset = prop.loc.start.offset;
186
+ }
187
+ if (name !== undefined && offset !== undefined) {
188
+ if (!tag.attrs.has(name)) {
189
+ tag.attrs.set(name, { offsets: [] });
190
+ }
191
+ tag.attrs.get(name).offsets.push(offset);
192
+ }
193
+ }
194
+ }
195
+ }
196
+ return tags;
197
+ });
198
+ map.set(sourceFile, getter);
199
+ }
200
+ return map.get(sourceFile)() ?? new Map();
201
+ }
202
+ //# sourceMappingURL=nameCasing.js.map
@@ -1,2 +1,2 @@
1
- import { LanguageServicePlugin } from '../types';
1
+ import type { LanguageServicePlugin } from '../types';
2
2
  export declare function create(): LanguageServicePlugin;
@@ -1,2 +1,2 @@
1
- import { LanguageServiceContext, LanguageServicePlugin } from '../types';
1
+ import { type LanguageServiceContext, type LanguageServicePlugin } from '../types';
2
2
  export declare function create(ts: typeof import('typescript'), getTsPluginClient?: (context: LanguageServiceContext) => import('@vue/typescript-plugin/lib/requests').Requests | undefined): LanguageServicePlugin;
@@ -1,5 +1,5 @@
1
1
  import type { LanguageServiceContext, LanguageServicePlugin } from '@volar/language-service';
2
- import { Sfc } from '@vue/language-core';
2
+ import { type Sfc } from '@vue/language-core';
3
3
  import type * as ts from 'typescript';
4
4
  export declare function create(ts: typeof import('typescript'), getTsPluginClient?: (context: LanguageServiceContext) => import('@vue/typescript-plugin/lib/requests').Requests | undefined): LanguageServicePlugin;
5
5
  export declare function getLastImportNode(ts: typeof import('typescript'), sourceFile: ts.SourceFile): ts.Node | undefined;
@@ -1,3 +1,3 @@
1
1
  import type { LanguageServiceContext } from '@volar/language-service';
2
- import { LanguageServicePlugin } from '../types';
2
+ import { type LanguageServicePlugin } from '../types';
3
3
  export declare function create(getTsPluginClient?: (context: LanguageServiceContext) => import('@vue/typescript-plugin/lib/requests').Requests | undefined): LanguageServicePlugin;
@@ -1,3 +1,3 @@
1
1
  import type { LanguageServiceContext } from '@volar/language-service';
2
- import { LanguageServicePlugin } from '../types';
2
+ import { type LanguageServicePlugin } from '../types';
3
3
  export declare function create(mode: 'html' | 'pug', getTsPluginClient?: (context: LanguageServiceContext) => import('@vue/typescript-plugin/lib/requests').Requests | undefined): LanguageServicePlugin;
@@ -258,7 +258,7 @@ function create(mode, getTsPluginClient) {
258
258
  ...propInfos,
259
259
  ...attrs.map(attr => ({ name: attr })),
260
260
  ]) {
261
- const isGlobal = !propsSet.has(prop.name);
261
+ const isGlobal = prop.isAttribute || !propsSet.has(prop.name);
262
262
  const name = casing.attr === types_1.AttrNameCasing.Camel ? prop.name : (0, language_core_1.hyphenateAttr)(prop.name);
263
263
  const isEvent = (0, language_core_1.hyphenateAttr)(name).startsWith('on-');
264
264
  if (isEvent) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vue/language-service",
3
- "version": "3.0.0-alpha.4",
3
+ "version": "3.0.0-alpha.6",
4
4
  "license": "MIT",
5
5
  "files": [
6
6
  "data",
@@ -17,13 +17,13 @@
17
17
  "update-html-data": "node ./scripts/update-html-data.js"
18
18
  },
19
19
  "dependencies": {
20
- "@volar/language-core": "~2.4.11",
21
- "@volar/language-service": "~2.4.11",
22
- "@volar/typescript": "~2.4.11",
20
+ "@volar/language-core": "~2.4.13",
21
+ "@volar/language-service": "~2.4.13",
22
+ "@volar/typescript": "~2.4.13",
23
23
  "@vue/compiler-dom": "^3.5.0",
24
- "@vue/language-core": "3.0.0-alpha.4",
24
+ "@vue/language-core": "3.0.0-alpha.6",
25
25
  "@vue/shared": "^3.5.0",
26
- "@vue/typescript-plugin": "3.0.0-alpha.4",
26
+ "@vue/typescript-plugin": "3.0.0-alpha.6",
27
27
  "alien-signals": "^1.0.3",
28
28
  "path-browserify": "^1.0.1",
29
29
  "volar-service-css": "0.0.64",
@@ -42,8 +42,8 @@
42
42
  "devDependencies": {
43
43
  "@types/node": "^22.10.4",
44
44
  "@types/path-browserify": "^1.0.1",
45
- "@volar/kit": "~2.4.11",
45
+ "@volar/kit": "~2.4.13",
46
46
  "vscode-languageserver-protocol": "^3.17.5"
47
47
  },
48
- "gitHead": "1769cd6b94ec9e0cc2681b8dbba904f35856ba1c"
48
+ "gitHead": "a7b5649ab4957cd2228f4bbc9205b2008bff58a2"
49
49
  }
@@ -1,2 +0,0 @@
1
- import type { LanguageServicePlugin } from '@volar/language-service';
2
- export declare function create(): LanguageServicePlugin;
@@ -1,33 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.create = create;
4
- function create() {
5
- return {
6
- name: 'vue-autoinsert-selfClosing',
7
- capabilities: {
8
- autoInsertionProvider: {
9
- triggerCharacters: ['/'],
10
- configurationSections: ['vue.autoInsert.selfClosing'],
11
- },
12
- },
13
- create(context) {
14
- return {
15
- async provideAutoInsertSnippet(document, selection, change) {
16
- if (document.languageId !== 'html') {
17
- return;
18
- }
19
- const enabled = await context.env.getConfiguration?.('vue.autoInsert.selfClosing') ?? true;
20
- if (!enabled) {
21
- return;
22
- }
23
- if (change.text === '{}'
24
- && document.getText().slice(change.rangeOffset - 1, change.rangeOffset + 3) === '{{}}'
25
- && document.offsetAt(selection) === change.rangeOffset + 1) {
26
- return ` $0 `;
27
- }
28
- },
29
- };
30
- },
31
- };
32
- }
33
- //# sourceMappingURL=vue-autoinsert-self-closing.js.map