Skip to content

fix(language-server): convert URI path to filesystem path for package manager detection - #147

Merged
9romise merged 2 commits into
npmx-dev:mainfrom
luo2430:fix/language-server
Aug 22, 2026
Merged

fix(language-server): convert URI path to filesystem path for package manager detection#147
9romise merged 2 commits into
npmx-dev:mainfrom
luo2430:fix/language-server

Conversation

@luo2430

@luo2430 luo2430 commented Aug 14, 2026

Copy link
Copy Markdown
Contributor

detectPackageManagerFromProject receives a POSIX-style URI path from WorkspaceContext, but package-manager-detector's detect() reads the actual filesystem and requires a platform-native path. Use vscode-uri to convert the path before passing it to detect().

Without this fix, the path lookup silently fails on Windows (since the POSIX-style path doesn't exist on the local filesystem), causing the detector to always fall back to npm regardless of the actual project configuration.

Fixes path handling on Windows where URI paths and filesystem paths differ.

Note for reviewers

If you need to verify behaviors on Windows, feel free to reach out to me.

… manager detection

`detectPackageManagerFromProject` receives a POSIX-style URI path from
`WorkspaceContext`, but `package-manager-detector`'s `detect()` reads the
actual filesystem and requires a platform-native path. Use `vscode-uri`
to convert the path before passing it to `detect()`.

Fixes path handling on Windows where URI paths and filesystem paths differ.
@coderabbitai

coderabbitai Bot commented Aug 14, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

Package-manager detection now converts the project URI path to a native filesystem path before calling detect(). The converted path is passed as both cwd and stopDir. Unit-test imports were updated, and the supported-package-manager test was removed. An integration test verifies that the repository root is detected as using pnpm.

Merge Risk: ⚪ Minimal · up to 66fb3

This localized path-conversion fix should preserve package-manager detection on supported platforms, and no actionable merge-blocking risk remains after normal checks and review.

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description check ✅ Passed The description clearly explains the Windows path-handling fix, which matches the changes to package manager detection and its tests.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

packages/language-server/src/workspace.integration.test.ts

ESLint skipped: missing config or dependency (missing-dependency). The ESLint configuration references a package that is not available in the sandbox.

packages/language-server/src/workspace.test.ts

ESLint skipped: the matched ESLint configuration already failed (missing-dependency).


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@luo2430

luo2430 commented Aug 16, 2026

Copy link
Copy Markdown
Contributor Author

@9romise on windows

@luo2430

luo2430 commented Aug 17, 2026

Copy link
Copy Markdown
Contributor Author

@9romise 😭

@luo2430

luo2430 commented Aug 19, 2026

Copy link
Copy Markdown
Contributor Author

@9romise 这问题真的存在
image

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1


ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: adf92e05-465f-4da5-b7a9-da300616a911

📥 Commits

Reviewing files that changed from the base of the PR and between 2702769 and 66fb388.

📒 Files selected for processing (2)
  • packages/language-server/src/workspace.integration.test.ts
  • packages/language-server/src/workspace.test.ts

Included review availability: Your plan provides up to 1 included review per hour; 0 remain after this review.

Comment on lines +1 to 13
import { detect } from 'package-manager-detector/detect'
import { afterEach, describe, expect, it, vi } from 'vitest'
import { detectPackageManagerFromProject } from './workspace'

vi.mock('package-manager-detector/detect', () => ({
detect: vi.fn(),
}))

const { detect } = await import('package-manager-detector/detect')

describe('detectPackageManagerFromProject', () => {
afterEach(() => {
vi.mocked(detect).mockReset()
})

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -eu

printf '%s\n' '--- workspace.ts ---'
sed -n '1,120p' packages/language-server/src/workspace.ts

printf '%s\n' '--- workspace.test.ts ---'
sed -n '1,220p' packages/language-server/src/workspace.test.ts

printf '%s\n' '--- relevant diff ---'
git diff -- packages/language-server/src/workspace.ts packages/language-server/src/workspace.test.ts

Repository: npmx-dev/vscode-npmx

Length of output: 4942


🏁 Script executed:

#!/bin/bash
set -eu

python3 - <<'PY'
from pathlib import Path
import re

source = Path("packages/language-server/src/workspace.ts").read_text()
test = Path("packages/language-server/src/workspace.test.ts").read_text()

function = re.search(
    r"export async function detectPackageManagerFromProject\(rootPath: string\).*?"
    r"\n\}\n",
    source,
    re.S,
)
if not function:
    raise SystemExit("detectPackageManagerFromProject was not found")

body = function.group(0)
required = [
    "const fsPath = URI.file(rootPath).fsPath",
    "cwd: fsPath",
    "stopDir: fsPath",
    "case 'bun':",
    "case 'npm':",
    "case 'pnpm':",
    "case 'yarn':",
    "return 'npm'",
]
missing = [item for item in required if item not in body]
if missing:
    raise SystemExit(f"Missing expected function behaviour: {missing}")

supported_cases = re.findall(r"mockResolvedValue\(\{\s*name:\s*'([^']+)'", test)
print("supported detector names handled by source:", ["bun", "npm", "pnpm", "yarn"])
print("detector names mocked by current tests:", supported_cases)
print("native-path call contract in source: cwd and stopDir both receive fsPath")
print("supported-manager test present:", any(name in {"bun", "npm", "pnpm", "yarn"} for name in supported_cases))
PY

printf '%s\n' '--- package declarations for URI and detector ---'
rg -n '"(vscode-uri|package-manager-detector)"' package.json packages pnpm-lock.yaml yarn.lock package-lock.json 2>/dev/null || true

Repository: npmx-dev/vscode-npmx

Length of output: 830


Add a supported-manager test. Mock detect() to return pnpm, assert that the function resolves to pnpm, and assert that detect() receives URI.file('/repo').fsPath as both cwd and stopDir.

@9romise
9romise added this pull request to the merge queue Aug 22, 2026
Merged via the queue into npmx-dev:main with commit 7d1a611 Aug 22, 2026
12 of 13 checks passed
@9romise

9romise commented Aug 22, 2026

Copy link
Copy Markdown
Member

Sorry for the late reply. I've made some adjustments to the tests and merged the PR — thanks for your contribution!

I've been quite busy with work lately. That said, in OSS communities, please avoid pinging maintainers casually, as it's generally considered impolite.

@9romise 9romise mentioned this pull request Aug 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants