diff --git a/packages/language-server/src/workspace.integration.test.ts b/packages/language-server/src/workspace.integration.test.ts new file mode 100644 index 0000000..10b0d07 --- /dev/null +++ b/packages/language-server/src/workspace.integration.test.ts @@ -0,0 +1,10 @@ +import { cwd } from 'node:process' +import { describe, expect, it } from 'vitest' +import { URI } from 'vscode-uri' +import { detectPackageManagerFromProject } from './workspace' + +describe('detectPackageManagerFromProject', () => { + it('detects the real repository as pnpm', async () => { + await expect(detectPackageManagerFromProject(URI.file(cwd()).path)).resolves.toBe('pnpm') + }) +}) diff --git a/packages/language-server/src/workspace.test.ts b/packages/language-server/src/workspace.test.ts index d3bf3d0..423b9c7 100644 --- a/packages/language-server/src/workspace.test.ts +++ b/packages/language-server/src/workspace.test.ts @@ -1,3 +1,4 @@ +import { detect } from 'package-manager-detector/detect' import { afterEach, describe, expect, it, vi } from 'vitest' import { detectPackageManagerFromProject } from './workspace' @@ -5,23 +6,11 @@ vi.mock('package-manager-detector/detect', () => ({ detect: vi.fn(), })) -const { detect } = await import('package-manager-detector/detect') - describe('detectPackageManagerFromProject', () => { afterEach(() => { vi.mocked(detect).mockReset() }) - it('returns supported package managers directly', async () => { - vi.mocked(detect).mockResolvedValue({ name: 'pnpm', agent: 'pnpm' }) - - await expect(detectPackageManagerFromProject('/repo')).resolves.toBe('pnpm') - expect(detect).toHaveBeenCalledWith({ - cwd: '/repo', - stopDir: '/repo', - }) - }) - it('falls back to npm for unsupported detectors', async () => { vi.mocked(detect).mockResolvedValue({ name: 'deno', agent: 'deno' }) diff --git a/packages/language-server/src/workspace.ts b/packages/language-server/src/workspace.ts index 204209b..9ab4ae0 100644 --- a/packages/language-server/src/workspace.ts +++ b/packages/language-server/src/workspace.ts @@ -15,9 +15,12 @@ import { URI } from 'vscode-uri' * @internal */ export async function detectPackageManagerFromProject(rootPath: string): Promise { + // `rootPath` is a URI path (posix-style) coming from `WorkspaceContext`, + // but `detect()` reads the filesystem and requires a platform-native path. + const fsPath = URI.file(rootPath).fsPath const result = await detect({ - cwd: rootPath, - stopDir: rootPath, + cwd: fsPath, + stopDir: fsPath, }) switch (result?.name) {