@vue/language-service 2.0.0 → 2.0.1

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.
Files changed (36) hide show
  1. package/index.d.ts +7 -0
  2. package/index.js +64 -0
  3. package/lib/ideFeatures/nameCasing.d.ts +13 -0
  4. package/lib/ideFeatures/nameCasing.js +211 -0
  5. package/lib/plugins/css.d.ts +2 -0
  6. package/lib/plugins/css.js +27 -0
  7. package/lib/plugins/data.d.ts +4 -0
  8. package/lib/plugins/data.js +91 -0
  9. package/lib/plugins/vue-autoinsert-dotvalue.d.ts +10 -0
  10. package/lib/plugins/vue-autoinsert-dotvalue.js +177 -0
  11. package/lib/plugins/vue-autoinsert-parentheses.d.ts +2 -0
  12. package/lib/plugins/vue-autoinsert-parentheses.js +60 -0
  13. package/lib/plugins/vue-autoinsert-space.d.ts +2 -0
  14. package/lib/plugins/vue-autoinsert-space.js +34 -0
  15. package/lib/plugins/vue-codelens-references.d.ts +2 -0
  16. package/lib/plugins/vue-codelens-references.js +38 -0
  17. package/lib/plugins/vue-directive-comments.d.ts +2 -0
  18. package/lib/plugins/vue-directive-comments.js +61 -0
  19. package/lib/plugins/vue-document-drop.d.ts +2 -0
  20. package/lib/plugins/vue-document-drop.js +81 -0
  21. package/lib/plugins/vue-extract-file.d.ts +8 -0
  22. package/lib/plugins/vue-extract-file.js +258 -0
  23. package/lib/plugins/vue-sfc.d.ts +7 -0
  24. package/lib/plugins/vue-sfc.js +163 -0
  25. package/lib/plugins/vue-template.d.ts +3 -0
  26. package/lib/plugins/vue-template.js +594 -0
  27. package/lib/plugins/vue-toggle-v-bind-codeaction.d.ts +2 -0
  28. package/lib/plugins/vue-toggle-v-bind-codeaction.js +126 -0
  29. package/lib/plugins/vue-twoslash-queries.d.ts +2 -0
  30. package/lib/plugins/vue-twoslash-queries.js +50 -0
  31. package/lib/plugins/vue-visualize-hidden-callback-param.d.ts +2 -0
  32. package/lib/plugins/vue-visualize-hidden-callback-param.js +45 -0
  33. package/lib/types.d.ts +10 -0
  34. package/lib/types.js +31 -0
  35. package/package.json +6 -6
  36. package/scripts/update-html-data.js +426 -0
@@ -0,0 +1,126 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.create = void 0;
4
+ const language_core_1 = require("@vue/language-core");
5
+ function create(ts) {
6
+ return {
7
+ name: 'vue-toggle-v-bind-codeaction',
8
+ create(context) {
9
+ return {
10
+ provideCodeActions(document, range, _context) {
11
+ const startOffset = document.offsetAt(range.start);
12
+ const endOffset = document.offsetAt(range.end);
13
+ const [virtualCode] = context.documents.getVirtualCodeByUri(document.uri);
14
+ if (!(virtualCode instanceof language_core_1.VueGeneratedCode)) {
15
+ return;
16
+ }
17
+ const { template } = virtualCode.sfc;
18
+ if (!template?.ast)
19
+ return;
20
+ const templateStartOffset = template.startTagEnd;
21
+ const result = [];
22
+ for (const node of (0, language_core_1.eachElementNode)(template.ast)) {
23
+ if (startOffset > templateStartOffset + node.loc.end.offset || endOffset < templateStartOffset + node.loc.start.offset) {
24
+ return;
25
+ }
26
+ for (const prop of node.props) {
27
+ if (startOffset - templateStartOffset >= prop.loc.start.offset
28
+ && endOffset - templateStartOffset <= prop.loc.end.offset) {
29
+ if (prop.type === 7 && prop.exp) {
30
+ const sourceFile = ts.createSourceFile('/a.ts', prop.exp.loc.source, ts.ScriptTarget.Latest, true);
31
+ const firstStatement = sourceFile.statements[0];
32
+ if (sourceFile.statements.length === 1 && ts.isExpressionStatement(firstStatement) && ts.isStringLiteralLike(firstStatement.expression)) {
33
+ const stringNode = sourceFile.statements[0];
34
+ const removeTextRanges = [
35
+ [prop.loc.start.offset, prop.loc.start.offset + 1],
36
+ // Work correctly with trivias for cases like <input :type=" 'password' " />
37
+ [prop.exp.loc.start.offset, prop.exp.loc.start.offset + stringNode.pos + stringNode.getLeadingTriviaWidth() + 1],
38
+ [prop.exp.loc.start.offset + stringNode.end - 1, prop.exp.loc.end.offset],
39
+ ];
40
+ result.push({
41
+ title: 'Remove v-bind from attribute',
42
+ kind: 'refactor.rewrite.removeVBind',
43
+ edit: {
44
+ changes: {
45
+ [document.uri]: removeTextRanges.map(range => ({
46
+ newText: '',
47
+ range: {
48
+ start: document.positionAt(templateStartOffset + range[0]),
49
+ end: document.positionAt(templateStartOffset + range[1]),
50
+ }
51
+ }))
52
+ },
53
+ },
54
+ });
55
+ }
56
+ }
57
+ if (prop.type === 6) {
58
+ const edits = [];
59
+ const addVBindPos = document.positionAt(templateStartOffset + prop.loc.start.offset);
60
+ edits.push({
61
+ newText: ':',
62
+ range: {
63
+ start: addVBindPos,
64
+ end: addVBindPos,
65
+ },
66
+ });
67
+ let newPosition;
68
+ if (prop.value) {
69
+ const valueStart = document.positionAt(templateStartOffset + prop.value.loc.start.offset);
70
+ const valueEnd = document.positionAt(templateStartOffset + prop.value.loc.end.offset);
71
+ if (prop.value.loc.end.offset - prop.value.loc.start.offset !== prop.value.content.length) {
72
+ valueStart.character++;
73
+ valueEnd.character--;
74
+ }
75
+ edits.push({
76
+ newText: "'",
77
+ range: {
78
+ start: valueStart,
79
+ end: valueStart,
80
+ },
81
+ });
82
+ edits.push({
83
+ newText: "'",
84
+ range: {
85
+ start: valueEnd,
86
+ end: valueEnd,
87
+ },
88
+ });
89
+ }
90
+ else {
91
+ const addValuePos = document.positionAt(templateStartOffset + prop.loc.end.offset);
92
+ newPosition = {
93
+ line: addValuePos.line,
94
+ character: addValuePos.character + ':'.length + '="'.length,
95
+ };
96
+ edits.push({
97
+ newText: '=""',
98
+ range: {
99
+ start: addValuePos,
100
+ end: addValuePos
101
+ },
102
+ });
103
+ }
104
+ result.push({
105
+ title: 'Add v-bind to attribute',
106
+ kind: 'refactor.rewrite.addVBind',
107
+ edit: {
108
+ changes: { [document.uri]: edits },
109
+ },
110
+ command: newPosition ? context?.commands.setSelection.create(newPosition) : undefined,
111
+ });
112
+ }
113
+ }
114
+ }
115
+ }
116
+ return result;
117
+ },
118
+ transformCodeAction(item) {
119
+ return item; // ignore mapping
120
+ },
121
+ };
122
+ },
123
+ };
124
+ }
125
+ exports.create = create;
126
+ //# sourceMappingURL=vue-toggle-v-bind-codeaction.js.map
@@ -0,0 +1,2 @@
1
+ import type { ServicePlugin } from '@volar/language-service';
2
+ export declare function create(ts: typeof import('typescript')): ServicePlugin;
@@ -0,0 +1,50 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.create = void 0;
4
+ const vue = require("@vue/language-core");
5
+ const client_1 = require("@vue/typescript-plugin/lib/client");
6
+ const twoslashReg = /<!--\s*\^\?\s*-->/g;
7
+ function create(ts) {
8
+ return {
9
+ name: 'vue-twoslash-queries',
10
+ create(context) {
11
+ return {
12
+ async provideInlayHints(document, range) {
13
+ const [virtualCode, sourceFile] = context.documents.getVirtualCodeByUri(document.uri);
14
+ if (!(sourceFile?.generated?.code instanceof vue.VueGeneratedCode) || virtualCode?.id !== 'template')
15
+ return;
16
+ const hoverOffsets = [];
17
+ const inlayHints = [];
18
+ for (const pointer of document.getText(range).matchAll(twoslashReg)) {
19
+ const offset = pointer.index + pointer[0].indexOf('^?') + document.offsetAt(range.start);
20
+ const position = document.positionAt(offset);
21
+ hoverOffsets.push([position, document.offsetAt({
22
+ line: position.line - 1,
23
+ character: position.character,
24
+ })]);
25
+ }
26
+ for (const [pointerPosition, hoverOffset] of hoverOffsets) {
27
+ for (const [_1, [_2, map]] of context.language.files.getMaps(virtualCode)) {
28
+ for (const [sourceOffset] of map.getSourceOffsets(hoverOffset)) {
29
+ const quickInfo = await (0, client_1.getQuickInfoAtPosition)(sourceFile.generated.code.fileName, sourceOffset);
30
+ if (quickInfo) {
31
+ inlayHints.push({
32
+ position: { line: pointerPosition.line, character: pointerPosition.character + 2 },
33
+ label: ts.displayPartsToString(quickInfo.displayParts),
34
+ paddingLeft: true,
35
+ paddingRight: false,
36
+ });
37
+ break;
38
+ }
39
+ }
40
+ break;
41
+ }
42
+ }
43
+ return inlayHints;
44
+ },
45
+ };
46
+ },
47
+ };
48
+ }
49
+ exports.create = create;
50
+ //# sourceMappingURL=vue-twoslash-queries.js.map
@@ -0,0 +1,2 @@
1
+ import type { ServicePlugin } from '../types';
2
+ export declare function create(): ServicePlugin;
@@ -0,0 +1,45 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.create = void 0;
4
+ function create() {
5
+ return {
6
+ name: 'vue-inlay-hints-hidden-callback-param',
7
+ create(context) {
8
+ return {
9
+ async provideInlayHints(document, range) {
10
+ const settings = {};
11
+ const result = [];
12
+ const [vitualFile] = context.documents.getVirtualCodeByUri(document.uri);
13
+ if (vitualFile) {
14
+ const start = document.offsetAt(range.start);
15
+ const end = document.offsetAt(range.end);
16
+ for (const mapping of vitualFile.mappings) {
17
+ const hint = mapping.data.__hint;
18
+ if (mapping.generatedOffsets[0] >= start
19
+ && mapping.generatedOffsets[mapping.generatedOffsets.length - 1] + mapping.lengths[mapping.lengths.length - 1] <= end
20
+ && hint) {
21
+ settings[hint.setting] ??= await context.env.getConfiguration?.(hint.setting) ?? false;
22
+ if (!settings[hint.setting])
23
+ continue;
24
+ result.push({
25
+ label: hint.label,
26
+ paddingRight: hint.paddingRight,
27
+ paddingLeft: hint.paddingLeft,
28
+ position: document.positionAt(mapping.generatedOffsets[0]),
29
+ kind: 2,
30
+ tooltip: {
31
+ kind: 'markdown',
32
+ value: hint.tooltip,
33
+ },
34
+ });
35
+ }
36
+ }
37
+ }
38
+ return result;
39
+ },
40
+ };
41
+ },
42
+ };
43
+ }
44
+ exports.create = create;
45
+ //# sourceMappingURL=vue-visualize-hidden-callback-param.js.map
package/lib/types.d.ts ADDED
@@ -0,0 +1,10 @@
1
+ export declare enum TagNameCasing {
2
+ Kebab = 0,
3
+ Pascal = 1
4
+ }
5
+ export declare enum AttrNameCasing {
6
+ Kebab = 0,
7
+ Camel = 1
8
+ }
9
+ export * from '@volar/language-service/lib/types';
10
+ export * from '@vue/language-core/lib/types';
package/lib/types.js ADDED
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ exports.AttrNameCasing = exports.TagNameCasing = void 0;
18
+ var TagNameCasing;
19
+ (function (TagNameCasing) {
20
+ TagNameCasing[TagNameCasing["Kebab"] = 0] = "Kebab";
21
+ TagNameCasing[TagNameCasing["Pascal"] = 1] = "Pascal";
22
+ })(TagNameCasing || (exports.TagNameCasing = TagNameCasing = {}));
23
+ var AttrNameCasing;
24
+ (function (AttrNameCasing) {
25
+ AttrNameCasing[AttrNameCasing["Kebab"] = 0] = "Kebab";
26
+ AttrNameCasing[AttrNameCasing["Camel"] = 1] = "Camel";
27
+ })(AttrNameCasing || (exports.AttrNameCasing = AttrNameCasing = {}));
28
+ // only export types of depend packages
29
+ __exportStar(require("@volar/language-service/lib/types"), exports);
30
+ __exportStar(require("@vue/language-core/lib/types"), exports);
31
+ //# sourceMappingURL=types.js.map
package/package.json CHANGED
@@ -1,11 +1,11 @@
1
1
  {
2
2
  "name": "@vue/language-service",
3
- "version": "2.0.0",
3
+ "version": "2.0.1",
4
4
  "license": "MIT",
5
5
  "files": [
6
6
  "data",
7
- "out/**/*.js",
8
- "out/**/*.d.ts"
7
+ "**/*.js",
8
+ "**/*.d.ts"
9
9
  ],
10
10
  "repository": {
11
11
  "type": "git",
@@ -20,9 +20,9 @@
20
20
  "@volar/language-service": "~2.1.0",
21
21
  "@volar/typescript": "~2.1.0",
22
22
  "@vue/compiler-dom": "^3.4.0",
23
- "@vue/language-core": "2.0.0",
23
+ "@vue/language-core": "2.0.1",
24
24
  "@vue/shared": "^3.4.0",
25
- "@vue/typescript-plugin": "2.0.0",
25
+ "@vue/typescript-plugin": "2.0.1",
26
26
  "computeds": "^0.0.1",
27
27
  "path-browserify": "^1.0.1",
28
28
  "volar-service-css": "0.0.31",
@@ -43,5 +43,5 @@
43
43
  "vscode-languageserver-protocol": "^3.17.5",
44
44
  "vscode-uri": "^3.0.8"
45
45
  },
46
- "gitHead": "aa47e5a7d8a6dae62cc80dbdb5db6a9bfa4f8715"
46
+ "gitHead": "adedfd0983c910370d080e955702cca7d2275420"
47
47
  }