From 1745a25cb8f00e211a9bbc05888fcaba29d3aa2f Mon Sep 17 00:00:00 2001 From: rhysd Date: Sun, 28 Jul 2024 23:04:31 +0900 Subject: [PATCH 1/2] fix `vim` command hangs on Windows --- src/vim.ts | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/vim.ts b/src/vim.ts index 757af0e..6215dd8 100644 --- a/src/vim.ts +++ b/src/vim.ts @@ -198,8 +198,18 @@ export async function installVimOnWindows(tag: string, dirSuffix: string): Promi const url = `https://github.com/vim/vim-win32-installer/releases/download/${tag}/gvim_${ver}_x64.zip`; const file = `gvim_${ver}_x64.zip`; const destDir = await installVimAssetOnWindows(file, url, dirSuffix); + const executable = exeName(false, 'windows'); + + // From v9.1.0631, vim.exe and gvim.exe share the same core, so OLE is enabled even in vim.exe. + // This command registers the vim64.dll as a type library. Without the command, vim.exe will + // ask the registration with GUI dialog and the process looks hanging. (#37) + // + // See: https://github.com/vim/vim/issues/15372 + const bin = path.join(destDir, executable); + await exec(bin, ['-silent', '-register']); + return { - executable: exeName(false, 'windows'), + executable, binDir: destDir, }; } From 4f5a280f1bd7e4accf90bd4546a6c0912a3cd118 Mon Sep 17 00:00:00 2001 From: rhysd Date: Sun, 28 Jul 2024 23:17:14 +0900 Subject: [PATCH 2/2] do not run `vim -silent -register` on Vim older than 9.1.0631 --- .github/workflows/ci.yml | 3 ++- src/vim.ts | 35 +++++++++++++++++------------------ test/vim.ts | 6 +++--- 3 files changed, 22 insertions(+), 22 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 32bdc1f..0ff3e86 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -27,7 +27,8 @@ jobs: - name: Validate action result run: node ./scripts/post_action_check.js "${{ matrix.neovim }}" "${{ matrix.version }}" "${{ steps.vim.outputs.executable }}" - # separate from stable-and-nightly since jobs.{id}.name.strategy.matrix.exclude seems not working + # Note: separate from stable-and-nightly since jobs.{id}.name.strategy.matrix.exclude seems not working + # Note: This is the last version which should not run `vim.exe -silent -register` on Windows (#37) vim-v9_1_0626: name: Vim v9.1.0626 strategy: diff --git a/src/vim.ts b/src/vim.ts index 6215dd8..0553140 100644 --- a/src/vim.ts +++ b/src/vim.ts @@ -10,8 +10,7 @@ import { exec, unzip, Env } from './shell'; import { makeTmpdir, exeName, Os, ensureError } from './utils'; import type { Installed } from './install'; -// eslint-disable-next-line @typescript-eslint/naming-convention -export function versionIsOlderThan8_2_1119(version: string): boolean { +export function versionIsOlderThan(version: string, vmajor: number, vminor: number, vpatch: number): boolean { // Note: Patch version may not exist on v7 or earlier const majorStr = version.match(/^v(\d+)\./)?.[1]; if (!majorStr) { @@ -19,8 +18,8 @@ export function versionIsOlderThan8_2_1119(version: string): boolean { } const major = parseInt(majorStr, 10); - if (major !== 8) { - return major < 8; + if (major !== vmajor) { + return major < vmajor; } const m = version.match(/\.(\d+)\.(\d{4})$/); // Extract minor and patch versions @@ -29,12 +28,12 @@ export function versionIsOlderThan8_2_1119(version: string): boolean { } const minor = parseInt(m[1], 10); - if (minor !== 2) { - return minor < 2; + if (minor !== vminor) { + return minor < vminor; } const patch = parseInt(m[2], 10); - return patch < 1119; + return patch < vpatch; } async function getXcode11DevDir(): Promise { @@ -70,7 +69,7 @@ export async function buildVim(version: string, os: Os, configureArgs: string | } const env: Env = {}; - if (os === 'macos' && versionIsOlderThan8_2_1119(version)) { + if (os === 'macos' && versionIsOlderThan(version, 8, 2, 1119)) { const dir = await getXcode11DevDir(); if (dir !== null) { // Vim before v8.2.1119 cannot be built with Xcode 12 or later. It requires Xcode 11. @@ -192,12 +191,12 @@ async function installVimAssetOnWindows(file: string, url: string, dirSuffix: st return destDir; } -export async function installVimOnWindows(tag: string, dirSuffix: string): Promise { +export async function installVimOnWindows(tag: string, version: string): Promise { const ver = tag.slice(1); // Strip 'v' prefix // e.g. https://github.com/vim/vim-win32-installer/releases/download/v8.2.0158/gvim_8.2.0158_x64.zip const url = `https://github.com/vim/vim-win32-installer/releases/download/${tag}/gvim_${ver}_x64.zip`; const file = `gvim_${ver}_x64.zip`; - const destDir = await installVimAssetOnWindows(file, url, dirSuffix); + const destDir = await installVimAssetOnWindows(file, url, version); const executable = exeName(false, 'windows'); // From v9.1.0631, vim.exe and gvim.exe share the same core, so OLE is enabled even in vim.exe. @@ -205,16 +204,16 @@ export async function installVimOnWindows(tag: string, dirSuffix: string): Promi // ask the registration with GUI dialog and the process looks hanging. (#37) // // See: https://github.com/vim/vim/issues/15372 - const bin = path.join(destDir, executable); - await exec(bin, ['-silent', '-register']); + if (version === 'stable' || version === 'nightly' || !versionIsOlderThan(version, 9, 1, 631)) { + const bin = path.join(destDir, executable); + await exec(bin, ['-silent', '-register']); + core.debug('Registered vim.exe as a type library'); + } - return { - executable, - binDir: destDir, - }; + return { executable, binDir: destDir }; } -export async function installNightlyVimOnWindows(dirSuffix: string): Promise { +export async function installNightlyVimOnWindows(version: string): Promise { const latestTag = await detectLatestWindowsReleaseTag(); - return installVimOnWindows(latestTag, dirSuffix); + return installVimOnWindows(latestTag, version); } diff --git a/test/vim.ts b/test/vim.ts index 71cc157..af2b9fe 100644 --- a/test/vim.ts +++ b/test/vim.ts @@ -1,7 +1,7 @@ import { strict as A } from 'assert'; import * as path from 'path'; import mock = require('mock-require'); -import { installVimOnWindows, detectLatestWindowsReleaseTag, versionIsOlderThan8_2_1119 } from '../src/vim'; +import { installVimOnWindows, detectLatestWindowsReleaseTag, versionIsOlderThan } from '../src/vim'; import type { Installed } from '../src/install'; import type { Os } from '../src/utils'; import type { Config } from '../src/config'; @@ -163,7 +163,7 @@ describe('buildVim()', function () { }); }); -describe('versionIsOlderThan8_2_1119()', function () { +describe('versionIsOlderThan()', function () { const testCases: [string, boolean][] = [ // Equal ['v8.2.1119', false], @@ -190,7 +190,7 @@ describe('versionIsOlderThan8_2_1119()', function () { for (const tc of testCases) { const [v, expected] = tc; it(`${v} is ${expected ? 'older' : 'equal or newer than'} 8.2.1119`, function () { - A.equal(versionIsOlderThan8_2_1119(v), expected); + A.equal(versionIsOlderThan(v, 8, 2, 1119), expected); }); } });