@vue/language-service 1.8.5 → 1.8.7

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.
@@ -0,0 +1,125 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const language_core_1 = require("@vue/language-core");
4
+ function default_1() {
5
+ return (ctx, modules) => {
6
+ if (!modules?.typescript)
7
+ return {};
8
+ const ts = modules.typescript;
9
+ return {
10
+ provideCodeActions(document, range, _context) {
11
+ const startOffset = document.offsetAt(range.start);
12
+ const endOffset = document.offsetAt(range.end);
13
+ const [vueFile] = ctx.documents.getVirtualFileByUri(document.uri);
14
+ if (!vueFile || !(vueFile instanceof language_core_1.VueFile)) {
15
+ return;
16
+ }
17
+ const { templateAst, template } = vueFile.sfc;
18
+ if (!templateAst)
19
+ return;
20
+ const templateStartOffset = template.startTagEnd;
21
+ const result = [];
22
+ (0, language_core_1.walkElementNodes)(templateAst, node => {
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 /* NodeTypes.DIRECTIVE */ && 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 /* NodeTypes.ATTRIBUTE */) {
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 ? ctx?.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
+ exports.default = default_1;
125
+ //# sourceMappingURL=vue-toggle-v-bind-codeaction.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vue/language-service",
3
- "version": "1.8.5",
3
+ "version": "1.8.7",
4
4
  "main": "out/index.js",
5
5
  "license": "MIT",
6
6
  "files": [
@@ -17,28 +17,28 @@
17
17
  "update-html-data": "node ./scripts/update-html-data.js"
18
18
  },
19
19
  "dependencies": {
20
- "@volar/language-core": "~1.9.0",
21
- "@volar/language-service": "~1.9.0",
22
- "@volar/typescript": "~1.9.0",
20
+ "@volar/language-core": "~1.10.0",
21
+ "@volar/language-service": "~1.10.0",
22
+ "@volar/typescript": "~1.10.0",
23
23
  "@vue/compiler-dom": "^3.3.0",
24
- "@vue/language-core": "1.8.5",
24
+ "@vue/language-core": "1.8.7",
25
25
  "@vue/reactivity": "^3.3.0",
26
26
  "@vue/shared": "^3.3.0",
27
- "volar-service-css": "0.0.10",
28
- "volar-service-emmet": "0.0.10",
29
- "volar-service-html": "0.0.10",
30
- "volar-service-json": "0.0.10",
31
- "volar-service-pug": "0.0.10",
32
- "volar-service-pug-beautify": "0.0.10",
33
- "volar-service-typescript": "0.0.10",
34
- "volar-service-typescript-twoslash-queries": "0.0.10",
27
+ "volar-service-css": "0.0.11",
28
+ "volar-service-emmet": "0.0.11",
29
+ "volar-service-html": "0.0.11",
30
+ "volar-service-json": "0.0.11",
31
+ "volar-service-pug": "0.0.11",
32
+ "volar-service-pug-beautify": "0.0.11",
33
+ "volar-service-typescript": "0.0.11",
34
+ "volar-service-typescript-twoslash-queries": "0.0.11",
35
35
  "vscode-html-languageservice": "^5.0.4",
36
36
  "vscode-languageserver-textdocument": "^1.0.8"
37
37
  },
38
38
  "devDependencies": {
39
- "@volar/kit": "~1.9.0",
39
+ "@volar/kit": "~1.10.0",
40
40
  "vscode-languageserver-protocol": "^3.17.3",
41
41
  "vscode-uri": "^3.0.7"
42
42
  },
43
- "gitHead": "971820b55ea42cb7e8c8ba7c35c8998d5572b420"
43
+ "gitHead": "2b888901897fc9155bc12eb30ddae41afed5d942"
44
44
  }