Skip to content

Commit

Permalink
Merge branch 'master' into davidmatter-patch-1
Browse files Browse the repository at this point in the history
  • Loading branch information
davidmatter authored Dec 9, 2024
2 parents 5a02a5e + 5784131 commit 0484815
Show file tree
Hide file tree
Showing 16 changed files with 743 additions and 932 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@

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

### Tests
Expand Down
4 changes: 2 additions & 2 deletions extensions/vscode/src/features/doctor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,12 +157,12 @@ export async function activate(client: BaseLanguageClient) {
'',
'- package.json',
'```json',
JSON.stringify({ devDependencies: { "@vue/language-plugin-pug": "latest" } }, undefined, 2),
JSON.stringify({ devDependencies: { '@vue/language-plugin-pug': 'latest' } }, undefined, 2),
'```',
'',
'- tsconfig.json / jsconfig.json',
'```jsonc',
JSON.stringify({ vueCompilerOptions: { plugins: ["@vue/language-plugin-pug"] } }, undefined, 2),
JSON.stringify({ vueCompilerOptions: { plugins: ['@vue/language-plugin-pug'] } }, undefined, 2),
'```',
].join('\n'),
});
Expand Down
229 changes: 117 additions & 112 deletions extensions/vscode/src/hybridMode.ts
Original file line number Diff line number Diff line change
@@ -1,166 +1,170 @@
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 (
enabledHybridMode.value ||
config.server.hybridMode === "typeScriptPluginOnly"
config.server.hybridMode === 'typeScriptPluginOnly'
);
});

const vscodeTsdkVersion = computed(() => {
const nightly = extensions.value.find(
({ id }) => id === "ms-vscode.vscode-typescript-next"
({ id }) => id === 'ms-vscode.vscode-typescript-next'
);
if (nightly) {
const libPath = path.join(
nightly.extensionPath.replace(/\\/g, "/"),
"node_modules/typescript/lib"
nightly.extensionPath.replace(/\\/g, '/'),
'node_modules/typescript/lib'
);
return getTsVersion(libPath);
}

if (vscode.env.appRoot) {
const libPath = path.join(
vscode.env.appRoot.replace(/\\/g, "/"),
"extensions/node_modules/typescript/lib"
vscode.env.appRoot.replace(/\\/g, '/'),
'extensions/node_modules/typescript/lib'
);
return getTsVersion(libPath);
}
});

const workspaceTsdkVersion = computed(() => {
const libPath = vscode.workspace
.getConfiguration("typescript")
.get<string>("tsdk")
?.replace(/\\/g, "/");
.getConfiguration('typescript')
.get<string>('tsdk')
?.replace(/\\/g, '/');
if (libPath) {
return getTsVersion(libPath);
}
});

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

watchEffect(() => {
switch (config.server.hybridMode) {
case "typeScriptPluginOnly": {
enabledHybridMode.value = false;
break;
}
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}`;
}
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;
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'
)
);
}
});
}
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"
)
);
}
});
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}`;
}
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'
)
);
}
});
}
});
}

export function useHybridModeStatusItem() {
const item = vscode.languages.createLanguageStatusItem(
"vue-hybrid-mode",
'vue-hybrid-mode',
config.server.includeLanguages
);

item.text = "Hybrid Mode";
item.text = 'Hybrid Mode';
item.detail =
(enabledHybridMode.value ? "Enabled" : "Disabled") +
(config.server.hybridMode === "auto" ? " (Auto)" : "");
(enabledHybridMode.value ? 'Enabled' : 'Disabled') +
(config.server.hybridMode === 'auto' ? ' (Auto)' : '');
item.command = {
title: "Open Setting",
command: "workbench.action.openSettings",
arguments: ["vue.server.hybridMode"],
title: 'Open Setting',
command: 'workbench.action.openSettings',
arguments: ['vue.server.hybridMode'],
};

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

function getTsVersion(libPath: string) {
try {
const p = libPath.toString().split("/");
const p = libPath.toString().split('/');
const p2 = p.slice(0, -1);
const modulePath = p2.join("/");
const filePath = modulePath + "/package.json";
const contents = fs.readFileSync(filePath, "utf-8");
const modulePath = p2.join('/');
const filePath = modulePath + '/package.json';
const contents = fs.readFileSync(filePath, 'utf-8');

if (contents === undefined) {
return;
Expand All @@ -183,7 +187,8 @@ function getTsVersion(libPath: string) {
let desc: any = null;
try {
desc = JSON.parse(contents);
} catch (err) {
}
catch (err) {
return;
}
if (!desc || !desc.version) {
Expand Down
Loading

0 comments on commit 0484815

Please sign in to comment.