Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(hybridMode): update enabledHybridMode before activate extension #5019

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
182 changes: 92 additions & 90 deletions extensions/vscode/src/hybridMode.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,33 @@
import * as fs from 'node:fs';
import * as path from 'node:path';
import { computed, executeCommand, ref, useAllExtensions, useVscodeContext, watchEffect } from "reactive-vscode";
import { computed, executeCommand, useAllExtensions, useVscodeContext, watchEffect } from "reactive-vscode";
import * as semver from 'semver';
import * as vscode from 'vscode';
import { incompatibleExtensions, unknownExtensions } from './compatibility';
import { config } from './config';

const extensions = useAllExtensions();

export const enabledHybridMode = ref<boolean>(true);
export const enabledHybridMode = computed(() => {
if (config.server.hybridMode === 'typeScriptPluginOnly') {
return false;
} else if (config.server.hybridMode === 'auto') {
if (
incompatibleExtensions.value.length ||
unknownExtensions.value.length
) {
return false;
}
else if (
(vscodeTsdkVersion.value && !semver.gte(vscodeTsdkVersion.value, "5.3.0")) ||
(workspaceTsdkVersion.value && !semver.gte(workspaceTsdkVersion.value, "5.3.0"))
) {
return false;
}
return true;
}
return config.server.hybridMode;
})

export const enabledTypeScriptPlugin = computed(() => {
return (
Expand Down Expand Up @@ -48,101 +67,84 @@ const workspaceTsdkVersion = computed(() => {
}
});


export function useHybridModeTips() {
useVscodeContext("vueHybridMode", enabledHybridMode);

watchEffect(() => {
switch (config.server.hybridMode) {
case "typeScriptPluginOnly": {
enabledHybridMode.value = false;
break;
if (config.server.hybridMode === 'auto') {
if (
incompatibleExtensions.value.length ||
unknownExtensions.value.length
) {
vscode.window
.showInformationMessage(
`Hybrid Mode is disabled automatically because there is a potentially incompatible ${[
...incompatibleExtensions.value,
...unknownExtensions.value,
].join(", ")} TypeScript plugin installed.`,
"Open Settings",
"Report a false positive"
)
.then(value => {
if (value === "Open Settings") {
executeCommand(
"workbench.action.openSettings",
"vue.server.hybridMode"
);
}
else if (value == "Report a false positive") {
vscode.env.openExternal(
vscode.Uri.parse(
"https://github.com/vuejs/language-tools/pull/4206"
)
);
}
});
}
case "auto": {
if (
incompatibleExtensions.value.length ||
unknownExtensions.value.length
) {
vscode.window
.showInformationMessage(
`Hybrid Mode is disabled automatically because there is a potentially incompatible ${[
...incompatibleExtensions.value,
...unknownExtensions.value,
].join(", ")} TypeScript plugin installed.`,
"Open Settings",
"Report a false positive"
)
.then(value => {
if (value === "Open Settings") {
executeCommand(
"workbench.action.openSettings",
"vue.server.hybridMode"
);
}
else if (value == "Report a false positive") {
vscode.env.openExternal(
vscode.Uri.parse(
"https://github.com/vuejs/language-tools/pull/4206"
)
);
}
});
enabledHybridMode.value = false;
else if (
(vscodeTsdkVersion.value && !semver.gte(vscodeTsdkVersion.value, "5.3.0")) ||
(workspaceTsdkVersion.value && !semver.gte(workspaceTsdkVersion.value, "5.3.0"))
) {
let msg = `Hybrid Mode is disabled automatically because TSDK >= 5.3.0 is required (VSCode TSDK: ${vscodeTsdkVersion.value}`;
if (workspaceTsdkVersion.value) {
msg += `, Workspace TSDK: ${workspaceTsdkVersion.value}`;
}
else if (
(vscodeTsdkVersion.value && !semver.gte(vscodeTsdkVersion.value, "5.3.0")) ||
(workspaceTsdkVersion.value && !semver.gte(workspaceTsdkVersion.value, "5.3.0"))
) {
let msg = `Hybrid Mode is disabled automatically because TSDK >= 5.3.0 is required (VSCode TSDK: ${vscodeTsdkVersion.value}`;
if (workspaceTsdkVersion.value) {
msg += `, Workspace TSDK: ${workspaceTsdkVersion.value}`;
}
msg += `).`;
vscode.window
.showInformationMessage(msg, "Open Settings")
.then(value => {
if (value === "Open Settings") {
executeCommand(
"workbench.action.openSettings",
"vue.server.hybridMode"
);
}
});
enabledHybridMode.value = false;
} else {
enabledHybridMode.value = true;
}
break;
}
default: {
if (
config.server.hybridMode &&
incompatibleExtensions.value.length
) {
vscode.window
.showWarningMessage(
`You have explicitly enabled Hybrid Mode, but you have installed known incompatible extensions: ${incompatibleExtensions.value.join(
", "
)}. You may want to change vue.server.hybridMode to "auto" to avoid compatibility issues.`,
"Open Settings",
"Report a false positive"
)
.then(value => {
if (value === "Open Settings") {
executeCommand(
"workbench.action.openSettings",
"vue.server.hybridMode"
);
} else if (value == "Report a false positive") {
vscode.env.openExternal(
vscode.Uri.parse(
"https://github.com/vuejs/language-tools/pull/4206"
)
);
}
});
}
enabledHybridMode.value = config.server.hybridMode;
msg += `).`;
vscode.window
.showInformationMessage(msg, "Open Settings")
.then(value => {
if (value === "Open Settings") {
executeCommand(
"workbench.action.openSettings",
"vue.server.hybridMode"
);
}
});
}
} else if (config.server.hybridMode && incompatibleExtensions.value.length) {
vscode.window
.showWarningMessage(
`You have explicitly enabled Hybrid Mode, but you have installed known incompatible extensions: ${incompatibleExtensions.value.join(
", "
)}. You may want to change vue.server.hybridMode to "auto" to avoid compatibility issues.`,
"Open Settings",
"Report a false positive"
)
.then(value => {
if (value === "Open Settings") {
executeCommand(
"workbench.action.openSettings",
"vue.server.hybridMode"
);
} else if (value == "Report a false positive") {
vscode.env.openExternal(
vscode.Uri.parse(
"https://github.com/vuejs/language-tools/pull/4206"
)
);
}
});
}
});
}
Expand Down