Skip to content

Commit 0484815

Browse files
authored
Merge branch 'master' into davidmatter-patch-1
2 parents 5a02a5e + 5784131 commit 0484815

File tree

16 files changed

+743
-932
lines changed

16 files changed

+743
-932
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@
9797

9898
- **language-core:** split `__VLS_templateResult` (#4781) - Thanks to @KazariEX!
9999
- **language-core:** wrap template virtual code into a function (#4784)
100-
- **language-core:** move `templateRef` into `composibles` (#4791) - Thanks to @KazariEX!
100+
- **language-core:** move `templateRef` into `composables` (#4791) - Thanks to @KazariEX!
101101
- **language-core:** generate global types for the first parsed Vue component if cannot write global types file
102102

103103
### Tests

extensions/vscode/src/features/doctor.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,12 +157,12 @@ export async function activate(client: BaseLanguageClient) {
157157
'',
158158
'- package.json',
159159
'```json',
160-
JSON.stringify({ devDependencies: { "@vue/language-plugin-pug": "latest" } }, undefined, 2),
160+
JSON.stringify({ devDependencies: { '@vue/language-plugin-pug': 'latest' } }, undefined, 2),
161161
'```',
162162
'',
163163
'- tsconfig.json / jsconfig.json',
164164
'```jsonc',
165-
JSON.stringify({ vueCompilerOptions: { plugins: ["@vue/language-plugin-pug"] } }, undefined, 2),
165+
JSON.stringify({ vueCompilerOptions: { plugins: ['@vue/language-plugin-pug'] } }, undefined, 2),
166166
'```',
167167
].join('\n'),
168168
});

extensions/vscode/src/hybridMode.ts

Lines changed: 117 additions & 112 deletions
Original file line numberDiff line numberDiff line change
@@ -1,166 +1,170 @@
11
import * as fs from 'node:fs';
22
import * as path from 'node:path';
3-
import { computed, executeCommand, ref, useAllExtensions, useVscodeContext, watchEffect } from "reactive-vscode";
3+
import { computed, executeCommand, useAllExtensions, useVscodeContext, watchEffect } from 'reactive-vscode';
44
import * as semver from 'semver';
55
import * as vscode from 'vscode';
66
import { incompatibleExtensions, unknownExtensions } from './compatibility';
77
import { config } from './config';
88

99
const extensions = useAllExtensions();
1010

11-
export const enabledHybridMode = ref<boolean>(true);
11+
export const enabledHybridMode = computed(() => {
12+
if (config.server.hybridMode === 'typeScriptPluginOnly') {
13+
return false;
14+
}
15+
else if (config.server.hybridMode === 'auto') {
16+
if (
17+
incompatibleExtensions.value.length ||
18+
unknownExtensions.value.length
19+
) {
20+
return false;
21+
}
22+
else if (
23+
(vscodeTsdkVersion.value && !semver.gte(vscodeTsdkVersion.value, '5.3.0')) ||
24+
(workspaceTsdkVersion.value && !semver.gte(workspaceTsdkVersion.value, '5.3.0'))
25+
) {
26+
return false;
27+
}
28+
return true;
29+
}
30+
return config.server.hybridMode;
31+
})
1232

1333
export const enabledTypeScriptPlugin = computed(() => {
1434
return (
1535
enabledHybridMode.value ||
16-
config.server.hybridMode === "typeScriptPluginOnly"
36+
config.server.hybridMode === 'typeScriptPluginOnly'
1737
);
1838
});
1939

2040
const vscodeTsdkVersion = computed(() => {
2141
const nightly = extensions.value.find(
22-
({ id }) => id === "ms-vscode.vscode-typescript-next"
42+
({ id }) => id === 'ms-vscode.vscode-typescript-next'
2343
);
2444
if (nightly) {
2545
const libPath = path.join(
26-
nightly.extensionPath.replace(/\\/g, "/"),
27-
"node_modules/typescript/lib"
46+
nightly.extensionPath.replace(/\\/g, '/'),
47+
'node_modules/typescript/lib'
2848
);
2949
return getTsVersion(libPath);
3050
}
3151

3252
if (vscode.env.appRoot) {
3353
const libPath = path.join(
34-
vscode.env.appRoot.replace(/\\/g, "/"),
35-
"extensions/node_modules/typescript/lib"
54+
vscode.env.appRoot.replace(/\\/g, '/'),
55+
'extensions/node_modules/typescript/lib'
3656
);
3757
return getTsVersion(libPath);
3858
}
3959
});
4060

4161
const workspaceTsdkVersion = computed(() => {
4262
const libPath = vscode.workspace
43-
.getConfiguration("typescript")
44-
.get<string>("tsdk")
45-
?.replace(/\\/g, "/");
63+
.getConfiguration('typescript')
64+
.get<string>('tsdk')
65+
?.replace(/\\/g, '/');
4666
if (libPath) {
4767
return getTsVersion(libPath);
4868
}
4969
});
5070

5171
export function useHybridModeTips() {
52-
useVscodeContext("vueHybridMode", enabledHybridMode);
72+
useVscodeContext('vueHybridMode', enabledHybridMode);
5373

5474
watchEffect(() => {
55-
switch (config.server.hybridMode) {
56-
case "typeScriptPluginOnly": {
57-
enabledHybridMode.value = false;
58-
break;
59-
}
60-
case "auto": {
61-
if (
62-
incompatibleExtensions.value.length ||
63-
unknownExtensions.value.length
64-
) {
65-
vscode.window
66-
.showInformationMessage(
67-
`Hybrid Mode is disabled automatically because there is a potentially incompatible ${[
68-
...incompatibleExtensions.value,
69-
...unknownExtensions.value,
70-
].join(", ")} TypeScript plugin installed.`,
71-
"Open Settings",
72-
"Report a false positive"
73-
)
74-
.then(value => {
75-
if (value === "Open Settings") {
76-
executeCommand(
77-
"workbench.action.openSettings",
78-
"vue.server.hybridMode"
79-
);
80-
}
81-
else if (value == "Report a false positive") {
82-
vscode.env.openExternal(
83-
vscode.Uri.parse(
84-
"https://github.com/vuejs/language-tools/pull/4206"
85-
)
86-
);
87-
}
88-
});
89-
enabledHybridMode.value = false;
90-
}
91-
else if (
92-
(vscodeTsdkVersion.value && !semver.gte(vscodeTsdkVersion.value, "5.3.0")) ||
93-
(workspaceTsdkVersion.value && !semver.gte(workspaceTsdkVersion.value, "5.3.0"))
94-
) {
95-
let msg = `Hybrid Mode is disabled automatically because TSDK >= 5.3.0 is required (VSCode TSDK: ${vscodeTsdkVersion.value}`;
96-
if (workspaceTsdkVersion.value) {
97-
msg += `, Workspace TSDK: ${workspaceTsdkVersion.value}`;
98-
}
99-
msg += `).`;
100-
vscode.window
101-
.showInformationMessage(msg, "Open Settings")
102-
.then(value => {
103-
if (value === "Open Settings") {
104-
executeCommand(
105-
"workbench.action.openSettings",
106-
"vue.server.hybridMode"
107-
);
108-
}
109-
});
110-
enabledHybridMode.value = false;
111-
} else {
112-
enabledHybridMode.value = true;
113-
}
114-
break;
75+
if (config.server.hybridMode === 'auto') {
76+
if (
77+
incompatibleExtensions.value.length ||
78+
unknownExtensions.value.length
79+
) {
80+
vscode.window
81+
.showInformationMessage(
82+
`Hybrid Mode is disabled automatically because there is a potentially incompatible ${[
83+
...incompatibleExtensions.value,
84+
...unknownExtensions.value,
85+
].join(', ')} TypeScript plugin installed.`,
86+
'Open Settings',
87+
'Report a false positive'
88+
)
89+
.then(value => {
90+
if (value === 'Open Settings') {
91+
executeCommand(
92+
'workbench.action.openSettings',
93+
'vue.server.hybridMode'
94+
);
95+
}
96+
else if (value == 'Report a false positive') {
97+
vscode.env.openExternal(
98+
vscode.Uri.parse(
99+
'https://github.com/vuejs/language-tools/pull/4206'
100+
)
101+
);
102+
}
103+
});
115104
}
116-
default: {
117-
if (
118-
config.server.hybridMode &&
119-
incompatibleExtensions.value.length
120-
) {
121-
vscode.window
122-
.showWarningMessage(
123-
`You have explicitly enabled Hybrid Mode, but you have installed known incompatible extensions: ${incompatibleExtensions.value.join(
124-
", "
125-
)}. You may want to change vue.server.hybridMode to "auto" to avoid compatibility issues.`,
126-
"Open Settings",
127-
"Report a false positive"
128-
)
129-
.then(value => {
130-
if (value === "Open Settings") {
131-
executeCommand(
132-
"workbench.action.openSettings",
133-
"vue.server.hybridMode"
134-
);
135-
} else if (value == "Report a false positive") {
136-
vscode.env.openExternal(
137-
vscode.Uri.parse(
138-
"https://github.com/vuejs/language-tools/pull/4206"
139-
)
140-
);
141-
}
142-
});
105+
else if (
106+
(vscodeTsdkVersion.value && !semver.gte(vscodeTsdkVersion.value, '5.3.0')) ||
107+
(workspaceTsdkVersion.value && !semver.gte(workspaceTsdkVersion.value, '5.3.0'))
108+
) {
109+
let msg = `Hybrid Mode is disabled automatically because TSDK >= 5.3.0 is required (VSCode TSDK: ${vscodeTsdkVersion.value}`;
110+
if (workspaceTsdkVersion.value) {
111+
msg += `, Workspace TSDK: ${workspaceTsdkVersion.value}`;
143112
}
144-
enabledHybridMode.value = config.server.hybridMode;
113+
msg += `).`;
114+
vscode.window
115+
.showInformationMessage(msg, 'Open Settings')
116+
.then(value => {
117+
if (value === 'Open Settings') {
118+
executeCommand(
119+
'workbench.action.openSettings',
120+
'vue.server.hybridMode'
121+
);
122+
}
123+
});
145124
}
146125
}
126+
else if (config.server.hybridMode && incompatibleExtensions.value.length) {
127+
vscode.window
128+
.showWarningMessage(
129+
`You have explicitly enabled Hybrid Mode, but you have installed known incompatible extensions: ${incompatibleExtensions.value.join(
130+
', '
131+
)}. You may want to change vue.server.hybridMode to "auto" to avoid compatibility issues.`,
132+
'Open Settings',
133+
'Report a false positive'
134+
)
135+
.then(value => {
136+
if (value === 'Open Settings') {
137+
executeCommand(
138+
'workbench.action.openSettings',
139+
'vue.server.hybridMode'
140+
);
141+
}
142+
else if (value == 'Report a false positive') {
143+
vscode.env.openExternal(
144+
vscode.Uri.parse(
145+
'https://github.com/vuejs/language-tools/pull/4206'
146+
)
147+
);
148+
}
149+
});
150+
}
147151
});
148152
}
149153

150154
export function useHybridModeStatusItem() {
151155
const item = vscode.languages.createLanguageStatusItem(
152-
"vue-hybrid-mode",
156+
'vue-hybrid-mode',
153157
config.server.includeLanguages
154158
);
155159

156-
item.text = "Hybrid Mode";
160+
item.text = 'Hybrid Mode';
157161
item.detail =
158-
(enabledHybridMode.value ? "Enabled" : "Disabled") +
159-
(config.server.hybridMode === "auto" ? " (Auto)" : "");
162+
(enabledHybridMode.value ? 'Enabled' : 'Disabled') +
163+
(config.server.hybridMode === 'auto' ? ' (Auto)' : '');
160164
item.command = {
161-
title: "Open Setting",
162-
command: "workbench.action.openSettings",
163-
arguments: ["vue.server.hybridMode"],
165+
title: 'Open Setting',
166+
command: 'workbench.action.openSettings',
167+
arguments: ['vue.server.hybridMode'],
164168
};
165169

166170
if (!enabledHybridMode.value) {
@@ -170,11 +174,11 @@ export function useHybridModeStatusItem() {
170174

171175
function getTsVersion(libPath: string) {
172176
try {
173-
const p = libPath.toString().split("/");
177+
const p = libPath.toString().split('/');
174178
const p2 = p.slice(0, -1);
175-
const modulePath = p2.join("/");
176-
const filePath = modulePath + "/package.json";
177-
const contents = fs.readFileSync(filePath, "utf-8");
179+
const modulePath = p2.join('/');
180+
const filePath = modulePath + '/package.json';
181+
const contents = fs.readFileSync(filePath, 'utf-8');
178182

179183
if (contents === undefined) {
180184
return;
@@ -183,7 +187,8 @@ function getTsVersion(libPath: string) {
183187
let desc: any = null;
184188
try {
185189
desc = JSON.parse(contents);
186-
} catch (err) {
190+
}
191+
catch (err) {
187192
return;
188193
}
189194
if (!desc || !desc.version) {

0 commit comments

Comments
 (0)